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