forked from pagarme/pagarme-golang-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createPaymentRequest.go
131 lines (125 loc) · 4.87 KB
/
createPaymentRequest.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
package models
import (
"encoding/json"
)
// Payment data
type CreatePaymentRequest struct {
PaymentMethod string `json:"payment_method"`
CreditCard *CreateCreditCardPaymentRequest `json:"credit_card,omitempty"`
DebitCard *CreateDebitCardPaymentRequest `json:"debit_card,omitempty"`
Boleto *CreateBoletoPaymentRequest `json:"boleto,omitempty"`
Currency *string `json:"currency,omitempty"`
Voucher *CreateVoucherPaymentRequest `json:"voucher,omitempty"`
Split *[]CreateSplitRequest `json:"split,omitempty"`
BankTransfer *CreateBankTransferPaymentRequest `json:"bank_transfer,omitempty"`
GatewayAffiliationId *string `json:"gateway_affiliation_id,omitempty"`
Amount *int `json:"amount,omitempty"`
Checkout *CreateCheckoutPaymentRequest `json:"checkout,omitempty"`
CustomerId *string `json:"customer_id,omitempty"`
Customer *CreateCustomerRequest `json:"customer,omitempty"`
Metadata map[string]*string `json:"metadata,omitempty"`
Cash *CreateCashPaymentRequest `json:"cash,omitempty"`
PrivateLabel *CreatePrivateLabelPaymentRequest `json:"private_label,omitempty"`
Pix *CreatePixPaymentRequest `json:"pix,omitempty"`
}
func (c *CreatePaymentRequest) MarshalJSON() (
[]byte,
error) {
return json.Marshal(c.toMap())
}
func (c *CreatePaymentRequest) toMap() map[string]any {
structMap := make(map[string]any)
structMap["payment_method"] = c.PaymentMethod
if c.CreditCard != nil {
structMap["credit_card"] = c.CreditCard
}
if c.DebitCard != nil {
structMap["debit_card"] = c.DebitCard
}
if c.Boleto != nil {
structMap["boleto"] = c.Boleto
}
if c.Currency != nil {
structMap["currency"] = c.Currency
}
if c.Voucher != nil {
structMap["voucher"] = c.Voucher
}
if c.Split != nil {
structMap["split"] = c.Split
}
if c.BankTransfer != nil {
structMap["bank_transfer"] = c.BankTransfer
}
if c.GatewayAffiliationId != nil {
structMap["gateway_affiliation_id"] = c.GatewayAffiliationId
}
if c.Amount != nil {
structMap["amount"] = c.Amount
}
if c.Checkout != nil {
structMap["checkout"] = c.Checkout
}
if c.CustomerId != nil {
structMap["customer_id"] = c.CustomerId
}
if c.Customer != nil {
structMap["customer"] = c.Customer
}
if c.Metadata != nil {
structMap["metadata"] = c.Metadata
}
if c.Cash != nil {
structMap["cash"] = c.Cash
}
if c.PrivateLabel != nil {
structMap["private_label"] = c.PrivateLabel
}
if c.Pix != nil {
structMap["pix"] = c.Pix
}
return structMap
}
func (c *CreatePaymentRequest) UnmarshalJSON(input []byte) error {
temp := &struct {
PaymentMethod string `json:"payment_method"`
CreditCard *CreateCreditCardPaymentRequest `json:"credit_card,omitempty"`
DebitCard *CreateDebitCardPaymentRequest `json:"debit_card,omitempty"`
Boleto *CreateBoletoPaymentRequest `json:"boleto,omitempty"`
Currency *string `json:"currency,omitempty"`
Voucher *CreateVoucherPaymentRequest `json:"voucher,omitempty"`
Split *[]CreateSplitRequest `json:"split,omitempty"`
BankTransfer *CreateBankTransferPaymentRequest `json:"bank_transfer,omitempty"`
GatewayAffiliationId *string `json:"gateway_affiliation_id,omitempty"`
Amount *int `json:"amount,omitempty"`
Checkout *CreateCheckoutPaymentRequest `json:"checkout,omitempty"`
CustomerId *string `json:"customer_id,omitempty"`
Customer *CreateCustomerRequest `json:"customer,omitempty"`
Metadata map[string]*string `json:"metadata,omitempty"`
Cash *CreateCashPaymentRequest `json:"cash,omitempty"`
PrivateLabel *CreatePrivateLabelPaymentRequest `json:"private_label,omitempty"`
Pix *CreatePixPaymentRequest `json:"pix,omitempty"`
}{}
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
c.PaymentMethod = temp.PaymentMethod
c.CreditCard = temp.CreditCard
c.DebitCard = temp.DebitCard
c.Boleto = temp.Boleto
c.Currency = temp.Currency
c.Voucher = temp.Voucher
c.Split = temp.Split
c.BankTransfer = temp.BankTransfer
c.GatewayAffiliationId = temp.GatewayAffiliationId
c.Amount = temp.Amount
c.Checkout = temp.Checkout
c.CustomerId = temp.CustomerId
c.Customer = temp.Customer
c.Metadata = temp.Metadata
c.Cash = temp.Cash
c.PrivateLabel = temp.PrivateLabel
c.Pix = temp.Pix
return nil
}