Skip to content

Commit

Permalink
feat!: Add improved support for notifications and events (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeymike authored May 29, 2024
1 parent 9acc4ae commit 000d871
Show file tree
Hide file tree
Showing 21 changed files with 3,334 additions and 99 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

Check our main [developer changelog](https://developer.paddle.com/?utm_source=dx&utm_medium=paddle-go-sdk) for information about changes to the Paddle Billing platform, the Paddle API, and other developer tools.

## 0.3.0 - 2024-05-27

### Breaking changes

- `Event` and `NotificationsEvent` are now an interfaces.
- `NotificationsEvent` has moved package to `paddlenotification`.

### Added

- New `paddlenotification` package.
- Support for `/events` and `/notifications` endpoints.


## 0.1.0 - 2024-05-07

### Added
Expand Down
156 changes: 78 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,84 +168,84 @@ While in early access, not all operations in the Paddle API are available in our

This table shows which operations are available as of the latest release.

| Paddle API operation | Support |
|----------------------------------------------|:-----------:|
| **Products** | **Full** |
| List products | |
| Create a product | |
| Get a product | |
| Update a product | |
| **Prices** | **Full** |
| List prices | |
| Create a price | |
| Get a price | |
| Update a price | |
| **Discounts** | **Full** |
| List discounts | |
| Create a discount | |
| Get a discount | |
| Update a discount | |
| **Customers** | **Full** |
| List customers | |
| Create a customer | |
| Get a customer | |
| Update a customer | |
| List credit balances for a customer | |
| **Addresses** | **Full** |
| List addresses for a customer | |
| Create an addresses for a customer | |
| Get an address for a customer | |
| Update an address for a customer | |
| **Businesses** | |
| List businesses for a customer | |
| Create a business for a customer | |
| Get a business for a customer | |
| Update a business for a customer | |
| **Transactions** | **Full** |
| List transactions | |
| Create a transaction | |
| Get a transaction | |
| Update a transaction | |
| Preview a transaction | |
| Get a PDF invoice for a transaction | |
| **Subscriptions** | **Full** |
| List subscriptions | |
| Get a subscription | |
| Preview an update to a subscription | |
| Update a subscription | |
| Get a transaction to update payment method | |
| Preview a one-time charge for a subscription | |
| Create a one-time charge for a subscription | |
| Activate a trialing subscription | |
| Pause a subscription | |
| Resume a paused subscription | |
| Cancel a subscription | |
| **Adjustments** | **Full** |
| List adjustments | |
| Create an adjustment | |
| **Pricing preview** | **Full** |
| Preview prices | |
| **Reports** | **Full** |
| List reports | |
| Create a report | |
| Get a report | |
| Get a CSV file for a report | |
| **Notification settings** | **Full** |
| List notification settings | |
| Create a notification setting | |
| Get a notification setting | |
| Update a notification setting | |
| Delete a notification setting | |
| **Event types** | **Full** |
| List event types | |
| **Events** | **-** |
| List events | - |
| **Notifications** | **Partial** |
| List notifications | - |
| Get a notification | - |
| Replay a notification | |
| **Notification logs** | **Full** |
| List logs for a notification | |
| Paddle API operation | Support |
|----------------------------------------------|:--------:|
| **Products** | **Full** |
| List products | |
| Create a product | |
| Get a product | |
| Update a product | |
| **Prices** | **Full** |
| List prices | |
| Create a price | |
| Get a price | |
| Update a price | |
| **Discounts** | **Full** |
| List discounts | |
| Create a discount | |
| Get a discount | |
| Update a discount | |
| **Customers** | **Full** |
| List customers | |
| Create a customer | |
| Get a customer | |
| Update a customer | |
| List credit balances for a customer | |
| **Addresses** | **Full** |
| List addresses for a customer | |
| Create an addresses for a customer | |
| Get an address for a customer | |
| Update an address for a customer | |
| **Businesses** | |
| List businesses for a customer | |
| Create a business for a customer | |
| Get a business for a customer | |
| Update a business for a customer | |
| **Transactions** | **Full** |
| List transactions | |
| Create a transaction | |
| Get a transaction | |
| Update a transaction | |
| Preview a transaction | |
| Get a PDF invoice for a transaction | |
| **Subscriptions** | **Full** |
| List subscriptions | |
| Get a subscription | |
| Preview an update to a subscription | |
| Update a subscription | |
| Get a transaction to update payment method | |
| Preview a one-time charge for a subscription | |
| Create a one-time charge for a subscription | |
| Activate a trialing subscription | |
| Pause a subscription | |
| Resume a paused subscription | |
| Cancel a subscription | |
| **Adjustments** | **Full** |
| List adjustments | |
| Create an adjustment | |
| **Pricing preview** | **Full** |
| Preview prices | |
| **Reports** | **Full** |
| List reports | |
| Create a report | |
| Get a report | |
| Get a CSV file for a report | |
| **Notification settings** | **Full** |
| List notification settings | |
| Create a notification setting | |
| Get a notification setting | |
| Update a notification setting | |
| Delete a notification setting | |
| **Event types** | **Full** |
| List event types | |
| **Events** | **Full** |
| List events | |
| **Notifications** | **Full** |
| List notifications | |
| Get a notification | |
| Replay a notification | |
| **Notification logs** | **Full** |
| List logs for a notification | |

## Learn more

Expand Down
21 changes: 18 additions & 3 deletions collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ func (c *Collection[T]) UnmarshalJSON(b []byte) error {
return nil
}

// Unmarshal into an intermediary struct that matches the API response.
var res response.Response[[]T]
// Unmarshal into an intermediary struct with delayed decoding
var res response.Response[[]json.RawMessage]

if err := json.Unmarshal(b, &res); err != nil {
return err
Expand All @@ -175,7 +175,22 @@ func (c *Collection[T]) UnmarshalJSON(b []byte) error {
c.pos = 0

for _, item := range res.Data {
c.results = append(c.results, &Res[T]{value: item})
switch any(c).(type) {
case *Collection[Event]:
e, err := unmarshalEvent(item)
if err != nil {
return err
}

c.results = append(c.results, &Res[T]{value: any(e).(T)}) //nolint:forcetypeassert // we know the type is correct.
default:
var t T
if err := json.Unmarshal(item, &t); err != nil {
return err
}

c.results = append(c.results, &Res[T]{value: t}) //nolint:forcetypeassert // we know the type is correct.
}
}

nextURL, err := url.Parse(res.Meta.Pagination.Next)
Expand Down
Loading

0 comments on commit 000d871

Please sign in to comment.