forked from stripe/stripe-go
/
paymentmethod.go
206 lines (177 loc) · 8.07 KB
/
paymentmethod.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package stripe
import "encoding/json"
// PaymentMethodFPXAccountHolderType is a list of string values that FPX AccountHolderType accepts.
type PaymentMethodFPXAccountHolderType string
// List of values that PaymentMethodFPXAccountHolderType can take
const (
PaymentMethodFPXAccountHolderTypeIndividual PaymentMethodFPXAccountHolderType = "individual"
PaymentMethodFPXAccountHolderTypeCompany PaymentMethodFPXAccountHolderType = "company"
)
// PaymentMethodType is the list of allowed values for the payment method type.
type PaymentMethodType string
// List of values that PaymentMethodType can take.
const (
PaymentMethodTypeCard PaymentMethodType = "card"
PaymentMethodTypeCardPresent PaymentMethodType = "card_present"
)
// PaymentMethodCardBrand is the list of allowed values for the brand property on a
// Card PaymentMethod.
type PaymentMethodCardBrand string
// List of values that PaymentMethodCardBrand can take.
const (
PaymentMethodCardBrandAmex PaymentMethodCardBrand = "amex"
PaymentMethodCardBrandDiners PaymentMethodCardBrand = "diners"
PaymentMethodCardBrandDiscover PaymentMethodCardBrand = "discover"
PaymentMethodCardBrandJCB PaymentMethodCardBrand = "jcb"
PaymentMethodCardBrandMastercard PaymentMethodCardBrand = "mastercard"
PaymentMethodCardBrandUnionpay PaymentMethodCardBrand = "unionpay"
PaymentMethodCardBrandUnknown PaymentMethodCardBrand = "unknown"
PaymentMethodCardBrandVisa PaymentMethodCardBrand = "visa"
)
// PaymentMethodCardWalletType is the list of allowed values for the type a wallet can take on
// a Card PaymentMethod.
type PaymentMethodCardWalletType string
// List of values that PaymentMethodCardWalletType can take.
const (
PaymentMethodCardWalletTypeAmexExpressCheckout PaymentMethodCardWalletType = "amex_express_checkout"
PaymentMethodCardWalletTypeApplePay PaymentMethodCardWalletType = "apple_pay"
PaymentMethodCardWalletTypeGooglePay PaymentMethodCardWalletType = "google_pay"
PaymentMethodCardWalletTypeMasterpass PaymentMethodCardWalletType = "masterpass"
PaymentMethodCardWalletTypeSamsungPay PaymentMethodCardWalletType = "samsung_pay"
PaymentMethodCardWalletTypeVisaCheckout PaymentMethodCardWalletType = "visa_checkout"
)
// BillingDetailsParams is the set of parameters that can be used as billing details
// when creating or updating a PaymentMethod
type BillingDetailsParams struct {
Address *AddressParams `form:"address"`
Email *string `form:"email"`
Name *string `form:"name"`
Phone *string `form:"phone"`
}
// PaymentMethodCardParams is the set of parameters allowed for the `card` hash when creating a
// PaymentMethod of type card.
type PaymentMethodCardParams struct {
CVC *string `form:"cvc"`
ExpMonth *string `form:"exp_month"`
ExpYear *string `form:"exp_year"`
Number *string `form:"number"`
Token *string `form:"token"`
}
// PaymentMethodFPXParams is the set of parameters allowed for the `fpx` hash when creating a
// PaymentMethod of type fpx.
type PaymentMethodFPXParams struct {
AccountHolderType *string `form:"account_holder_type"`
Bank *string `form:"bank"`
}
// PaymentMethodParams is the set of parameters that can be used when creating or updating a
// PaymentMethod.
type PaymentMethodParams struct {
Params `form:"*"`
BillingDetails *BillingDetailsParams `form:"billing_details"`
Card *PaymentMethodCardParams `form:"card"`
FPX *PaymentMethodFPXParams `form:"fpx"`
PaymentMethod *string `form:"payment_method"`
Type *string `form:"type"`
}
// PaymentMethodAttachParams is the set of parameters that can be used when attaching a
// PaymentMethod to a Customer.
type PaymentMethodAttachParams struct {
Params `form:"*"`
Customer *string `form:"customer"`
}
// PaymentMethodDetachParams is the set of parameters that can be used when detaching a
// PaymentMethod.
type PaymentMethodDetachParams struct {
Params `form:"*"`
}
// PaymentMethodListParams is the set of parameters that can be used when listing PaymentMethods.
type PaymentMethodListParams struct {
ListParams `form:"*"`
Customer *string `form:"customer"`
Type *string `form:"type"`
}
// BillingDetails represents the billing details associated with a PaymentMethod.
type BillingDetails struct {
Address *Address `json:"address"`
Email string `json:"email"`
Name string `json:"name"`
Phone string `json:"phone"`
}
// PaymentMethodCardChecks represents the checks associated with a Card PaymentMethod.
type PaymentMethodCardChecks struct {
AddressLine1Check CardVerification `json:"address_line1_check"`
AddressPostalCodeCheck CardVerification `json:"address_postal_code_check"`
CVCCheck CardVerification `json:"cvc_check"`
}
// PaymentMethodCardThreeDSecureUsage represents the 3DS usage for that Card PaymentMethod.
type PaymentMethodCardThreeDSecureUsage struct {
Supported bool `json:"supported"`
}
// PaymentMethodCardWallet represents the details of the card wallet if this Card PaymentMethod
// is part of a card wallet.
type PaymentMethodCardWallet struct {
DynamicLast4 string `json:"dynamic_last4"`
Type PaymentMethodCardWalletType `json:"type"`
}
// PaymentMethodCard represents the card-specific properties on a PaymentMethod.
type PaymentMethodCard struct {
Brand PaymentMethodCardBrand `json:"brand"`
Checks *PaymentMethodCardChecks `json:"checks"`
Country string `json:"country"`
ExpMonth uint64 `json:"exp_month"`
ExpYear uint64 `json:"exp_year"`
Fingerprint string `json:"fingerprint"`
Funding CardFunding `json:"funding"`
Last4 string `json:"last4"`
ThreeDSecureUsage *PaymentMethodCardThreeDSecureUsage `json:"three_d_secure_usage"`
Wallet *PaymentMethodCardWallet `json:"wallet"`
// Please note that the fields below are for internal use only and are not returned
// as part of standard API requests.
Description string `json:"description"`
IIN string `json:"iin"`
Issuer string `json:"issuer"`
}
// PaymentMethodCardPresent represents the card-present-specific properties on a PaymentMethod.
type PaymentMethodCardPresent struct {
}
// PaymentMethodFPX represents Malaysia FPX PaymentMethod (Malaysia Only).
type PaymentMethodFPX struct {
AccountHolderType PaymentMethodFPXAccountHolderType `json:"account_holder_type"`
Bank string `json:"bank"`
TransactionID string `json:"transaction_id"`
}
// PaymentMethod is the resource representing a PaymentMethod.
type PaymentMethod struct {
BillingDetails *BillingDetails `json:"billing_details"`
Card *PaymentMethodCard `json:"card"`
CardPresent *PaymentMethodCardPresent `json:"card_present"`
Created int64 `json:"created"`
Customer *Customer `json:"customer"`
FPX *PaymentMethodFPX `json:"fpx"`
ID string `json:"id"`
Livemode bool `json:"livemode"`
Metadata map[string]string `json:"metadata"`
Object string `json:"object"`
Type PaymentMethodType `json:"type"`
}
// PaymentMethodList is a list of PaymentMethods as retrieved from a list endpoint.
type PaymentMethodList struct {
ListMeta
Data []*PaymentMethod `json:"data"`
}
// UnmarshalJSON handles deserialization of a PaymentMethod.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (i *PaymentMethod) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
i.ID = id
return nil
}
type pm PaymentMethod
var v pm
if err := json.Unmarshal(data, &v); err != nil {
return err
}
*i = PaymentMethod(v)
return nil
}