-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Subscription Events (#51)
* Add SubscriptionEvents definitions Add MetaCursor struct * Add deleteWithData function to delete without providing UUID * Add subscription_events * Update README * Change type from uint32 to uint64 to handle BigInt on the server * Update subscription events tests * Make sure that the setup function returns error on failure
- Loading branch information
Showing
5 changed files
with
410 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,6 +174,14 @@ api.AddTagsToCustomersWithEmail("[email protected]", []string{}) | |
api.AddCustomAttributesToCustomer("customerUUID", []*cm.CustomAttribute{}) | ||
``` | ||
|
||
#### [Subscription Events](https://dev.chartmogul.com/reference/subscription-events) | ||
```go | ||
api.ListSubscriptionEvents(filters *FilterSubscriptionEvents, cursor *MetaCursor) | ||
api.CreateSubscriptionEvent(newSubscriptionEvent *SubscriptionEvent) | ||
api.UpdateSubscriptionEvent(subscriptionEvent *SubscriptionEvent) | ||
api.DeleteSubscriptionEvent(deleteParams *DeleteSubscriptionEvent) | ||
``` | ||
|
||
|
||
### [Metrics API](https://dev.chartmogul.com/docs/introduction-metrics-api) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
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"` | ||
} | ||
|
||
type SubscriptionEvents struct { | ||
SubscriptionEvents []*SubscriptionEvent `json:"subscription_events"` | ||
Meta MetaCursor `json:"meta"` | ||
} | ||
|
||
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 *MetaCursor) (*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}, | ||
) | ||
} |
Oops, something went wrong.