Skip to content

Commit

Permalink
Merge pull request #1385 from stripe/yejia/codegen-misc-5
Browse files Browse the repository at this point in the history
Make sub.go and event.go codegen-able
  • Loading branch information
yejia-stripe authored Nov 30, 2021
2 parents b26fdee + a509a9e commit 5223216
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 38 deletions.
42 changes: 25 additions & 17 deletions event.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//
//
// File generated from our OpenAPI spec
//
//

package stripe

import (
Expand All @@ -6,15 +12,34 @@ 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 {
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"`
Expand Down Expand Up @@ -42,30 +67,13 @@ 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
ListMeta
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)
Expand Down
43 changes: 22 additions & 21 deletions sub.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
//
//
// File generated from our OpenAPI spec
//
//

package stripe

import (
"encoding/json"

"github.com/stripe/stripe-go/v72/form"
)

Expand Down Expand Up @@ -218,13 +223,27 @@ 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.
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(s.BillingCycleAnchorUnchanged) {
body.Add(form.FormatKey(append(keyParts, "billing_cycle_anchor")), "unchanged")
}
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"`
}
Expand All @@ -244,23 +263,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 {
Expand All @@ -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"`
Expand Down Expand Up @@ -298,7 +301,6 @@ type SubscriptionPauseCollection struct {
Behavior SubscriptionPauseCollectionBehavior `json:"behavior"`
ResumesAt int64 `json:"resumes_at"`
}

type SubscriptionPaymentSettingsPaymentMethodOptionsACSSDebitMandateOptions struct {
TransactionType SubscriptionPaymentSettingsPaymentMethodOptionsACSSDebitMandateOptionsTransactionType `json:"transaction_type"`
}
Expand Down Expand Up @@ -398,7 +400,6 @@ type Subscription struct {
TrialEnd int64 `json:"trial_end"`
TrialStart int64 `json:"trial_start"`
}

type SubscriptionAutomaticTax struct {
Enabled bool `json:"enabled"`
}
Expand Down

0 comments on commit 5223216

Please sign in to comment.