-
Notifications
You must be signed in to change notification settings - Fork 1
/
failed_payment_event_data.go
103 lines (95 loc) · 3.86 KB
/
failed_payment_event_data.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"
)
// FailedPaymentEventData represents a FailedPaymentEventData struct.
// Example schema for an `failed_payment` event
type FailedPaymentEventData struct {
// The monetary value of the payment, expressed in cents.
AmountInCents int `json:"amount_in_cents"`
// The monetary value of the payment, expressed in dollars.
AppliedAmount int `json:"applied_amount"`
// The memo passed when the payment was created.
Memo Optional[string] `json:"memo"`
PaymentMethod InvoicePaymentMethodType `json:"payment_method"`
// The transaction ID of the failed payment.
TransactionId int `json:"transaction_id"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for FailedPaymentEventData.
// It customizes the JSON marshaling process for FailedPaymentEventData objects.
func (f FailedPaymentEventData) MarshalJSON() (
[]byte,
error) {
return json.Marshal(f.toMap())
}
// toMap converts the FailedPaymentEventData object to a map representation for JSON marshaling.
func (f FailedPaymentEventData) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, f.AdditionalProperties)
structMap["amount_in_cents"] = f.AmountInCents
structMap["applied_amount"] = f.AppliedAmount
if f.Memo.IsValueSet() {
if f.Memo.Value() != nil {
structMap["memo"] = f.Memo.Value()
} else {
structMap["memo"] = nil
}
}
structMap["payment_method"] = f.PaymentMethod
structMap["transaction_id"] = f.TransactionId
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for FailedPaymentEventData.
// It customizes the JSON unmarshaling process for FailedPaymentEventData objects.
func (f *FailedPaymentEventData) UnmarshalJSON(input []byte) error {
var temp failedPaymentEventData
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", "applied_amount", "memo", "payment_method", "transaction_id")
if err != nil {
return err
}
f.AdditionalProperties = additionalProperties
f.AmountInCents = *temp.AmountInCents
f.AppliedAmount = *temp.AppliedAmount
f.Memo = temp.Memo
f.PaymentMethod = *temp.PaymentMethod
f.TransactionId = *temp.TransactionId
return nil
}
// failedPaymentEventData is a temporary struct used for validating the fields of FailedPaymentEventData.
type failedPaymentEventData struct {
AmountInCents *int `json:"amount_in_cents"`
AppliedAmount *int `json:"applied_amount"`
Memo Optional[string] `json:"memo"`
PaymentMethod *InvoicePaymentMethodType `json:"payment_method"`
TransactionId *int `json:"transaction_id"`
}
func (f *failedPaymentEventData) validate() error {
var errs []string
if f.AmountInCents == nil {
errs = append(errs, "required field `amount_in_cents` is missing for type `Failed Payment Event Data`")
}
if f.AppliedAmount == nil {
errs = append(errs, "required field `applied_amount` is missing for type `Failed Payment Event Data`")
}
if f.PaymentMethod == nil {
errs = append(errs, "required field `payment_method` is missing for type `Failed Payment Event Data`")
}
if f.TransactionId == nil {
errs = append(errs, "required field `transaction_id` is missing for type `Failed Payment Event Data`")
}
if len(errs) == 0 {
return nil
}
return errors.New(strings.Join(errs, "\n"))
}