-
Notifications
You must be signed in to change notification settings - Fork 3
/
subscription_events.go
85 lines (73 loc) · 3.6 KB
/
subscription_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
75
76
77
78
79
80
81
82
83
84
85
package chartmogul
const subscriptionEventsEndpoint = "subscription_events"
type SubscriptionEvent struct {
ID uint64 `json:"id,omitempty"`
DataSourceUUID string `json:"data_source_uuid,omitempty"`
CustomerExternalID string `json:"customer_external_id,omitempty"`
SubscriptionSetExternalID string `json:"subscription_set_external_id,omitempty"`
SubscriptionExternalID string `json:"subscription_external_id,omitempty"`
PlanExternalID string `json:"plan_external_id,omitempty"`
EventDate string `json:"event_date,omitempty"`
EffectiveDate string `json:"effective_date,omitempty"`
EventType string `json:"event_type,omitempty"`
ExternalID string `json:"external_id,omitempty"`
Errors interface{} `json:"errors,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
Quantity int32 `json:"quantity,omitempty"`
Currency string `json:"currency,omitempty"`
AmountInCents int32 `json:"amount_in_cents,omitempty"`
TaxAmountInCents int32 `json:"tax_amount_in_cents,omitempty"`
RetractedEventId string `json:"retracted_event_id,omitempty"`
EventOrder int32 `json:"event_order,omitempty"`
}
type SubscriptionEvents struct {
SubscriptionEvents []*SubscriptionEvent `json:"subscription_events"`
Pagination
}
type DeleteSubscriptionEvent struct {
ID uint64 `json:"id,omitempty"`
DataSourceUUID string `json:"data_source_uuid,omitempty"`
ExternalID string `json:"external_id,omitempty"`
}
type FilterSubscriptionEvents struct {
CustomerExternalID string `json:"customer_external_id,omitempty"`
DataSourceUUID string `json:"data_source_uuid,omitempty"`
EffectiveDate string `json:"effective_date,omitempty"`
EventDate string `json:"event_date,omitempty"`
EventType string `json:"event_type,omitempty"`
ExternalID string `json:"external_id,omitempty"`
PlanExternalID string `json:"plan_external_id,omitempty"`
SubscriptionExternalID string `json:"subscription_external_id,omitempty"`
}
type DeleteSubscriptionEventParams struct {
Params *DeleteSubscriptionEvent `json:"subscription_event"`
}
type SubscriptionEventParams struct {
Params *SubscriptionEvent `json:"subscription_event"`
}
func (api API) ListSubscriptionEvents(filters *FilterSubscriptionEvents, cursor *Cursor) (*SubscriptionEvents, error) {
result := &SubscriptionEvents{}
query := make([]interface{}, 0, 1)
if cursor != nil {
query = append(query, *cursor)
}
if filters != nil {
query = append(query, *filters)
}
return result, api.list(subscriptionEventsEndpoint, result, query...)
}
func (api API) CreateSubscriptionEvent(newSubscriptionEvent *SubscriptionEvent) (*SubscriptionEvent, error) {
result := &SubscriptionEvent{}
return result, api.create(subscriptionEventsEndpoint, SubscriptionEventParams{Params: newSubscriptionEvent}, result)
}
func (api API) UpdateSubscriptionEvent(subscriptionEvent *SubscriptionEvent) (*SubscriptionEvent, error) {
result := &SubscriptionEvent{}
return result, api.update(subscriptionEventsEndpoint, "", SubscriptionEventParams{Params: subscriptionEvent}, result)
}
func (api API) DeleteSubscriptionEvent(deleteParams *DeleteSubscriptionEvent) error {
return api.deleteWithData(
subscriptionEventsEndpoint,
DeleteSubscriptionEventParams{Params: deleteParams},
)
}