forked from stripe/stripe-go
/
setupintent.go
183 lines (156 loc) · 8.1 KB
/
setupintent.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
176
177
178
179
180
181
182
183
package stripe
import (
"encoding/json"
)
// SetupIntentCancellationReason is the list of allowed values for the cancelation reason.
type SetupIntentCancellationReason string
// List of values that SetupIntentCancellationReason can take.
const (
SetupIntentCancellationReasonAbandoned SetupIntentCancellationReason = "abandoned"
SetupIntentCancellationReasonFailedInvoice SetupIntentCancellationReason = "failed_invoice"
SetupIntentCancellationReasonFraudulent SetupIntentCancellationReason = "fraudulent"
SetupIntentCancellationReasonRequestedByCustomer SetupIntentCancellationReason = "requested_by_customer"
)
// SetupIntentNextActionType is the list of allowed values for the next action's type.
type SetupIntentNextActionType string
// List of values that SetupIntentNextActionType can take.
const (
SetupIntentNextActionTypeRedirectToURL SetupIntentNextActionType = "redirect_to_url"
)
// SetupIntentPaymentMethodOptionsCardRequestThreeDSecure is the list of allowed values controlling
// when to request 3D Secure on a SetupIntent.
type SetupIntentPaymentMethodOptionsCardRequestThreeDSecure string
// List of values that SetupIntentNextActionType can take.
const (
SetupIntentPaymentMethodOptionsCardRequestThreeDSecureAny SetupIntentPaymentMethodOptionsCardRequestThreeDSecure = "any"
SetupIntentPaymentMethodOptionsCardRequestThreeDSecureAutomatic SetupIntentPaymentMethodOptionsCardRequestThreeDSecure = "automatic"
// The following constant is considered deprecated and will be removed in the next major version.
SetupIntentPaymentMethodOptionsCardRequestThreeDSecureChallengeOnly SetupIntentPaymentMethodOptionsCardRequestThreeDSecure = "challenge_only"
)
// SetupIntentStatus is the list of allowed values for the setup intent's status.
type SetupIntentStatus string
// List of values that SetupIntentStatus can take.
const (
SetupIntentStatusCanceled SetupIntentStatus = "canceled"
SetupIntentStatusProcessing SetupIntentStatus = "processing"
SetupIntentStatusRequiresAction SetupIntentStatus = "requires_action"
SetupIntentStatusRequiresConfirmation SetupIntentStatus = "requires_confirmation"
SetupIntentStatusRequiresPaymentMethod SetupIntentStatus = "requires_payment_method"
SetupIntentStatusSucceeded SetupIntentStatus = "succeeded"
)
// SetupIntentUsage is the list of allowed values for the setup intent's usage.
type SetupIntentUsage string
// List of values that SetupIntentUsage can take.
const (
SetupIntentUsageOffSession SetupIntentUsage = "off_session"
SetupIntentUsageOnSession SetupIntentUsage = "on_session"
)
// SetupIntentCancelParams is the set of parameters that can be used when canceling a setup intent.
type SetupIntentCancelParams struct {
Params `form:"*"`
CancellationReason *string `form:"cancellation_reason"`
}
// SetupIntentConfirmParams is the set of parameters that can be used when confirming a setup intent.
type SetupIntentConfirmParams struct {
Params `form:"*"`
PaymentMethod *string `form:"payment_method"`
PaymentMethodOptions *SetupIntentPaymentMethodOptionsParams `form:"payment_method_options"`
ReturnURL *string `form:"return_url"`
}
// SetupIntentPaymentMethodOptionsCardParams represents the card-specific options applied to a
// SetupIntent.
type SetupIntentPaymentMethodOptionsCardParams struct {
MOTO *bool `form:"moto"`
RequestThreeDSecure *string `form:"request_three_d_secure"`
}
// SetupIntentPaymentMethodOptionsParams represents the type-specific payment method options
// applied to a SetupIntent.
type SetupIntentPaymentMethodOptionsParams struct {
Card *SetupIntentPaymentMethodOptionsCardParams `form:"card"`
}
// SetupIntentParams is the set of parameters that can be used when handling a setup intent.
type SetupIntentParams struct {
Params `form:"*"`
Confirm *bool `form:"confirm"`
Customer *string `form:"customer"`
Description *string `form:"description"`
OnBehalfOf *string `form:"on_behalf_of"`
PaymentMethod *string `form:"payment_method"`
PaymentMethodOptions *SetupIntentPaymentMethodOptionsParams `form:"payment_method_options"`
PaymentMethodTypes []*string `form:"payment_method_types"`
ReturnURL *string `form:"return_url"`
Usage *string `form:"usage"`
}
// SetupIntentListParams is the set of parameters that can be used when listing setup intents.
// For more details see https://stripe.com/docs/api#list_payouts.
type SetupIntentListParams struct {
ListParams `form:"*"`
Created *int64 `form:"created"`
CreatedRange *RangeQueryParams `form:"created"`
Customer *string `form:"customer"`
PaymentMethod *string `form:"payment_method"`
}
// SetupIntentNextActionRedirectToURL represents the resource for the next action of type
// "redirect_to_url".
type SetupIntentNextActionRedirectToURL struct {
ReturnURL string `json:"return_url"`
URL string `json:"url"`
}
// SetupIntentNextAction represents the type of action to take on a setup intent.
type SetupIntentNextAction struct {
RedirectToURL *SetupIntentNextActionRedirectToURL `json:"redirect_to_url"`
Type SetupIntentNextActionType `json:"type"`
}
// SetupIntentPaymentMethodOptionsCard represents the card-specific options applied to a
// SetupIntent.
type SetupIntentPaymentMethodOptionsCard struct {
RequestThreeDSecure SetupIntentPaymentMethodOptionsCardRequestThreeDSecure `json:"request_three_d_secure"`
}
// SetupIntentPaymentMethodOptions represents the type-specific payment method options applied to a
// SetupIntent.
type SetupIntentPaymentMethodOptions struct {
Card *SetupIntentPaymentMethodOptionsCard `json:"card"`
}
// SetupIntent is the resource representing a Stripe payout.
// For more details see https://stripe.com/docs/api#payment_intents.
type SetupIntent struct {
Application *Application `json:"application"`
CancellationReason SetupIntentCancellationReason `json:"cancellation_reason"`
ClientSecret string `json:"client_secret"`
Created int64 `json:"created"`
Customer *Customer `json:"customer"`
Description string `json:"description"`
ID string `json:"id"`
LastSetupError *Error `json:"last_setup_error"`
Livemode bool `json:"livemode"`
Metadata map[string]string `json:"metadata"`
NextAction *SetupIntentNextAction `json:"next_action"`
Object string `json:"object"`
OnBehalfOf *Account `json:"on_behalf_of"`
PaymentMethod *PaymentMethod `json:"payment_method"`
PaymentMethodOptions *SetupIntentPaymentMethodOptions `json:"payment_method_options"`
PaymentMethodTypes []string `json:"payment_method_types"`
Status SetupIntentStatus `json:"status"`
Usage SetupIntentUsage `json:"usage"`
}
// SetupIntentList is a list of setup intents as retrieved from a list endpoint.
type SetupIntentList struct {
ListMeta
Data []*SetupIntent `json:"data"`
}
// UnmarshalJSON handles deserialization of a SetupIntent.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (p *SetupIntent) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
p.ID = id
return nil
}
type setupIntent SetupIntent
var v setupIntent
if err := json.Unmarshal(data, &v); err != nil {
return err
}
*p = SetupIntent(v)
return nil
}