forked from pagarme/pagarme-golang-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateChargePaymentMethodRequest.go
67 lines (61 loc) · 2.51 KB
/
updateChargePaymentMethodRequest.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
package models
import (
"encoding/json"
)
// Request for updating the payment method of a charge
type UpdateChargePaymentMethodRequest struct {
UpdateSubscription bool `json:"update_subscription"`
PaymentMethod string `json:"payment_method"`
CreditCard CreateCreditCardPaymentRequest `json:"credit_card"`
DebitCard CreateDebitCardPaymentRequest `json:"debit_card"`
Boleto CreateBoletoPaymentRequest `json:"boleto"`
Voucher CreateVoucherPaymentRequest `json:"voucher"`
Cash CreateCashPaymentRequest `json:"cash"`
BankTransfer CreateBankTransferPaymentRequest `json:"bank_transfer"`
PrivateLabel CreatePrivateLabelPaymentRequest `json:"private_label"`
}
func (u *UpdateChargePaymentMethodRequest) MarshalJSON() (
[]byte,
error) {
return json.Marshal(u.toMap())
}
func (u *UpdateChargePaymentMethodRequest) toMap() map[string]any {
structMap := make(map[string]any)
structMap["update_subscription"] = u.UpdateSubscription
structMap["payment_method"] = u.PaymentMethod
structMap["credit_card"] = u.CreditCard
structMap["debit_card"] = u.DebitCard
structMap["boleto"] = u.Boleto
structMap["voucher"] = u.Voucher
structMap["cash"] = u.Cash
structMap["bank_transfer"] = u.BankTransfer
structMap["private_label"] = u.PrivateLabel
return structMap
}
func (u *UpdateChargePaymentMethodRequest) UnmarshalJSON(input []byte) error {
temp := &struct {
UpdateSubscription bool `json:"update_subscription"`
PaymentMethod string `json:"payment_method"`
CreditCard CreateCreditCardPaymentRequest `json:"credit_card"`
DebitCard CreateDebitCardPaymentRequest `json:"debit_card"`
Boleto CreateBoletoPaymentRequest `json:"boleto"`
Voucher CreateVoucherPaymentRequest `json:"voucher"`
Cash CreateCashPaymentRequest `json:"cash"`
BankTransfer CreateBankTransferPaymentRequest `json:"bank_transfer"`
PrivateLabel CreatePrivateLabelPaymentRequest `json:"private_label"`
}{}
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
u.UpdateSubscription = temp.UpdateSubscription
u.PaymentMethod = temp.PaymentMethod
u.CreditCard = temp.CreditCard
u.DebitCard = temp.DebitCard
u.Boleto = temp.Boleto
u.Voucher = temp.Voucher
u.Cash = temp.Cash
u.BankTransfer = temp.BankTransfer
u.PrivateLabel = temp.PrivateLabel
return nil
}