-
Notifications
You must be signed in to change notification settings - Fork 1
/
invoice_refund.go
103 lines (96 loc) · 3.92 KB
/
invoice_refund.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
package models
import (
"encoding/json"
)
// InvoiceRefund represents a InvoiceRefund struct.
type InvoiceRefund struct {
TransactionId *int `json:"transaction_id,omitempty"`
PaymentId *int `json:"payment_id,omitempty"`
Memo *string `json:"memo,omitempty"`
OriginalAmount *string `json:"original_amount,omitempty"`
AppliedAmount *string `json:"applied_amount,omitempty"`
// The transaction ID for the refund as returned from the payment gateway
GatewayTransactionId Optional[string] `json:"gateway_transaction_id"`
GatewayUsed *string `json:"gateway_used,omitempty"`
GatewayHandle Optional[string] `json:"gateway_handle"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for InvoiceRefund.
// It customizes the JSON marshaling process for InvoiceRefund objects.
func (i InvoiceRefund) MarshalJSON() (
[]byte,
error) {
return json.Marshal(i.toMap())
}
// toMap converts the InvoiceRefund object to a map representation for JSON marshaling.
func (i InvoiceRefund) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, i.AdditionalProperties)
if i.TransactionId != nil {
structMap["transaction_id"] = i.TransactionId
}
if i.PaymentId != nil {
structMap["payment_id"] = i.PaymentId
}
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.GatewayTransactionId.IsValueSet() {
if i.GatewayTransactionId.Value() != nil {
structMap["gateway_transaction_id"] = i.GatewayTransactionId.Value()
} else {
structMap["gateway_transaction_id"] = nil
}
}
if i.GatewayUsed != nil {
structMap["gateway_used"] = i.GatewayUsed
}
if i.GatewayHandle.IsValueSet() {
if i.GatewayHandle.Value() != nil {
structMap["gateway_handle"] = i.GatewayHandle.Value()
} else {
structMap["gateway_handle"] = nil
}
}
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for InvoiceRefund.
// It customizes the JSON unmarshaling process for InvoiceRefund objects.
func (i *InvoiceRefund) UnmarshalJSON(input []byte) error {
var temp invoiceRefund
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "transaction_id", "payment_id", "memo", "original_amount", "applied_amount", "gateway_transaction_id", "gateway_used", "gateway_handle")
if err != nil {
return err
}
i.AdditionalProperties = additionalProperties
i.TransactionId = temp.TransactionId
i.PaymentId = temp.PaymentId
i.Memo = temp.Memo
i.OriginalAmount = temp.OriginalAmount
i.AppliedAmount = temp.AppliedAmount
i.GatewayTransactionId = temp.GatewayTransactionId
i.GatewayUsed = temp.GatewayUsed
i.GatewayHandle = temp.GatewayHandle
return nil
}
// invoiceRefund is a temporary struct used for validating the fields of InvoiceRefund.
type invoiceRefund struct {
TransactionId *int `json:"transaction_id,omitempty"`
PaymentId *int `json:"payment_id,omitempty"`
Memo *string `json:"memo,omitempty"`
OriginalAmount *string `json:"original_amount,omitempty"`
AppliedAmount *string `json:"applied_amount,omitempty"`
GatewayTransactionId Optional[string] `json:"gateway_transaction_id"`
GatewayUsed *string `json:"gateway_used,omitempty"`
GatewayHandle Optional[string] `json:"gateway_handle"`
}