-
Notifications
You must be signed in to change notification settings - Fork 1
/
payment_related_events.go
74 lines (66 loc) · 2.41 KB
/
payment_related_events.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
package models
import (
"encoding/json"
"errors"
"strings"
)
// PaymentRelatedEvents represents a PaymentRelatedEvents struct.
type PaymentRelatedEvents struct {
ProductId int `json:"product_id"`
AccountTransactionId int `json:"account_transaction_id"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for PaymentRelatedEvents.
// It customizes the JSON marshaling process for PaymentRelatedEvents objects.
func (p PaymentRelatedEvents) MarshalJSON() (
[]byte,
error) {
return json.Marshal(p.toMap())
}
// toMap converts the PaymentRelatedEvents object to a map representation for JSON marshaling.
func (p PaymentRelatedEvents) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, p.AdditionalProperties)
structMap["product_id"] = p.ProductId
structMap["account_transaction_id"] = p.AccountTransactionId
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for PaymentRelatedEvents.
// It customizes the JSON unmarshaling process for PaymentRelatedEvents objects.
func (p *PaymentRelatedEvents) UnmarshalJSON(input []byte) error {
var temp paymentRelatedEvents
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
err = temp.validate()
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "product_id", "account_transaction_id")
if err != nil {
return err
}
p.AdditionalProperties = additionalProperties
p.ProductId = *temp.ProductId
p.AccountTransactionId = *temp.AccountTransactionId
return nil
}
// paymentRelatedEvents is a temporary struct used for validating the fields of PaymentRelatedEvents.
type paymentRelatedEvents struct {
ProductId *int `json:"product_id"`
AccountTransactionId *int `json:"account_transaction_id"`
}
func (p *paymentRelatedEvents) validate() error {
var errs []string
if p.ProductId == nil {
errs = append(errs, "required field `product_id` is missing for type `Payment Related Events`")
}
if p.AccountTransactionId == nil {
errs = append(errs, "required field `account_transaction_id` is missing for type `Payment Related Events`")
}
if len(errs) == 0 {
return nil
}
return errors.New(strings.Join(errs, "\n"))
}