Skip to content

Commit

Permalink
feat: Add import_meta to SubscriptionClient preview responses (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgrayston-paddle committed Sep 23, 2024
1 parent 383300b commit 3a17b56
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ Check our main [developer changelog](https://developer.paddle.com/?utm_source=dx
- Support notification settings pagination, see [related changelog](https://developer.paddle.com/changelog/2024/notification-settings-pagination)
- Support notification settings `active` filter
- `TransactionsClient.get_invoice_pdf` now supports `disposition` parameter, see [related changelog](https://developer.paddle.com/changelog/2024/invoice-pdf-open-in-browser)
- `SubscriptionClient` `preview_update` and `preview_one_time_charge` responses now have `import_meta` property

### Changed

- `paddle_billing.Entities.Shared.CustomData` is no longer a `dataclass`

### Fixed

- `PreviewPrice` operation no longer allows empty `items`

## 0.2.2 - 2024-09-03

### Fixed
Expand Down
4 changes: 3 additions & 1 deletion paddle_billing/Entities/SubscriptionPreview.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import datetime

from paddle_billing.Entities.Entity import Entity
from paddle_billing.Entities.Shared import BillingDetails, CollectionMode, CurrencyCode, CustomData, TimePeriod
from paddle_billing.Entities.Shared import BillingDetails, CollectionMode, CurrencyCode, CustomData, TimePeriod, ImportMeta

from paddle_billing.Entities.Shared.TransactionDetailsPreview import TransactionDetailsPreview

Expand Down Expand Up @@ -46,6 +46,7 @@ class SubscriptionPreview(Entity):
next_transaction: SubscriptionNextTransaction | None
recurring_transaction_details: TransactionDetailsPreview | None
update_summary: SubscriptionPreviewSubscriptionUpdateSummary | None
import_meta: ImportMeta | None


@staticmethod
Expand Down Expand Up @@ -76,4 +77,5 @@ def from_dict(data: dict) -> SubscriptionPreview:
next_transaction = SubscriptionNextTransaction.from_dict(data['next_transaction']) if data.get('next_transaction') else None,
recurring_transaction_details = TransactionDetailsPreview.from_dict(data['recurring_transaction_details']) if data.get('recurring_transaction_details') else None,
update_summary = SubscriptionPreviewSubscriptionUpdateSummary.from_dict(data['update_summary']) if data.get('update_summary') else None,
import_meta = ImportMeta.from_dict(data['import_meta']) if data.get('import_meta') else None,
)
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,16 @@
"import_meta": null,
"created_at": "2023-02-23T13:55:22.538367Z",
"updated_at": "2023-11-09T14:07:16.051528Z"
},
"product": {
"id": "pro_01gsz4t5hdjse780zja8vvr7jg",
"name": "ChatApp Pro",
"description": "Everything in basic, plus access to a suite of powerful tools and features designed to take your team's productivity to the next level.",
"tax_category": "standard",
"image_url": "https://paddle-sandbox.s3.amazonaws.com/user/10889/2nmP8MQSret0aWeDemRw_icon1.png",
"status": "active",
"created_at": "2023-08-16T14:38:08.3Z",
"updated_at": "2023-08-16T14:38:08.3Z"
}
},
{
Expand Down Expand Up @@ -415,6 +425,16 @@
"import_meta": null,
"created_at": "2023-06-01T13:31:12.625056Z",
"updated_at": "2023-08-30T10:34:33.862679Z"
},
"product": {
"id": "pro_01gsz4t5hdjse780zja8vvr7jg",
"name": "ChatApp Pro",
"description": "Everything in basic, plus access to a suite of powerful tools and features designed to take your team's productivity to the next level.",
"tax_category": "standard",
"image_url": "https://paddle-sandbox.s3.amazonaws.com/user/10889/2nmP8MQSret0aWeDemRw_icon1.png",
"status": "active",
"created_at": "2023-08-16T14:38:08.3Z",
"updated_at": "2023-08-16T14:38:08.3Z"
}
}
],
Expand All @@ -439,7 +459,10 @@
"currency_code": "USD"
}
},
"import_meta": null
"import_meta": {
"external_id": "external-id",
"imported_from": "external-platform"
}
},
"meta": {
"request_id": "5a10266d-eb36-486c-b9a0-8ec44543ee6d"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,10 @@
"currency_code": "USD"
}
},
"import_meta": null
"import_meta": {
"external_id": "external-id",
"imported_from": "external-platform"
}
},
"meta": {
"request_id": "e7181c45-0370-46a9-b405-91783219dda2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
Interval,
CatalogType,
TaxCategory,
ImportMeta,
)

