-
Notifications
You must be signed in to change notification settings - Fork 1
/
chargify_ebb.go
104 lines (97 loc) · 4.53 KB
/
chargify_ebb.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
104
package models
import (
"encoding/json"
"log"
"time"
)
// ChargifyEBB represents a ChargifyEBB struct.
type ChargifyEBB struct {
// This timestamp determines what billing period the event will be billed in. If your request payload does not include it, Chargify will add `chargify.timestamp` to the event payload and set the value to `now`.
Timestamp *time.Time `json:"timestamp,omitempty"`
// A unique ID set by Chargify. Please note that this field is reserved. If `chargify.id` is present in the request payload, it will be overwritten.
Id *string `json:"id,omitempty"`
// An ISO-8601 timestamp, set by Chargify at the time each event is recorded. Please note that this field is reserved. If `chargify.created_at` is present in the request payload, it will be overwritten.
CreatedAt *time.Time `json:"created_at,omitempty"`
// User-defined string scoped per-stream. Duplicate events within a stream will be silently ignored. Tokens expire after 31 days.
UniquenessToken *string `json:"uniqueness_token,omitempty"`
// Id of Maxio Advanced Billing Subscription which is connected to this event.
// Provide `subscription_id` if you configured `chargify.subscription_id` as Subscription Identifier in your Event Stream.
SubscriptionId *int `json:"subscription_id,omitempty"`
// Reference of Maxio Advanced Billing Subscription which is connected to this event.
// Provide `subscription_reference` if you configured `chargify.subscription_reference` as Subscription Identifier in your Event Stream.
SubscriptionReference *string `json:"subscription_reference,omitempty"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for ChargifyEBB.
// It customizes the JSON marshaling process for ChargifyEBB objects.
func (c ChargifyEBB) MarshalJSON() (
[]byte,
error) {
return json.Marshal(c.toMap())
}
// toMap converts the ChargifyEBB object to a map representation for JSON marshaling.
func (c ChargifyEBB) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, c.AdditionalProperties)
if c.Timestamp != nil {
structMap["timestamp"] = c.Timestamp.Format(time.RFC3339)
}
if c.Id != nil {
structMap["id"] = c.Id
}
if c.CreatedAt != nil {
structMap["created_at"] = c.CreatedAt.Format(time.RFC3339)
}
if c.UniquenessToken != nil {
structMap["uniqueness_token"] = c.UniquenessToken
}
if c.SubscriptionId != nil {
structMap["subscription_id"] = c.SubscriptionId
}
if c.SubscriptionReference != nil {
structMap["subscription_reference"] = c.SubscriptionReference
}
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for ChargifyEBB.
// It customizes the JSON unmarshaling process for ChargifyEBB objects.
func (c *ChargifyEBB) UnmarshalJSON(input []byte) error {
var temp chargifyEBB
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "timestamp", "id", "created_at", "uniqueness_token", "subscription_id", "subscription_reference")
if err != nil {
return err
}
c.AdditionalProperties = additionalProperties
if temp.Timestamp != nil {
TimestampVal, err := time.Parse(time.RFC3339, *temp.Timestamp)
if err != nil {
log.Fatalf("Cannot Parse timestamp as % s format.", time.RFC3339)
}
c.Timestamp = &TimestampVal
}
c.Id = temp.Id
if temp.CreatedAt != nil {
CreatedAtVal, err := time.Parse(time.RFC3339, *temp.CreatedAt)
if err != nil {
log.Fatalf("Cannot Parse created_at as % s format.", time.RFC3339)
}
c.CreatedAt = &CreatedAtVal
}
c.UniquenessToken = temp.UniquenessToken
c.SubscriptionId = temp.SubscriptionId
c.SubscriptionReference = temp.SubscriptionReference
return nil
}
// chargifyEBB is a temporary struct used for validating the fields of ChargifyEBB.
type chargifyEBB struct {
Timestamp *string `json:"timestamp,omitempty"`
Id *string `json:"id,omitempty"`
CreatedAt *string `json:"created_at,omitempty"`
UniquenessToken *string `json:"uniqueness_token,omitempty"`
SubscriptionId *int `json:"subscription_id,omitempty"`
SubscriptionReference *string `json:"subscription_reference,omitempty"`
}