-
Notifications
You must be signed in to change notification settings - Fork 460
/
checkout_session.go
175 lines (155 loc) · 8.29 KB
/
checkout_session.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package stripe
import (
"encoding/json"
)
// CheckoutSessionSubmitType is the list of allowed values for the `submit_type`
// of a Session.
type CheckoutSessionSubmitType string
// List of values that CheckoutSessionSubmitType can take.
const (
CheckoutSessionSubmitTypeAuto CheckoutSessionSubmitType = "auto"
CheckoutSessionSubmitTypeBook CheckoutSessionSubmitType = "book"
CheckoutSessionSubmitTypeDonate CheckoutSessionSubmitType = "donate"
CheckoutSessionSubmitTypePay CheckoutSessionSubmitType = "pay"
)
// CheckoutSessionDisplayItemType is the list of allowed values for the display item type.
type CheckoutSessionDisplayItemType string
// List of values that CheckoutSessionDisplayItemType can take.
const (
CheckoutSessionDisplayItemTypeCustom CheckoutSessionDisplayItemType = "custom"
CheckoutSessionDisplayItemTypePlan CheckoutSessionDisplayItemType = "plan"
CheckoutSessionDisplayItemTypeSKU CheckoutSessionDisplayItemType = "sku"
)
// CheckoutSessionMode is the list of allowed values for the mode on a Session.
type CheckoutSessionMode string
// List of values that CheckoutSessionMode can take.
const (
CheckoutSessionModePayment CheckoutSessionMode = "payment"
CheckoutSessionModeSetup CheckoutSessionMode = "setup"
CheckoutSessionModeSubscription CheckoutSessionMode = "subscription"
)
// CheckoutSessionLineItemParams is the set of parameters allowed for a line item
// on a checkout session.
type CheckoutSessionLineItemParams struct {
Amount *int64 `form:"amount"`
Currency *string `form:"currency"`
Description *string `form:"description"`
Images []*string `form:"images"`
Name *string `form:"name"`
Quantity *int64 `form:"quantity"`
}
// CheckoutSessionPaymentIntentDataTransferDataParams is the set of parameters allowed for the
// transfer_data hash.
type CheckoutSessionPaymentIntentDataTransferDataParams struct {
Destination *string `form:"destination"`
}
// CheckoutSessionPaymentIntentDataParams is the set of parameters allowed for the
// payment intent creation on a checkout session.
type CheckoutSessionPaymentIntentDataParams struct {
Params `form:"*"`
ApplicationFeeAmount *int64 `form:"application_fee_amount"`
CaptureMethod *string `form:"capture_method"`
Description *string `form:"description"`
OnBehalfOf *string `form:"on_behalf_of"`
ReceiptEmail *string `form:"receipt_email"`
SetupFutureUsage *string `form:"setup_future_usage"`
Shipping *ShippingDetailsParams `form:"shipping"`
StatementDescriptor *string `form:"statement_descriptor"`
TransferData *CheckoutSessionPaymentIntentDataTransferDataParams `form:"transfer_data"`
}
// CheckoutSessionSetupIntentDataParams is the set of parameters allowed for the setup intent
// creation on a checkout session.
type CheckoutSessionSetupIntentDataParams struct {
Params `form:"*"`
Description *string `form:"description"`
OnBehalfOf *string `form:"on_behalf_of"`
}
// CheckoutSessionSubscriptionDataItemsParams is the set of parameters allowed for one item on a
// checkout session associated with a subscription.
type CheckoutSessionSubscriptionDataItemsParams struct {
Plan *string `form:"plan"`
Quantity *int64 `form:"quantity"`
}
// CheckoutSessionSubscriptionDataParams is the set of parameters allowed for the subscription
// creation on a checkout session.
type CheckoutSessionSubscriptionDataParams struct {
Params `form:"*"`
ApplicationFeePercent *float64 `form:"application_fee_percent"`
Items []*CheckoutSessionSubscriptionDataItemsParams `form:"items"`
TrialEnd *int64 `form:"trial_end"`
TrialFromPlan *bool `form:"trial_from_plan"`
TrialPeriodDays *int64 `form:"trial_period_days"`
}
// CheckoutSessionParams is the set of parameters that can be used when creating
// a checkout session.
// For more details see https://stripe.com/docs/api/checkout/sessions/create
type CheckoutSessionParams struct {
Params `form:"*"`
BillingAddressCollection *string `form:"billing_address_collection"`
CancelURL *string `form:"cancel_url"`
ClientReferenceID *string `form:"client_reference_id"`
Customer *string `form:"customer"`
CustomerEmail *string `form:"customer_email"`
LineItems []*CheckoutSessionLineItemParams `form:"line_items"`
Locale *string `form:"locale"`
Mode *string `form:"mode"`
PaymentIntentData *CheckoutSessionPaymentIntentDataParams `form:"payment_intent_data"`
PaymentMethodTypes []*string `form:"payment_method_types"`
SetupIntentData *CheckoutSessionSetupIntentDataParams `form:"setup_intent_data"`
SubscriptionData *CheckoutSessionSubscriptionDataParams `form:"subscription_data"`
SubmitType *string `form:"submit_type"`
SuccessURL *string `form:"success_url"`
}
// CheckoutSessionDisplayItemCustom represents an item of type custom in a checkout session
type CheckoutSessionDisplayItemCustom struct {
Description string `json:"description"`
Images []string `json:"images"`
Name string `json:"name"`
}
// CheckoutSessionDisplayItem represents one of the items in a checkout session.
type CheckoutSessionDisplayItem struct {
Amount int64 `json:"amount"`
Currency Currency `json:"currency"`
Custom *CheckoutSessionDisplayItemCustom `json:"custom"`
Quantity int64 `json:"quantity"`
Plan *Plan `json:"plan"`
SKU *SKU `json:"sku"`
Type CheckoutSessionDisplayItemType `json:"type"`
}
// CheckoutSession is the resource representing a Stripe checkout session.
// For more details see https://stripe.com/docs/api/checkout/sessions/object
type CheckoutSession struct {
CancelURL string `json:"cancel_url"`
ClientReferenceID string `json:"client_reference_id"`
Customer *Customer `json:"customer"`
CustomerEmail string `json:"customer_email"`
Deleted bool `json:"deleted"`
DisplayItems []*CheckoutSessionDisplayItem `json:"display_items"`
ID string `json:"id"`
Livemode bool `json:"livemode"`
Locale string `json:"locale"`
Mode CheckoutSessionMode `json:"mode"`
Object string `json:"object"`
PaymentIntent *PaymentIntent `json:"payment_intent"`
PaymentMethodTypes []string `json:"payment_method_types"`
SetupIntent *SetupIntent `json:"setup_intent"`
Subscription *Subscription `json:"subscription"`
SubmitType CheckoutSessionSubmitType `json:"submit_type"`
SuccessURL string `json:"success_url"`
}
// UnmarshalJSON handles deserialization of a checkout session.
// 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 {
if id, ok := ParseID(data); ok {
p.ID = id
return nil
}
type session CheckoutSession
var v session
if err := json.Unmarshal(data, &v); err != nil {
return err
}
*p = CheckoutSession(v)
return nil
}