from paddle_billing.Entities.Subscriptions import (
Expand Down Expand Up @@ -840,6 +841,27 @@ def test_preview_update_subscription_uses_expected_payload(
"The response JSON doesn't match the expected fixture JSON"


def test_preview_update_subscription_has_import_meta(
self,
test_client,
mock_requests,
):
mock_requests.patch(
f"{test_client.base_url}/subscriptions/sub_01h8bx8fmywym11t6swgzba704/preview",
status_code=200,
text=ReadsFixtures.read_raw_json_fixture('response/preview_update_full_entity'),
)

response = test_client.client.subscriptions.preview_update('sub_01h8bx8fmywym11t6swgzba704', PreviewUpdateSubscription())

assert isinstance(response, SubscriptionPreview)

import_meta = response.import_meta
assert isinstance(import_meta, ImportMeta)
assert import_meta.external_id == 'external-id'
assert import_meta.imported_from == 'external-platform'


@mark.parametrize(
'subscription_id, operation, expected_request_body, expected_response_status, expected_response_body, expected_url',
[
Expand All @@ -851,7 +873,7 @@ def test_preview_update_subscription_uses_expected_payload(
),
ReadsFixtures.read_raw_json_fixture('request/preview_one_time_charge_minimal'),
200,
ReadsFixtures.read_raw_json_fixture('response/preview_update_full_entity'),
ReadsFixtures.read_raw_json_fixture('response/preview_charge_full_entity'),
'/subscriptions/sub_01h8bx8fmywym11t6swgzba704/charge/preview',
), (
'sub_01h8bx8fmywym11t6swgzba704',
Expand All @@ -865,7 +887,7 @@ def test_preview_update_subscription_uses_expected_payload(
),
ReadsFixtures.read_raw_json_fixture('request/preview_one_time_charge_full'),
200,
ReadsFixtures.read_raw_json_fixture('response/preview_update_full_entity'),
ReadsFixtures.read_raw_json_fixture('response/preview_charge_full_entity'),
'/subscriptions/sub_01h8bx8fmywym11t6swgzba704/charge/preview',
),
],
Expand Down Expand Up @@ -903,3 +925,30 @@ def test_preview_create_subscription_one_time_charge_uses_expected_payload(
"The request JSON doesn't match the expected fixture JSON"
assert response_json == loads(str(expected_response_body)), \
"The response JSON doesn't match the expected fixture JSON"


def test_preview_create_subscription_one_time_charge_has_import_meta(
self,
test_client,
mock_requests,
):
mock_requests.post(
f"{test_client.base_url}/subscriptions/sub_01h8bx8fmywym11t6swgzba704/charge/preview",
status_code=200,
text=ReadsFixtures.read_raw_json_fixture('response/preview_charge_full_entity'),
)

response = test_client.client.subscriptions.preview_one_time_charge(
'sub_01h8bx8fmywym11t6swgzba704',
PreviewOneTimeCharge(
SubscriptionEffectiveFrom.NextBillingPeriod,
[SubscriptionItems('pri_01gsz98e27ak2tyhexptwc58yk', 1)]
),
)

assert isinstance(response, SubscriptionPreview)

import_meta = response.import_meta
assert isinstance(import_meta, ImportMeta)
assert import_meta.external_id == 'external-id'
assert import_meta.imported_from == 'external-platform'

0 comments on commit 3a17b56

Please sign in to comment.