Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Customer portal sessions subscription IDs / Replay Endpoint #81

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ 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-python-sdk) for information about changes to the Paddle Billing platform, the Paddle API, and other developer tools.

## 1.2.1 - 2024-12-04

### Fixed

- Subscription IDs can be omitted when creating customer portal sessions
- Customer portal session customer ID will always be returned as string
- `Client.notifications.replay` now calls correct endpoint

## 1.2.0 - 2024-12-03

### Added
Expand Down
2 changes: 1 addition & 1 deletion paddle_billing/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def build_request_session(self) -> Session:
"Authorization": f"Bearer {self.__api_key}",
"Content-Type": "application/json",
"Paddle-Version": str(self.use_api_version),
"User-Agent": "PaddleSDK/python 1.2.0",
"User-Agent": "PaddleSDK/python 1.2.1",
}
)

Expand Down
4 changes: 2 additions & 2 deletions paddle_billing/Entities/CustomerPortalSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
@dataclass
class CustomerPortalSession(Entity):
id: str
customer_id: str | None
customer_id: str
urls: CustomerPortalSessionUrls
created_at: datetime

@staticmethod
def from_dict(data: dict) -> CustomerPortalSession:
return CustomerPortalSession(
id=data["id"],
customer_id=data.get("customer_id"),
customer_id=data["customer_id"],
urls=CustomerPortalSessionUrls.from_dict(data["urls"]),
created_at=datetime.fromisoformat(data["created_at"]),
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from dataclasses import dataclass

from paddle_billing.Operation import Operation
from paddle_billing.Undefined import Undefined


@dataclass
class CreateCustomerPortalSession(Operation):
subscription_ids: list[str] = (None,)
subscription_ids: list[str] | Undefined = Undefined()
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get(self, notification_id: str) -> Notification:
return Notification.from_dict(parser.get_data())

def replay(self, notification_id: str) -> str:
self.response = self.client.post_raw(f"/notifications/{notification_id}")
self.response = self.client.post_raw(f"/notifications/{notification_id}/replay")
parser = ResponseParser(self.response)
data = parser.get_data()

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


setup(
version="1.2.0",
version="1.2.1",
author="Paddle and contributors",
author_email="[email protected]",
description="Paddle's Python SDK for Paddle Billing",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"subscription_ids": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"data": {
"id": "cpls_01h4ge9r64c22exjsx0fy8b48b",
"customer_id": "ctm_01gysfvfy7vqhpzkq8rjmrq7an",
"urls": {
"general": {
"overview": "https://customer-portal.paddle.com/cpl_01j7zbyqs3vah3aafp4jf62qaw?action=overview&token=pga_eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJjdG1fMDFncm5uNHp0YTVhMW1mMDJqanplN3kyeXMiLCJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE3Mjc2NzkyMzh9._oO12IejzdKmyKTwb7BLjmiILkx4_cSyGjXraOBUI_g"
},
"subscriptions": []
},
"created_at": "2024-10-25T06:53:58Z"
},
"meta": {
"request_id": "fa176777-4bca-49ec-aa1e-f53885333cb7"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,26 @@ class TestAddressesClient:
ReadsFixtures.read_raw_json_fixture("response/full_entity_multiple"),
"/customers/ctm_01gysfvfy7vqhpzkq8rjmrq7an/portal-sessions",
),
(
"ctm_01gysfvfy7vqhpzkq8rjmrq7an",
CreateCustomerPortalSession([]),
ReadsFixtures.read_raw_json_fixture("request/create_empty"),
ReadsFixtures.read_raw_json_fixture("response/full_entity_empty"),
"/customers/ctm_01gysfvfy7vqhpzkq8rjmrq7an/portal-sessions",
),
(
"ctm_01gysfvfy7vqhpzkq8rjmrq7an",
CreateCustomerPortalSession(),
"{}",
ReadsFixtures.read_raw_json_fixture("response/full_entity_empty"),
"/customers/ctm_01gysfvfy7vqhpzkq8rjmrq7an/portal-sessions",
),
],
ids=[
"Create portal session with single subscription ID",
"Create portal session with multiple subscription IDs",
"Create portal session with empty subscription IDs",
"Create portal session with omitted subscription IDs",
],
)
def test_create_uses_expected_payload(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ def test_get_notification_returns_expected_response(
200,
ReadsFixtures.read_raw_json_fixture("response/replay"),
"ntf_01h46h1s2zabpkdks7yt4vkgkc",
"/notifications/nft_01h8441jn5pcwrfhwh78jqt8hk",
"/notifications/nft_01h8441jn5pcwrfhwh78jqt8hk/replay",
)
],
ids=["Replay a notification by its id"],
)
def test_replacy_notification_returns_expected_response(
def test_replay_notification_returns_expected_response(
self,
test_client,
mock_requests,
Expand Down
Loading