-
Notifications
You must be signed in to change notification settings - Fork 1
/
remove_payment_event.go
102 lines (94 loc) · 3.52 KB
/
remove_payment_event.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
package models
import (
"encoding/json"
"errors"
"log"
"strings"
"time"
)
// RemovePaymentEvent represents a RemovePaymentEvent struct.
type RemovePaymentEvent struct {
Id int64 `json:"id"`
Timestamp time.Time `json:"timestamp"`
Invoice Invoice `json:"invoice"`
EventType InvoiceEventType `json:"event_type"`
// Example schema for an `remove_payment` event
EventData RemovePaymentEventData `json:"event_data"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for RemovePaymentEvent.
// It customizes the JSON marshaling process for RemovePaymentEvent objects.
func (r RemovePaymentEvent) MarshalJSON() (
[]byte,
error) {
return json.Marshal(r.toMap())
}
// toMap converts the RemovePaymentEvent object to a map representation for JSON marshaling.
func (r RemovePaymentEvent) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, r.AdditionalProperties)
structMap["id"] = r.Id
structMap["timestamp"] = r.Timestamp.Format(time.RFC3339)
structMap["invoice"] = r.Invoice.toMap()
structMap["event_type"] = r.EventType
structMap["event_data"] = r.EventData.toMap()
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for RemovePaymentEvent.
// It customizes the JSON unmarshaling process for RemovePaymentEvent objects.
func (r *RemovePaymentEvent) UnmarshalJSON(input []byte) error {
var temp removePaymentEvent
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
err = temp.validate()
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "id", "timestamp", "invoice", "event_type", "event_data")
if err != nil {
return err
}
r.AdditionalProperties = additionalProperties
r.Id = *temp.Id
TimestampVal, err := time.Parse(time.RFC3339, *temp.Timestamp)
if err != nil {
log.Fatalf("Cannot Parse timestamp as % s format.", time.RFC3339)
}
r.Timestamp = TimestampVal
r.Invoice = *temp.Invoice
r.EventType = *temp.EventType
r.EventData = *temp.EventData
return nil
}
// removePaymentEvent is a temporary struct used for validating the fields of RemovePaymentEvent.
type removePaymentEvent struct {
Id *int64 `json:"id"`
Timestamp *string `json:"timestamp"`
Invoice *Invoice `json:"invoice"`
EventType *InvoiceEventType `json:"event_type"`
EventData *RemovePaymentEventData `json:"event_data"`
}
func (r *removePaymentEvent) validate() error {
var errs []string
if r.Id == nil {
errs = append(errs, "required field `id` is missing for type `Remove Payment Event`")
}
if r.Timestamp == nil {
errs = append(errs, "required field `timestamp` is missing for type `Remove Payment Event`")
}
if r.Invoice == nil {
errs = append(errs, "required field `invoice` is missing for type `Remove Payment Event`")
}
if r.EventType == nil {
errs = append(errs, "required field `event_type` is missing for type `Remove Payment Event`")
}
if r.EventData == nil {
errs = append(errs, "required field `event_data` is missing for type `Remove Payment Event`")
}
if len(errs) == 0 {
return nil
}
return errors.New(strings.Join(errs, "\n"))
}