From 19b5217050a649bdafb94cf0df78f339de922426 Mon Sep 17 00:00:00 2001 From: Yejia Chen Date: Tue, 23 Nov 2021 16:13:14 -0500 Subject: [PATCH 1/2] Rearrange files pre-codegen --- event.go | 34 +++++++++++++++++----------------- sub.go | 36 ++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/event.go b/event.go index 420ba06104..6e6ce66cbc 100644 --- a/event.go +++ b/event.go @@ -6,6 +6,23 @@ import ( "strconv" ) +// EventParams is the set of parameters that can be used when retrieving events. +// For more details see https://stripe.com/docs/api#retrieve_events. +type EventParams struct { + Params `form:"*"` +} + +// EventListParams is the set of parameters that can be used when listing events. +// For more details see https://stripe.com/docs/api#list_events. +type EventListParams struct { + ListParams `form:"*"` + Created *int64 `form:"created"` + CreatedRange *RangeQueryParams `form:"created"` + DeliverySuccess *bool `form:"delivery_success"` + Type *string `form:"type"` + Types []*string `form:"types"` +} + // Event is the resource representing a Stripe event. // For more details see https://stripe.com/docs/api#events. type Event struct { @@ -42,12 +59,6 @@ type EventData struct { Raw json.RawMessage `json:"object"` } -// EventParams is the set of parameters that can be used when retrieving events. -// For more details see https://stripe.com/docs/api#retrieve_events. -type EventParams struct { - Params `form:"*"` -} - // EventList is a list of events as retrieved from a list endpoint. type EventList struct { APIResource @@ -55,17 +66,6 @@ type EventList struct { Data []*Event `json:"data"` } -// EventListParams is the set of parameters that can be used when listing events. -// For more details see https://stripe.com/docs/api#list_events. -type EventListParams struct { - ListParams `form:"*"` - Created *int64 `form:"created"` - CreatedRange *RangeQueryParams `form:"created"` - DeliverySuccess *bool `form:"delivery_success"` - Type *string `form:"type"` - Types []*string `form:"types"` -} - // GetObjectValue returns the value from the e.Data.Object bag based on the keys hierarchy. func (e *Event) GetObjectValue(keys ...string) string { return getValue(e.Data.Object, keys) diff --git a/sub.go b/sub.go index a9832ab8ac..7eede9d183 100644 --- a/sub.go +++ b/sub.go @@ -218,13 +218,30 @@ type SubscriptionParams struct { ProrationBehavior *string `form:"proration_behavior"` ProrationDate *int64 `form:"proration_date"` Quantity *int64 `form:"quantity"` - TrialEnd *int64 `form:"trial_end"` TransferData *SubscriptionTransferDataParams `form:"transfer_data"` + TrialEnd *int64 `form:"trial_end"` TrialEndNow *bool `form:"-"` // See custom AppendTo TrialFromPlan *bool `form:"trial_from_plan"` TrialPeriodDays *int64 `form:"trial_period_days"` } +// AppendTo implements custom encoding logic for SubscriptionParams so that the special +// "now" value for billing_cycle_anchor and trial_end can be implemented +// (they're otherwise timestamps rather than strings). +func (p *SubscriptionParams) AppendTo(body *form.Values, keyParts []string) { + if BoolValue(p.BillingCycleAnchorNow) { + body.Add(form.FormatKey(append(keyParts, "billing_cycle_anchor")), "now") + } + + if BoolValue(p.BillingCycleAnchorUnchanged) { + body.Add(form.FormatKey(append(keyParts, "billing_cycle_anchor")), "unchanged") + } + + if BoolValue(p.TrialEndNow) { + body.Add(form.FormatKey(append(keyParts, "trial_end")), "now") + } +} + type SubscriptionAutomaticTaxParams struct { Enabled *bool `form:"enabled"` } @@ -244,23 +261,6 @@ type SubscriptionCancelParams struct { Prorate *bool `form:"prorate"` } -// AppendTo implements custom encoding logic for SubscriptionParams so that the special -// "now" value for billing_cycle_anchor and trial_end can be implemented -// (they're otherwise timestamps rather than strings). -func (p *SubscriptionParams) AppendTo(body *form.Values, keyParts []string) { - if BoolValue(p.BillingCycleAnchorNow) { - body.Add(form.FormatKey(append(keyParts, "billing_cycle_anchor")), "now") - } - - if BoolValue(p.BillingCycleAnchorUnchanged) { - body.Add(form.FormatKey(append(keyParts, "billing_cycle_anchor")), "unchanged") - } - - if BoolValue(p.TrialEndNow) { - body.Add(form.FormatKey(append(keyParts, "trial_end")), "now") - } -} - // SubscriptionItemsParams is the set of parameters that can be used when creating or updating a subscription item on a subscription // For more details see https://stripe.com/docs/api#create_subscription and https://stripe.com/docs/api#update_subscription. type SubscriptionItemsParams struct { From a509a9ede361152d9f9b3cbb753b2dc15fc0c1cf Mon Sep 17 00:00:00 2001 From: Yejia Chen Date: Mon, 29 Nov 2021 11:41:43 -0500 Subject: [PATCH 2/2] Codegen --- event.go | 8 ++++++++ sub.go | 25 +++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/event.go b/event.go index 6e6ce66cbc..37fc0df04f 100644 --- a/event.go +++ b/event.go @@ -1,3 +1,9 @@ +// +// +// File generated from our OpenAPI spec +// +// + package stripe import ( @@ -28,10 +34,12 @@ type EventListParams struct { type Event struct { APIResource Account string `json:"account"` + APIVersion string `json:"api_version"` Created int64 `json:"created"` Data *EventData `json:"data"` ID string `json:"id"` Livemode bool `json:"livemode"` + Object string `json:"object"` PendingWebhooks int64 `json:"pending_webhooks"` Request *EventRequest `json:"request"` Type string `json:"type"` diff --git a/sub.go b/sub.go index 7eede9d183..b5c44661f8 100644 --- a/sub.go +++ b/sub.go @@ -1,8 +1,13 @@ +// +// +// File generated from our OpenAPI spec +// +// + package stripe import ( "encoding/json" - "github.com/stripe/stripe-go/v72/form" ) @@ -225,23 +230,20 @@ type SubscriptionParams struct { TrialPeriodDays *int64 `form:"trial_period_days"` } -// AppendTo implements custom encoding logic for SubscriptionParams so that the special -// "now" value for billing_cycle_anchor and trial_end can be implemented -// (they're otherwise timestamps rather than strings). -func (p *SubscriptionParams) AppendTo(body *form.Values, keyParts []string) { - if BoolValue(p.BillingCycleAnchorNow) { +// AppendTo implements custom encoding logic for SubscriptionParams. +func (s *SubscriptionParams) AppendTo(body *form.Values, keyParts []string) { + if BoolValue(s.BillingCycleAnchorNow) { body.Add(form.FormatKey(append(keyParts, "billing_cycle_anchor")), "now") } - - if BoolValue(p.BillingCycleAnchorUnchanged) { + if BoolValue(s.BillingCycleAnchorUnchanged) { body.Add(form.FormatKey(append(keyParts, "billing_cycle_anchor")), "unchanged") } - - if BoolValue(p.TrialEndNow) { + if BoolValue(s.TrialEndNow) { body.Add(form.FormatKey(append(keyParts, "trial_end")), "now") } } +// Automatic tax settings for this subscription. type SubscriptionAutomaticTaxParams struct { Enabled *bool `form:"enabled"` } @@ -269,6 +271,7 @@ type SubscriptionItemsParams struct { ClearUsage *bool `form:"clear_usage"` Deleted *bool `form:"deleted"` ID *string `form:"id"` + Metadata map[string]string `form:"metadata"` Plan *string `form:"plan"` Price *string `form:"price"` PriceData *SubscriptionItemPriceDataParams `form:"price_data"` @@ -298,7 +301,6 @@ type SubscriptionPauseCollection struct { Behavior SubscriptionPauseCollectionBehavior `json:"behavior"` ResumesAt int64 `json:"resumes_at"` } - type SubscriptionPaymentSettingsPaymentMethodOptionsACSSDebitMandateOptions struct { TransactionType SubscriptionPaymentSettingsPaymentMethodOptionsACSSDebitMandateOptionsTransactionType `json:"transaction_type"` } @@ -398,7 +400,6 @@ type Subscription struct { TrialEnd int64 `json:"trial_end"` TrialStart int64 `json:"trial_start"` } - type SubscriptionAutomaticTax struct { Enabled bool `json:"enabled"` }