-
Notifications
You must be signed in to change notification settings - Fork 1
/
credit_card_payment_profile.go
252 lines (244 loc) · 10.9 KB
/
credit_card_payment_profile.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
package models
import (
"encoding/json"
"errors"
"strings"
)
// CreditCardPaymentProfile represents a CreditCardPaymentProfile struct.
type CreditCardPaymentProfile struct {
// The Chargify-assigned ID of the stored card. This value can be used as an input to payment_profile_id when creating a subscription, in order to re-use a stored payment profile for the same customer.
Id *int `json:"id,omitempty"`
// The first name of the card holder.
FirstName *string `json:"first_name,omitempty"`
// The last name of the card holder.
LastName *string `json:"last_name,omitempty"`
// A string representation of the credit card number with all but the last 4 digits masked with X’s (i.e. ‘XXXX-XXXX-XXXX-1234’).
MaskedCardNumber string `json:"masked_card_number"`
// The type of card used.
CardType *CardType `json:"card_type,omitempty"`
// An integer representing the expiration month of the card(1 – 12).
ExpirationMonth *int `json:"expiration_month,omitempty"`
// An integer representing the 4-digit expiration year of the card(i.e. ‘2012’).
ExpirationYear *int `json:"expiration_year,omitempty"`
// The Chargify-assigned id for the customer record to which the card belongs.
CustomerId *int `json:"customer_id,omitempty"`
// The vault that stores the payment profile with the provided `vault_token`. Use `bogus` for testing.
CurrentVault *CurrentVault `json:"current_vault,omitempty"`
// The “token” provided by your vault storage for an already stored payment profile.
VaultToken Optional[string] `json:"vault_token"`
// The current billing street address for the card.
BillingAddress Optional[string] `json:"billing_address"`
// The current billing address city for the card.
BillingCity Optional[string] `json:"billing_city"`
// The current billing address state for the card.
BillingState Optional[string] `json:"billing_state"`
// The current billing address zip code for the card.
BillingZip Optional[string] `json:"billing_zip"`
// The current billing address country for the card.
BillingCountry Optional[string] `json:"billing_country"`
// (only for Authorize.Net CIM storage): the customerProfileId for the owner of the customerPaymentProfileId provided as the vault_token.
CustomerVaultToken Optional[string] `json:"customer_vault_token"`
// The current billing street address, second line, for the card.
BillingAddress2 Optional[string] `json:"billing_address_2"`
PaymentType *PaymentType `json:"payment_type,omitempty"`
Disabled *bool `json:"disabled,omitempty"`
// Token received after sending billing information using chargify.js. This token will only be received if passed as a sole attribute of credit_card_attributes (i.e. tok_9g6hw85pnpt6knmskpwp4ttt)
ChargifyToken *string `json:"chargify_token,omitempty"`
SiteGatewaySettingId Optional[int] `json:"site_gateway_setting_id"`
// An identifier of connected gateway.
GatewayHandle Optional[string] `json:"gateway_handle"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for CreditCardPaymentProfile.
// It customizes the JSON marshaling process for CreditCardPaymentProfile objects.
func (c CreditCardPaymentProfile) MarshalJSON() (
[]byte,
error) {
return json.Marshal(c.toMap())
}
// toMap converts the CreditCardPaymentProfile object to a map representation for JSON marshaling.
func (c CreditCardPaymentProfile) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, c.AdditionalProperties)
if c.Id != nil {
structMap["id"] = c.Id
}
if c.FirstName != nil {
structMap["first_name"] = c.FirstName
}
if c.LastName != nil {
structMap["last_name"] = c.LastName
}
structMap["masked_card_number"] = c.MaskedCardNumber
if c.CardType != nil {
structMap["card_type"] = c.CardType
}
if c.ExpirationMonth != nil {
structMap["expiration_month"] = c.ExpirationMonth
}
if c.ExpirationYear != nil {
structMap["expiration_year"] = c.ExpirationYear
}
if c.CustomerId != nil {
structMap["customer_id"] = c.CustomerId
}
if c.CurrentVault != nil {
structMap["current_vault"] = c.CurrentVault
}
if c.VaultToken.IsValueSet() {
if c.VaultToken.Value() != nil {
structMap["vault_token"] = c.VaultToken.Value()
} else {
structMap["vault_token"] = nil
}
}
if c.BillingAddress.IsValueSet() {
if c.BillingAddress.Value() != nil {
structMap["billing_address"] = c.BillingAddress.Value()
} else {
structMap["billing_address"] = nil
}
}
if c.BillingCity.IsValueSet() {
if c.BillingCity.Value() != nil {
structMap["billing_city"] = c.BillingCity.Value()
} else {
structMap["billing_city"] = nil
}
}
if c.BillingState.IsValueSet() {
if c.BillingState.Value() != nil {
structMap["billing_state"] = c.BillingState.Value()
} else {
structMap["billing_state"] = nil
}
}
if c.BillingZip.IsValueSet() {
if c.BillingZip.Value() != nil {
structMap["billing_zip"] = c.BillingZip.Value()
} else {
structMap["billing_zip"] = nil
}
}
if c.BillingCountry.IsValueSet() {
if c.BillingCountry.Value() != nil {
structMap["billing_country"] = c.BillingCountry.Value()
} else {
structMap["billing_country"] = nil
}
}
if c.CustomerVaultToken.IsValueSet() {
if c.CustomerVaultToken.Value() != nil {
structMap["customer_vault_token"] = c.CustomerVaultToken.Value()
} else {
structMap["customer_vault_token"] = nil
}
}
if c.BillingAddress2.IsValueSet() {
if c.BillingAddress2.Value() != nil {
structMap["billing_address_2"] = c.BillingAddress2.Value()
} else {
structMap["billing_address_2"] = nil
}
}
if c.PaymentType != nil {
structMap["payment_type"] = c.PaymentType
}
if c.Disabled != nil {
structMap["disabled"] = c.Disabled
}
if c.ChargifyToken != nil {
structMap["chargify_token"] = c.ChargifyToken
}
if c.SiteGatewaySettingId.IsValueSet() {
if c.SiteGatewaySettingId.Value() != nil {
structMap["site_gateway_setting_id"] = c.SiteGatewaySettingId.Value()
} else {
structMap["site_gateway_setting_id"] = nil
}
}
if c.GatewayHandle.IsValueSet() {
if c.GatewayHandle.Value() != nil {
structMap["gateway_handle"] = c.GatewayHandle.Value()
} else {
structMap["gateway_handle"] = nil
}
}
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for CreditCardPaymentProfile.
// It customizes the JSON unmarshaling process for CreditCardPaymentProfile objects.
func (c *CreditCardPaymentProfile) UnmarshalJSON(input []byte) error {
var temp creditCardPaymentProfile
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
err = temp.validate()
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "id", "first_name", "last_name", "masked_card_number", "card_type", "expiration_month", "expiration_year", "customer_id", "current_vault", "vault_token", "billing_address", "billing_city", "billing_state", "billing_zip", "billing_country", "customer_vault_token", "billing_address_2", "payment_type", "disabled", "chargify_token", "site_gateway_setting_id", "gateway_handle")
if err != nil {
return err
}
c.AdditionalProperties = additionalProperties
c.Id = temp.Id
c.FirstName = temp.FirstName
c.LastName = temp.LastName
c.MaskedCardNumber = *temp.MaskedCardNumber
c.CardType = temp.CardType
c.ExpirationMonth = temp.ExpirationMonth
c.ExpirationYear = temp.ExpirationYear
c.CustomerId = temp.CustomerId
c.CurrentVault = temp.CurrentVault
c.VaultToken = temp.VaultToken
c.BillingAddress = temp.BillingAddress
c.BillingCity = temp.BillingCity
c.BillingState = temp.BillingState
c.BillingZip = temp.BillingZip
c.BillingCountry = temp.BillingCountry
c.CustomerVaultToken = temp.CustomerVaultToken
c.BillingAddress2 = temp.BillingAddress2
c.PaymentType = temp.PaymentType
c.Disabled = temp.Disabled
c.ChargifyToken = temp.ChargifyToken
c.SiteGatewaySettingId = temp.SiteGatewaySettingId
c.GatewayHandle = temp.GatewayHandle
return nil
}
// creditCardPaymentProfile is a temporary struct used for validating the fields of CreditCardPaymentProfile.
type creditCardPaymentProfile struct {
Id *int `json:"id,omitempty"`
FirstName *string `json:"first_name,omitempty"`
LastName *string `json:"last_name,omitempty"`
MaskedCardNumber *string `json:"masked_card_number"`
CardType *CardType `json:"card_type,omitempty"`
ExpirationMonth *int `json:"expiration_month,omitempty"`
ExpirationYear *int `json:"expiration_year,omitempty"`
CustomerId *int `json:"customer_id,omitempty"`
CurrentVault *CurrentVault `json:"current_vault,omitempty"`
VaultToken Optional[string] `json:"vault_token"`
BillingAddress Optional[string] `json:"billing_address"`
BillingCity Optional[string] `json:"billing_city"`
BillingState Optional[string] `json:"billing_state"`
BillingZip Optional[string] `json:"billing_zip"`
BillingCountry Optional[string] `json:"billing_country"`
CustomerVaultToken Optional[string] `json:"customer_vault_token"`
BillingAddress2 Optional[string] `json:"billing_address_2"`
PaymentType *PaymentType `json:"payment_type,omitempty"`
Disabled *bool `json:"disabled,omitempty"`
ChargifyToken *string `json:"chargify_token,omitempty"`
SiteGatewaySettingId Optional[int] `json:"site_gateway_setting_id"`
GatewayHandle Optional[string] `json:"gateway_handle"`
}
func (c *creditCardPaymentProfile) validate() error {
var errs []string
if c.MaskedCardNumber == nil {
errs = append(errs, "required field `masked_card_number` is missing for type `Credit Card Payment Profile`")
}
if len(errs) == 0 {
return nil
}
return errors.New(strings.Join(errs, "\n"))
}