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

codegen: 14 more files #1312

Merged
merged 10 commits into from
Jul 12, 2021
74 changes: 44 additions & 30 deletions checkout/session/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// Package session provides API functions related to checkout sessions.
//
//
// File generated from our OpenAPI spec
//
//

// Package session provides the /checkout/sessions APIs
package session

import (
Expand All @@ -9,43 +15,49 @@ import (
"github.com/stripe/stripe-go/v72/lineitem"
)

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

// New creates a new session.
// New creates a new checkout session.
func New(params *stripe.CheckoutSessionParams) (*stripe.CheckoutSession, error) {
return getC().New(params)
}

// New creates a new session.
// New creates a new checkout session.
func (c Client) New(params *stripe.CheckoutSessionParams) (*stripe.CheckoutSession, error) {
session := &stripe.CheckoutSession{}
err := c.B.Call(http.MethodPost, "/v1/checkout/sessions", c.Key, params, session)
err := c.B.Call(
http.MethodPost,
"/v1/checkout/sessions",
c.Key,
params,
session,
)
return session, err
}

// Get retrieves a session.
// Get returns the details of a checkout session.
func Get(id string, params *stripe.CheckoutSessionParams) (*stripe.CheckoutSession, error) {
return getC().Get(id, params)
}

// Get retrieves a session.
// Get returns the details of a checkout session.
func (c Client) Get(id string, params *stripe.CheckoutSessionParams) (*stripe.CheckoutSession, error) {
path := stripe.FormatURLPath("/v1/checkout/sessions/%s", id)
session := &stripe.CheckoutSession{}
err := c.B.Call(http.MethodGet, path, c.Key, params, session)
return session, err
}

// List returns a list of sessions.
// List returns a list of checkout sessions.
func List(params *stripe.CheckoutSessionListParams) *Iter {
return getC().List(params)
}

// List returns a list of sessions.
// List returns a list of checkout sessions.
func (c Client) List(listParams *stripe.CheckoutSessionListParams) *Iter {
return &Iter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
list := &stripe.CheckoutSessionList{}
Expand All @@ -60,15 +72,32 @@ func (c Client) List(listParams *stripe.CheckoutSessionListParams) *Iter {
})}
}

