-
Notifications
You must be signed in to change notification settings - Fork 1
/
subscription_group_prepayment.go
88 lines (80 loc) · 3.13 KB
/
subscription_group_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
package models
import (
"encoding/json"
"errors"
"strings"
)
// SubscriptionGroupPrepayment represents a SubscriptionGroupPrepayment struct.
type SubscriptionGroupPrepayment struct {
Amount int `json:"amount"`
Details string `json:"details"`
Memo string `json:"memo"`
Method SubscriptionGroupPrepaymentMethod `json:"method"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for SubscriptionGroupPrepayment.
// It customizes the JSON marshaling process for SubscriptionGroupPrepayment objects.
func (s SubscriptionGroupPrepayment) MarshalJSON() (
[]byte,
error) {
return json.Marshal(s.toMap())
}
// toMap converts the SubscriptionGroupPrepayment object to a map representation for JSON marshaling.
func (s SubscriptionGroupPrepayment) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, s.AdditionalProperties)
structMap["amount"] = s.Amount
structMap["details"] = s.Details
structMap["memo"] = s.Memo
structMap["method"] = s.Method
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for SubscriptionGroupPrepayment.
// It customizes the JSON unmarshaling process for SubscriptionGroupPrepayment objects.
func (s *SubscriptionGroupPrepayment) UnmarshalJSON(input []byte) error {
var temp subscriptionGroupPrepayment
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
err = temp.validate()
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "amount", "details", "memo", "method")
if err != nil {
return err
}
s.AdditionalProperties = additionalProperties
s.Amount = *temp.Amount
s.Details = *temp.Details
s.Memo = *temp.Memo
s.Method = *temp.Method
return nil
}
// subscriptionGroupPrepayment is a temporary struct used for validating the fields of SubscriptionGroupPrepayment.
type subscriptionGroupPrepayment struct {
Amount *int `json:"amount"`
Details *string `json:"details"`
Memo *string `json:"memo"`
Method *SubscriptionGroupPrepaymentMethod `json:"method"`
}
func (s *subscriptionGroupPrepayment) validate() error {
var errs []string
if s.Amount == nil {
errs = append(errs, "required field `amount` is missing for type `Subscription Group Prepayment`")
}
if s.Details == nil {
errs = append(errs, "required field `details` is missing for type `Subscription Group Prepayment`")
}
if s.Memo == nil {
errs = append(errs, "required field `memo` is missing for type `Subscription Group Prepayment`")
}
if s.Method == nil {
errs = append(errs, "required field `method` is missing for type `Subscription Group Prepayment`")
}
if len(errs) == 0 {
return nil
}
return errors.New(strings.Join(errs, "\n"))
}