-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_multi_invoice_payment.go
103 lines (95 loc) · 3.93 KB
/
create_multi_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
package models
import (
"encoding/json"
"errors"
"strings"
)
// CreateMultiInvoicePayment represents a CreateMultiInvoicePayment struct.
type CreateMultiInvoicePayment struct {
// A description to be attached to the payment.
Memo *string `json:"memo,omitempty"`
// Additional information related to the payment method (eg. Check #).
Details *string `json:"details,omitempty"`
// The type of payment method used. Defaults to other.
Method *InvoicePaymentMethodType `json:"method,omitempty"`
// Dollar amount of the sum of the invoices payment (eg. "10.50" => $10.50).
Amount CreateMultiInvoicePaymentAmount `json:"amount"`
// Date reflecting when the payment was received from a customer. Must be in the past.
ReceivedOn *string `json:"received_on,omitempty"`
Applications []CreateInvoicePaymentApplication `json:"applications"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for CreateMultiInvoicePayment.
// It customizes the JSON marshaling process for CreateMultiInvoicePayment objects.
func (c CreateMultiInvoicePayment) MarshalJSON() (
[]byte,
error) {
return json.Marshal(c.toMap())
}
// toMap converts the CreateMultiInvoicePayment object to a map representation for JSON marshaling.
func (c CreateMultiInvoicePayment) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, c.AdditionalProperties)
if c.Memo != nil {
structMap["memo"] = c.Memo
}
if c.Details != nil {
structMap["details"] = c.Details
}
if c.Method != nil {
structMap["method"] = c.Method
}
structMap["amount"] = c.Amount.toMap()
if c.ReceivedOn != nil {
structMap["received_on"] = c.ReceivedOn
}
structMap["applications"] = c.Applications
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for CreateMultiInvoicePayment.
// It customizes the JSON unmarshaling process for CreateMultiInvoicePayment objects.
func (c *CreateMultiInvoicePayment) UnmarshalJSON(input []byte) error {
var temp createMultiInvoicePayment
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
err = temp.validate()
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "memo", "details", "method", "amount", "received_on", "applications")
if err != nil {
return err
}
c.AdditionalProperties = additionalProperties
c.Memo = temp.Memo
c.Details = temp.Details
c.Method = temp.Method
c.Amount = *temp.Amount
c.ReceivedOn = temp.ReceivedOn
c.Applications = *temp.Applications
return nil
}
// createMultiInvoicePayment is a temporary struct used for validating the fields of CreateMultiInvoicePayment.
type createMultiInvoicePayment struct {
Memo *string `json:"memo,omitempty"`
Details *string `json:"details,omitempty"`
Method *InvoicePaymentMethodType `json:"method,omitempty"`
Amount *CreateMultiInvoicePaymentAmount `json:"amount"`
ReceivedOn *string `json:"received_on,omitempty"`
Applications *[]CreateInvoicePaymentApplication `json:"applications"`
}
func (c *createMultiInvoicePayment) validate() error {
var errs []string
if c.Amount == nil {
errs = append(errs, "required field `amount` is missing for type `Create Multi Invoice Payment`")
}
if c.Applications == nil {
errs = append(errs, "required field `applications` is missing for type `Create Multi Invoice Payment`")
}
if len(errs) == 0 {
return nil
}
return errors.New(strings.Join(errs, "\n"))
}