-
Notifications
You must be signed in to change notification settings - Fork 1
/
invoice_payment.go
123 lines (116 loc) · 4.94 KB
/
invoice_payment.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
package models
import (
"encoding/json"
"log"
"time"
)
// InvoicePayment represents a InvoicePayment struct.
type InvoicePayment struct {
TransactionTime *time.Time `json:"transaction_time,omitempty"`
Memo *string `json:"memo,omitempty"`
OriginalAmount *string `json:"original_amount,omitempty"`
AppliedAmount *string `json:"applied_amount,omitempty"`
PaymentMethod *InvoicePaymentMethod `json:"payment_method,omitempty"`
TransactionId *int `json:"transaction_id,omitempty"`
Prepayment *bool `json:"prepayment,omitempty"`
GatewayHandle Optional[string] `json:"gateway_handle"`
GatewayUsed *string `json:"gateway_used,omitempty"`
// The transaction ID for the payment as returned from the payment gateway
GatewayTransactionId Optional[string] `json:"gateway_transaction_id"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for InvoicePayment.
// It customizes the JSON marshaling process for InvoicePayment objects.
func (i InvoicePayment) MarshalJSON() (
[]byte,
error) {
return json.Marshal(i.toMap())
}
// toMap converts the InvoicePayment object to a map representation for JSON marshaling.
func (i InvoicePayment) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, i.AdditionalProperties)
if i.TransactionTime != nil {
structMap["transaction_time"] = i.TransactionTime.Format(time.RFC3339)
}
if i.Memo != nil {
structMap["memo"] = i.Memo
}
if i.OriginalAmount != nil {
structMap["original_amount"] = i.OriginalAmount
}
if i.AppliedAmount != nil {
structMap["applied_amount"] = i.AppliedAmount
}
if i.PaymentMethod != nil {
structMap["payment_method"] = i.PaymentMethod.toMap()
}
if i.TransactionId != nil {
structMap["transaction_id"] = i.TransactionId
}
if i.Prepayment != nil {
structMap["prepayment"] = i.Prepayment
}
if i.GatewayHandle.IsValueSet() {
if i.GatewayHandle.Value() != nil {
structMap["gateway_handle"] = i.GatewayHandle.Value()
} else {
structMap["gateway_handle"] = nil
}
}
if i.GatewayUsed != nil {
structMap["gateway_used"] = i.GatewayUsed
}
if i.GatewayTransactionId.IsValueSet() {
if i.GatewayTransactionId.Value() != nil {
structMap["gateway_transaction_id"] = i.GatewayTransactionId.Value()
} else {
structMap["gateway_transaction_id"] = nil
}
}
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for InvoicePayment.
// It customizes the JSON unmarshaling process for InvoicePayment objects.
func (i *InvoicePayment) UnmarshalJSON(input []byte) error {
var temp invoicePayment
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "transaction_time", "memo", "original_amount", "applied_amount", "payment_method", "transaction_id", "prepayment", "gateway_handle", "gateway_used", "gateway_transaction_id")
if err != nil {
return err
}
i.AdditionalProperties = additionalProperties
if temp.TransactionTime != nil {
TransactionTimeVal, err := time.Parse(time.RFC3339, *temp.TransactionTime)
if err != nil {
log.Fatalf("Cannot Parse transaction_time as % s format.", time.RFC3339)
}
i.TransactionTime = &TransactionTimeVal
}
i.Memo = temp.Memo
i.OriginalAmount = temp.OriginalAmount
i.AppliedAmount = temp.AppliedAmount
i.PaymentMethod = temp.PaymentMethod
i.TransactionId = temp.TransactionId
i.Prepayment = temp.Prepayment
i.GatewayHandle = temp.GatewayHandle
i.GatewayUsed = temp.GatewayUsed
i.GatewayTransactionId = temp.GatewayTransactionId
return nil
}
// invoicePayment is a temporary struct used for validating the fields of InvoicePayment.
type invoicePayment struct {
TransactionTime *string `json:"transaction_time,omitempty"`
Memo *string `json:"memo,omitempty"`
OriginalAmount *string `json:"original_amount,omitempty"`
AppliedAmount *string `json:"applied_amount,omitempty"`
PaymentMethod *InvoicePaymentMethod `json:"payment_method,omitempty"`
TransactionId *int `json:"transaction_id,omitempty"`
Prepayment *bool `json:"prepayment,omitempty"`
GatewayHandle Optional[string] `json:"gateway_handle"`
GatewayUsed *string `json:"gateway_used,omitempty"`
GatewayTransactionId Optional[string] `json:"gateway_transaction_id"`
}