Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update generated code for beta #1677

Merged
merged 14 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 74.23.0 - 2023-06-22
* [#1678](https://github.com/stripe/stripe-go/pull/1678) Update generated code
* Add support for `OnBehalfOf` on `Mandate`
* [#1680](https://github.com/stripe/stripe-go/pull/1680) Deserialization test
* [#1676](https://github.com/stripe/stripe-go/pull/1676) Update generated code
* Release specs are identical.
* [#1672](https://github.com/stripe/stripe-go/pull/1672) Update generated code
* Change type of `FileFileParams` from `string` to `file`

## 74.23.0-beta.2 - 2023-06-15
* [#1675](https://github.com/stripe/stripe-go/pull/1675) Update generated code for beta
* Add support for `PaymentDetails` on `ChargeCaptureParams`, `ChargeParams`, `PaymentIntentCaptureParams`, `PaymentIntentConfirmParams`, `PaymentIntentParams`, and `PaymentIntent`
Expand Down
2 changes: 1 addition & 1 deletion OPENAPI_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v387
v393
4 changes: 4 additions & 0 deletions client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/stripe/stripe-go/v74/customer"
"github.com/stripe/stripe-go/v74/customerbalancetransaction"
"github.com/stripe/stripe-go/v74/customercashbalancetransaction"
"github.com/stripe/stripe-go/v74/customersession"
"github.com/stripe/stripe-go/v74/dispute"
"github.com/stripe/stripe-go/v74/ephemeralkey"
"github.com/stripe/stripe-go/v74/event"
Expand Down Expand Up @@ -182,6 +183,8 @@ type API struct {
CustomerCashBalanceTransactions *customercashbalancetransaction.Client
// Customers is the client used to invoke /customers APIs.
Customers *customer.Client
// CustomerSessions is the client used to invoke /customer_sessions APIs.
CustomerSessions *customersession.Client
// Disputes is the client used to invoke /disputes APIs.
Disputes *dispute.Client
// EphemeralKeys is the client used to invoke /ephemeral_keys APIs.
Expand Down Expand Up @@ -407,6 +410,7 @@ func (a *API) Init(key string, backends *stripe.Backends) {
a.CustomerBalanceTransactions = &customerbalancetransaction.Client{B: backends.API, Key: key}
a.CustomerCashBalanceTransactions = &customercashbalancetransaction.Client{B: backends.API, Key: key}
a.Customers = &customer.Client{B: backends.API, Key: key}
a.CustomerSessions = &customersession.Client{B: backends.API, Key: key}
a.Disputes = &dispute.Client{B: backends.API, Key: key}
a.EphemeralKeys = &ephemeralkey.Client{B: backends.API, Key: key}
a.Events = &event.Client{B: backends.API, Key: key}
Expand Down
32 changes: 32 additions & 0 deletions customersession.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
//
// File generated from our OpenAPI spec
//
//

package stripe

// Creates a customer session object that includes a single-use client secret that you can use on your front-end to grant client-side API access for certain customer resources.
type CustomerSessionParams struct {
Params `form:"*"`
// The ID of an existing customer for which to create the customer session.
Customer *string `form:"customer"`
}

// A customer session allows you to grant client access to Stripe's frontend SDKs (like BillingJs)
// control over a customer.
type CustomerSession struct {
APIResource
// The client secret of this customer session. Used on the client to set up secure access to the given `customer`.
//
// The client secret can be used to provide access to `customer` from your frontend. It should not be stored, logged, or exposed to anyone other than the relevant customer. Make sure that you have TLS enabled on any page that includes the client secret.
ClientSecret string `json:"client_secret"`
// The customer the customer session was created for.
Customer *Customer `json:"customer"`
// The timestamp at which this customer session will expire.
ExpiresAt int64 `json:"expires_at"`
// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
Livemode bool `json:"livemode"`
// String representing the object's type. Objects of the same type share the same value.
Object string `json:"object"`
}
42 changes: 42 additions & 0 deletions customersession/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
//
// File generated from our OpenAPI spec
//
//

// Package customersession provides the /customer_sessions APIs
package customersession

import (
"net/http"

stripe "github.com/stripe/stripe-go/v74"
)

// Client is used to invoke /customer_sessions APIs.
type Client struct {
B stripe.Backend
Key string
}

// New creates a new customer session.
func New(params *stripe.CustomerSessionParams) (*stripe.CustomerSession, error) {
return getC().New(params)
}

// New creates a new customer session.
func (c Client) New(params *stripe.CustomerSessionParams) (*stripe.CustomerSession, error) {
customersession := &stripe.CustomerSession{}
err := c.B.Call(
http.MethodPost,
"/v1/customer_sessions",
c.Key,
params,
customersession,
)
return customersession, err
}

func getC() Client {
return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
}
180 changes: 180 additions & 0 deletions example/deserialization_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
package example

import (
"encoding/json"
"testing"

assert "github.com/stretchr/testify/require"
stripe "github.com/stripe/stripe-go/v74"
)

type APIResource = stripe.APIResource
type ListMeta = stripe.ListMeta

var parseID = stripe.ParseID

func ParseID(data []byte) (string, bool) {
return string(data), false
}

func TestStubWithIdDirect(t *testing.T) {
input := []byte("{\"some_ref\":{\"id\":\"xyz\"}}")
var resource MyResource
err := json.Unmarshal(input, &resource)
assert.Equal(t, nil, err)
assert.Equal(t, "xyz", resource.SomeRef.ID)
}

func TestStubWithIdExpanded(t *testing.T) {
input := []byte("{\"some_expandable\":{\"id\":\"xyz\"}}")
var resource MyResource
err := json.Unmarshal(input, &resource)
assert.Equal(t, nil, err)
assert.Equal(t, "xyz", resource.SomeExpandable.ID)
}

func TestStubWithIdArrayExpanded(t *testing.T) {
input := []byte("{\"some_expanded_array\":[{\"id\":\"xyz\"}]}")
var resource MyResource
err := json.Unmarshal(input, &resource)
assert.Equal(t, nil, err)
assert.Equal(t, "xyz", resource.SomeExpandedArray[0].ID)
}

func TestStubWithIdInArray(t *testing.T) {
input := []byte("{\"some_ref_array\":[{\"id\":\"xyz\"}]}")
var resource MyResource
err := json.Unmarshal(input, &resource)
assert.Equal(t, nil, err)
assert.Equal(t, "xyz", resource.SomeRefArray[0].ID)
}

func TestStubWithIdInListObject(t *testing.T) {
input := []byte("{\"some_list_object\":{\"data\":[{\"id\":\"xyz\"}]}}")
var resource MyResource
err := json.Unmarshal(input, &resource)
assert.Equal(t, nil, err)
assert.Equal(t, "xyz", resource.SomeListObject.Data[0].ID)
}

func TestEmptyObjectDirect(t *testing.T) {
input := []byte("{\"some_ref\":{}}")
var resource MyResource
err := json.Unmarshal(input, &resource)
assert.Equal(t, nil, err)
assert.Equal(t, "", resource.SomeRef.ID)
}

func TestEmptyObjectArray(t *testing.T) {
input := []byte("{\"some_ref_array\":[{}]}")
var resource MyResource
err := json.Unmarshal(input, &resource)
assert.Equal(t, nil, err)
assert.Equal(t, "", resource.SomeRefArray[0].ID)
}

func TestEmptyObjectExpanded(t *testing.T) {
input := []byte("{\"some_expandable\":{}}")
var resource MyResource
err := json.Unmarshal(input, &resource)
assert.Equal(t, nil, err)
assert.Equal(t, "", resource.SomeExpandable.ID)
}

func TestEmptyObjectArrayExpanded(t *testing.T) {
input := []byte("{\"some_expanded_array\":[{}]}")
var resource MyResource
err := json.Unmarshal(input, &resource)
assert.Equal(t, nil, err)
assert.Equal(t, "", resource.SomeExpandedArray[0].ID)
}

type MyResourceSomeLiteral string

// List of values that MyResourceSomeLiteral can take
const (
MyResourceSomeLiteralLiteral MyResourceSomeLiteral = "literal"
)

type MyResourceSomeEnum string

// List of values that MyResourceSomeEnum can take
const (
MyResourceSomeEnumFoo MyResourceSomeEnum = "foo"
MyResourceSomeEnumBar MyResourceSomeEnum = "bar"
)

type MyResourceSomePolymorphicGroupType string

// List of values that MyResourceSomePolymorphicGroupType can take
const (
MyResourceSomePolymorphicGroupTypeMyResource MyResourceSomePolymorphicGroupType = "MyResource"
MyResourceSomePolymorphicGroupTypeMyResourceSomeObject MyResourceSomePolymorphicGroupType = "MyResourceSomeObject"
)

type MyResourceSomeObject struct {
SomeString string `json:"some_string"`
}
type MyResource struct {
ID string `json:"id"`
SomeBoolean bool `json:"some_boolean"`
SomeDatetime int64 `json:"some_datetime"`
SomeDecimalString float64 `json:"some_decimal_string,string"`
SomeEnum MyResourceSomeEnum `json:"some_enum"`
SomeExpandable *MyResource `json:"some_expandable"`
SomeExpandedArray []*MyResource `json:"some_expanded_array"`
SomeInteger int64 `json:"some_integer"`
SomeListObject *MyResourceList `json:"some_list_object"`
SomeLiteral MyResourceSomeLiteral `json:"some_literal"`
SomeLonginteger int64 `json:"some_longinteger"`
SomeMap map[string]string `json:"some_map"`
SomeNullable string `json:"some_nullable"`
SomeNumber float64 `json:"some_number"`
SomeObject *MyResourceSomeObject `json:"some_object"`
SomePolymorphicGroup MyResourceSomePolymorphicGroup `json:"some_polymorphic_group"`
SomeRef *MyResource `json:"some_ref"`
SomeRefArray []*MyResource `json:"some_ref_array"`
SomeString string `json:"some_string"`
SomeStringArray []string `json:"some_string_array"`
}
type MyResourceSomePolymorphicGroup struct {
ID string `json:"id"`
Type MyResourceSomePolymorphicGroupType `json:"object"`

MyResource *MyResource `json:"-"`
MyResourceSomeObject *MyResourceSomeObject `json:"-"`
}

// UnmarshalJSON handles deserialization of a MyResourceSomePolymorphicGroup.
// This custom unmarshaling is needed because the specific type of
// MyResourceSomePolymorphicGroup it refers to is specified in the JSON
func (m *MyResourceSomePolymorphicGroup) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
m.ID = id
return nil
}

type myResourceSomePolymorphicGroup MyResourceSomePolymorphicGroup
var v myResourceSomePolymorphicGroup
if err := json.Unmarshal(data, &v); err != nil {
return err
}

*m = MyResourceSomePolymorphicGroup(v)
var err error

switch m.Type {
case MyResourceSomePolymorphicGroupTypeMyResource:
err = json.Unmarshal(data, &m.MyResource)
case MyResourceSomePolymorphicGroupTypeMyResourceSomeObject:
err = json.Unmarshal(data, &m.MyResourceSomeObject)
}
return err
}

// MyResourceList is a list of MyResources as retrieved from a list endpoint.
type MyResourceList struct {
APIResource
ListMeta
Data []*MyResource `json:"data"`
}
2 changes: 2 additions & 0 deletions mandate.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ type Mandate struct {
MultiUse *MandateMultiUse `json:"multi_use"`
// String representing the object's type. Objects of the same type share the same value.
Object string `json:"object"`
// The account (if any) for which the mandate is intended.
OnBehalfOf string `json:"on_behalf_of"`
// ID of the payment method associated with this mandate.
PaymentMethod *PaymentMethod `json:"payment_method"`
PaymentMethodDetails *MandatePaymentMethodDetails `json:"payment_method_details"`
Expand Down
2 changes: 1 addition & 1 deletion subscriptionschedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ type SubscriptionScheduleListParams struct {

// All invoices will be billed using the specified settings.
type SubscriptionScheduleDefaultSettingsInvoiceSettingsParams struct {
// Number of days within which a customer must pay invoices generated by this subscription schedule. This value will be `null` for subscription schedules where `billing=charge_automatically`.
// Number of days within which a customer must pay invoices generated by this subscription schedule. This value will be `null` for subscription schedules where `collection_method=charge_automatically`.
DaysUntilDue *int64 `form:"days_until_due"`
}

Expand Down
1 change: 1 addition & 0 deletions tax_registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ type TaxRegistrationCountryOptionsUSType string

// List of values that TaxRegistrationCountryOptionsUSType can take
const (
TaxRegistrationCountryOptionsUSTypeLocalLeaseTax TaxRegistrationCountryOptionsUSType = "local_lease_tax"
TaxRegistrationCountryOptionsUSTypeStateSalesTax TaxRegistrationCountryOptionsUSType = "state_sales_tax"
)

Expand Down
2 changes: 1 addition & 1 deletion tax_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ type TaxTransactionCreateReversalParams struct {
Mode *string `form:"mode"`
// The ID of the Transaction to partially or fully reverse.
OriginalTransaction *string `form:"original_transaction"`
// A custom identifier for this reversal, such as 'myOrder_123-refund_1', which must be unique across all transactions. The reference helps identify this reversal transaction in exported [tax reports](https://stripe.com/docs/tax/reports).
// A custom identifier for this reversal, such as `myOrder_123-refund_1`, which must be unique across all transactions. The reference helps identify this reversal transaction in exported [tax reports](https://stripe.com/docs/tax/reports).
Reference *string `form:"reference"`
// The shipping cost to reverse.
ShippingCost *TaxTransactionCreateReversalShippingCostParams `form:"shipping_cost"`
Expand Down