// ListLineItems returns a list of line items on a session.
func ListLineItems(id string, params *stripe.CheckoutSessionListLineItemsParams) *lineitem.Iter {
// Iter is an iterator for checkout sessions.
type Iter struct {
*stripe.Iter
}

// CheckoutSession returns the checkout session which the iterator is currently pointing to.
func (i *Iter) CheckoutSession() *stripe.CheckoutSession {
return i.Current().(*stripe.CheckoutSession)
}

// CheckoutSessionList returns the current list object which the iterator is
// currently using. List objects will change as new API calls are made to
// continue pagination.
func (i *Iter) CheckoutSessionList() *stripe.CheckoutSessionList {
return i.List().(*stripe.CheckoutSessionList)
}

// ListLineItems is the method for the `GET /v1/checkout/sessions/{session}/line_items` API.
func ListLineItems(id string, params *stripe.CheckoutSessionListLineItemsParams) *LineItemIter {
return getC().ListLineItems(id, params)
}

// ListLineItems returns a list of line items on a session.
func (c Client) ListLineItems(id string, listParams *stripe.CheckoutSessionListLineItemsParams) *lineitem.Iter {
// ListLineItems is the method for the `GET /v1/checkout/sessions/{session}/line_items` API.
func (c Client) ListLineItems(id string, listParams *stripe.CheckoutSessionListLineItemsParams) *LineItemIter {
path := stripe.FormatURLPath("/v1/checkout/sessions/%s/line_items", id)
return &lineitem.Iter{Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
return &LineItemIter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
list := &stripe.LineItemList{}
err := c.B.CallRaw(http.MethodGet, path, c.Key, b, p, list)

Expand All @@ -81,22 +110,7 @@ func (c Client) ListLineItems(id string, listParams *stripe.CheckoutSessionListL
})}
}

// Iter is an iterator for sessions.
type Iter struct {
*stripe.Iter
}

// CheckoutSession returns the session which the iterator is currently pointing to.
func (i *Iter) CheckoutSession() *stripe.CheckoutSession {
return i.Current().(*stripe.CheckoutSession)
}

// CheckoutSessionList returns the current list object which the iterator is
// currently using. List objects will change as new API calls are made to
// continue pagination.
func (i *Iter) CheckoutSessionList() *stripe.CheckoutSessionList {
return i.List().(*stripe.CheckoutSessionList)
}
type LineItemIter lineitem.Iter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this make it a breaking change on existing integrations?
Asking as there's an Iter in lineitem.go and some broken tests at the bottom

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, this is breaking as is -- we need to do type LineItemIter = lineitem.Iter to make it a transparent type alias and that will fix the test. I thought I had written the correct override for codegen to do this, need to debug.


func getC() Client {
return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
Expand Down
69 changes: 43 additions & 26 deletions checkout_session.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
//
//
// File generated from our OpenAPI spec
//
//

package stripe

import (
"encoding/json"
)
import "encoding/json"

// CheckoutSessionCustomerDetailsTaxIDsType is the list of allowed values for type
// on the tax_ids inside customer_details of a checkout session.
Expand Down Expand Up @@ -53,12 +57,22 @@ const (

type CheckoutSessionAutomaticTaxStatus string

// List of values that CheckoutSessionAutomaticTaxStatus can take
const (
CheckoutSessionAutomaticTaxStatusComplete CheckoutSessionAutomaticTaxStatus = "complete"
CheckoutSessionAutomaticTaxStatusFailed CheckoutSessionAutomaticTaxStatus = "failed"
CheckoutSessionAutomaticTaxStatusRequiresLocationInputs CheckoutSessionAutomaticTaxStatus = "requires_location_inputs"
)

// Describes whether Checkout should collect the customer's billing address.
type CheckoutSessionBillingAddressCollection string

// List of values that CheckoutSessionBillingAddressCollection can take
const (
CheckoutSessionBillingAddressCollectionAuto CheckoutSessionBillingAddressCollection = "auto"
CheckoutSessionBillingAddressCollectionRequired CheckoutSessionBillingAddressCollection = "required"
)

// CheckoutSessionCustomerDetailsTaxExempt is the list of allowed values for
// tax_exempt inside customer_details of a checkout session.
type CheckoutSessionCustomerDetailsTaxExempt string
Expand Down Expand Up @@ -169,11 +183,11 @@ type CheckoutSessionLineItemPriceDataParams struct {
UnitAmount *int64 `form:"unit_amount"`
UnitAmountDecimal *float64 `form:"unit_amount_decimal,high_precision"`
}

type CheckoutSessionAutomaticTaxParams struct {
Enabled *bool `form:"enabled"`
}

// Controls what fields on Customer can be updated by the Checkout Session. Can only be provided when `customer` is provided.
type CheckoutSessionCustomerUpdateParams struct {
Address *string `form:"address"`
Name *string `form:"name"`
Expand Down Expand Up @@ -310,6 +324,8 @@ type CheckoutSessionSubscriptionDataParams struct {
TrialFromPlan *bool `form:"trial_from_plan"`
TrialPeriodDays *int64 `form:"trial_period_days"`
}

// Controls tax ID collection settings for the session.
type CheckoutSessionTaxIDCollectionParams struct {
Enabled *bool `form:"enabled"`
}
Expand Down Expand Up @@ -343,11 +359,6 @@ type CheckoutSessionParams struct {
TaxIDCollection *CheckoutSessionTaxIDCollectionParams `form:"tax_id_collection"`
}

type CheckoutSessionAutomaticTax struct {
Enabled bool `json:"enabled"`
Status CheckoutSessionAutomaticTaxStatus `json:"status"`
}

// CheckoutSessionListLineItemsParams is the set of parameters that can be
// used when listing line items on a session.
type CheckoutSessionListLineItemsParams struct {
Expand All @@ -363,6 +374,10 @@ type CheckoutSessionListParams struct {
PaymentIntent *string `form:"payment_intent"`
Subscription *string `form:"subscription"`
}
type CheckoutSessionAutomaticTax struct {
Enabled bool `json:"enabled"`
Status CheckoutSessionAutomaticTaxStatus `json:"status"`
}

// CheckoutSessionCustomerDetailsTaxIDs represent customer's tax IDs at the
// time of checkout.
Expand Down Expand Up @@ -429,7 +444,8 @@ type CheckoutSessionTotalDetailsBreakdownDiscount struct {
// CheckoutSessionTotalDetailsBreakdownTax represent the details of tax rate applied to a session.
type CheckoutSessionTotalDetailsBreakdownTax struct {
Amount int64 `json:"amount"`
TaxRate *TaxRate `json:"tax_rate"`
Rate *TaxRate `json:"rate"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have Rate appear here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah great question, need to call this out in the changelog and should add a comment. This is a bugfix.

The json field is tax_rate, not rate, so TaxRate will never be populated and will always be nil.

https://github.com/stripe/stripe-node/blob/master/types/2020-08-27/Checkout/Sessions.d.ts#L724

TaxRate *TaxRate `json:"tax_rate"` // Do not use: use `Rate`
}

// CheckoutSessionTotalDetailsBreakdown is the set of properties detailing a breakdown of taxes and discounts applied to a session if any.
Expand All @@ -451,14 +467,15 @@ type CheckoutSessionTotalDetails struct {
type CheckoutSession struct {
APIResource
AllowPromotionCodes bool `json:"allow_promotion_codes"`
CancelURL string `json:"cancel_url"`
CustomerDetails *CheckoutSessionCustomerDetails `json:"customer_details"`
AmountSubtotal int64 `json:"amount_subtotal"`
AmountTotal int64 `json:"amount_total"`
AutomaticTax *CheckoutSessionAutomaticTax `json:"automatic_tax"`
BillingAddressCollection CheckoutSessionBillingAddressCollection `json:"billing_address_collection"`
CancelURL string `json:"cancel_url"`
ClientReferenceID string `json:"client_reference_id"`
Currency Currency `json:"currency"`
Customer *Customer `json:"customer"`
CustomerDetails *CheckoutSessionCustomerDetails `json:"customer_details"`
CustomerEmail string `json:"customer_email"`
Deleted bool `json:"deleted"`
ID string `json:"id"`
Expand All @@ -475,36 +492,36 @@ type CheckoutSession struct {
SetupIntent *SetupIntent `json:"setup_intent"`
Shipping *ShippingDetails `json:"shipping"`
ShippingAddressCollection *CheckoutSessionShippingAddressCollection `json:"shipping_address_collection"`
Subscription *Subscription `json:"subscription"`
SubmitType CheckoutSessionSubmitType `json:"submit_type"`
Subscription *Subscription `json:"subscription"`
SuccessURL string `json:"success_url"`
TaxIDCollection *CheckoutSessionTaxIDCollection `json:"tax_id_collection"`
TotalDetails *CheckoutSessionTotalDetails `json:"total_details"`
URL string `json:"url"`
}

// CheckoutSessionList is a list of sessions as retrieved from a list endpoint.
type CheckoutSessionList struct {
APIResource
ListMeta
Data []*CheckoutSession `json:"data"`
}

// UnmarshalJSON handles deserialization of a checkout session.
// UnmarshalJSON handles deserialization of a CheckoutSession.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (p *CheckoutSession) UnmarshalJSON(data []byte) error {
func (c *CheckoutSession) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
p.ID = id
c.ID = id
return nil
}

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

*p = CheckoutSession(v)
*c = CheckoutSession(v)
return nil
}

// CheckoutSessionList is a list of sessions as retrieved from a list endpoint.
type CheckoutSessionList struct {
APIResource
ListMeta
Data []*CheckoutSession `json:"data"`
}
26 changes: 16 additions & 10 deletions dispute.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
//
//
// File generated from our OpenAPI spec
//
//

package stripe

import (
"encoding/json"
)
import "encoding/json"

// DisputeReason is the list of allowed values for a discount's reason.
type DisputeReason string
Expand Down Expand Up @@ -99,18 +103,13 @@ type Dispute struct {
IsChargeRefundable bool `json:"is_charge_refundable"`
Livemode bool `json:"livemode"`
Metadata map[string]string `json:"metadata"`
NetworkReasonCode string `json:"network_reason_code"`
Object string `json:"object"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Missing the support for this in the changelog.

PaymentIntent *PaymentIntent `json:"payment_intent"`
Reason DisputeReason `json:"reason"`
Status DisputeStatus `json:"status"`
}

// DisputeList is a list of disputes as retrieved from a list endpoint.
type DisputeList struct {
APIResource
ListMeta
Data []*Dispute `json:"data"`
}

// EvidenceDetails is the structure representing more details about
// the dispute.
type EvidenceDetails struct {
Expand Down Expand Up @@ -154,6 +153,13 @@ type DisputeEvidence struct {
UncategorizedText string `json:"uncategorized_text"`
}

// DisputeList is a list of disputes as retrieved from a list endpoint.
type DisputeList struct {
APIResource
ListMeta
Data []*Dispute `json:"data"`
}

// UnmarshalJSON handles deserialization of a Dispute.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
Expand Down