-
Notifications
You must be signed in to change notification settings - Fork 1
/
refund_prepayment.go
91 lines (83 loc) · 3.14 KB
/
refund_prepayment.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
package models
import (
"encoding/json"
"errors"
"strings"
)
// RefundPrepayment represents a RefundPrepayment struct.
type RefundPrepayment struct {
// `amount` is not required if you pass `amount_in_cents`.
AmountInCents *int64 `json:"amount_in_cents"`
// `amount_in_cents` is not required if you pass `amount`.
Amount RefundPrepaymentAmount `json:"amount"`
Memo string `json:"memo"`
// Specify the type of refund you wish to initiate. When the prepayment is external, the `external` flag is optional. But if the prepayment was made through a payment profile, the `external` flag is required.
External *bool `json:"external,omitempty"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for RefundPrepayment.
// It customizes the JSON marshaling process for RefundPrepayment objects.
func (r RefundPrepayment) MarshalJSON() (
[]byte,
error) {
return json.Marshal(r.toMap())
}
// toMap converts the RefundPrepayment object to a map representation for JSON marshaling.
func (r RefundPrepayment) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, r.AdditionalProperties)
if r.AmountInCents != nil {
structMap["amount_in_cents"] = r.AmountInCents
} else {
structMap["amount_in_cents"] = nil
}
structMap["amount"] = r.Amount.toMap()
structMap["memo"] = r.Memo
if r.External != nil {
structMap["external"] = r.External
}
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for RefundPrepayment.
// It customizes the JSON unmarshaling process for RefundPrepayment objects.
func (r *RefundPrepayment) UnmarshalJSON(input []byte) error {
var temp refundPrepayment
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
err = temp.validate()
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "amount_in_cents", "amount", "memo", "external")
if err != nil {
return err
}
r.AdditionalProperties = additionalProperties
r.AmountInCents = temp.AmountInCents
r.Amount = *temp.Amount
r.Memo = *temp.Memo
r.External = temp.External
return nil
}
// refundPrepayment is a temporary struct used for validating the fields of RefundPrepayment.
type refundPrepayment struct {
AmountInCents *int64 `json:"amount_in_cents"`
Amount *RefundPrepaymentAmount `json:"amount"`
Memo *string `json:"memo"`
External *bool `json:"external,omitempty"`
}
func (r *refundPrepayment) validate() error {
var errs []string
if r.Amount == nil {
errs = append(errs, "required field `amount` is missing for type `Refund Prepayment`")
}
if r.Memo == nil {
errs = append(errs, "required field `memo` is missing for type `Refund Prepayment`")
}
if len(errs) == 0 {
return nil
}
return errors.New(strings.Join(errs, "\n"))
}