-
Notifications
You must be signed in to change notification settings - Fork 1
/
refund_consolidated_invoice.go
106 lines (98 loc) · 4.28 KB
/
refund_consolidated_invoice.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
package models
import (
"encoding/json"
"errors"
"strings"
)
// RefundConsolidatedInvoice represents a RefundConsolidatedInvoice struct.
// Refund consolidated invoice
type RefundConsolidatedInvoice struct {
// A description for the refund
Memo string `json:"memo"`
// The ID of the payment to be refunded
PaymentId int `json:"payment_id"`
// An array of segment uids to refund or the string 'all' to indicate that all segments should be refunded
SegmentUids RefundConsolidatedInvoiceSegmentUids `json:"segment_uids"`
// Flag that marks refund as external (no money is returned to the customer). Defaults to `false`.
External *bool `json:"external,omitempty"`
// If set to true, creates credit and applies it to an invoice. Defaults to `false`.
ApplyCredit *bool `json:"apply_credit,omitempty"`
// The amount of payment to be refunded in decimal format. Example: "10.50". This will default to the full amount of the payment if not provided.
Amount *string `json:"amount,omitempty"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for RefundConsolidatedInvoice.
// It customizes the JSON marshaling process for RefundConsolidatedInvoice objects.
func (r RefundConsolidatedInvoice) MarshalJSON() (
[]byte,
error) {
return json.Marshal(r.toMap())
}
// toMap converts the RefundConsolidatedInvoice object to a map representation for JSON marshaling.
func (r RefundConsolidatedInvoice) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, r.AdditionalProperties)
structMap["memo"] = r.Memo
structMap["payment_id"] = r.PaymentId
structMap["segment_uids"] = r.SegmentUids.toMap()
if r.External != nil {
structMap["external"] = r.External
}
if r.ApplyCredit != nil {
structMap["apply_credit"] = r.ApplyCredit
}
if r.Amount != nil {
structMap["amount"] = r.Amount
}
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for RefundConsolidatedInvoice.
// It customizes the JSON unmarshaling process for RefundConsolidatedInvoice objects.
func (r *RefundConsolidatedInvoice) UnmarshalJSON(input []byte) error {
var temp refundConsolidatedInvoice
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
err = temp.validate()
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "memo", "payment_id", "segment_uids", "external", "apply_credit", "amount")
if err != nil {
return err
}
r.AdditionalProperties = additionalProperties
r.Memo = *temp.Memo
r.PaymentId = *temp.PaymentId
r.SegmentUids = *temp.SegmentUids
r.External = temp.External
r.ApplyCredit = temp.ApplyCredit
r.Amount = temp.Amount
return nil
}
// refundConsolidatedInvoice is a temporary struct used for validating the fields of RefundConsolidatedInvoice.
type refundConsolidatedInvoice struct {
Memo *string `json:"memo"`
PaymentId *int `json:"payment_id"`
SegmentUids *RefundConsolidatedInvoiceSegmentUids `json:"segment_uids"`
External *bool `json:"external,omitempty"`
ApplyCredit *bool `json:"apply_credit,omitempty"`
Amount *string `json:"amount,omitempty"`
}
func (r *refundConsolidatedInvoice) validate() error {
var errs []string
if r.Memo == nil {
errs = append(errs, "required field `memo` is missing for type `Refund Consolidated Invoice`")
}
if r.PaymentId == nil {
errs = append(errs, "required field `payment_id` is missing for type `Refund Consolidated Invoice`")
}
if r.SegmentUids == nil {
errs = append(errs, "required field `segment_uids` is missing for type `Refund Consolidated Invoice`")
}
if len(errs) == 0 {
return nil
}
return errors.New(strings.Join(errs, "\n"))
}