Skip to content

Commit

Permalink
feat: Add on_resume support to subscription resume and pause operatio…
Browse files Browse the repository at this point in the history
…ns (#86)
  • Loading branch information
davidgrayston-paddle authored Dec 19, 2024
1 parent 5cbf524 commit c2ba603
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ 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.4.0 - 2024-12-19

### Added

- Added `on_resume` support to subscription resume and pause operations

## 1.3.1 - 2024-12-17

### Fixed
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.3.1",
"User-Agent": "PaddleSDK/python 1.4.0",
}
)

Expand Down
6 changes: 6 additions & 0 deletions paddle_billing/Entities/Subscriptions/SubscriptionOnResume.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta


class SubscriptionOnResume(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
ContinueExistingBillingPeriod: "SubscriptionOnResume" = "continue_existing_billing_period"
StartNewBillingPeriod: "SubscriptionOnResume" = "start_new_billing_period"
1 change: 1 addition & 0 deletions paddle_billing/Entities/Subscriptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from paddle_billing.Entities.Subscriptions.SubscriptionManagementUrls import SubscriptionManagementUrls
from paddle_billing.Entities.Subscriptions.SubscriptionNextTransaction import SubscriptionNextTransaction
from paddle_billing.Entities.Subscriptions.SubscriptionOnPaymentFailure import SubscriptionOnPaymentFailure
from paddle_billing.Entities.Subscriptions.SubscriptionOnResume import SubscriptionOnResume
from paddle_billing.Entities.Subscriptions.SubscriptionPreviewSubscriptionUpdateSummary import (
SubscriptionPreviewSubscriptionUpdateSummary,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

from paddle_billing.Operation import Operation
from paddle_billing.Entities.DateTime import DateTime
from paddle_billing.Entities.Subscriptions import SubscriptionEffectiveFrom
from paddle_billing.Entities.Subscriptions import SubscriptionEffectiveFrom, SubscriptionOnResume
from paddle_billing.Undefined import Undefined


@dataclass
class PauseSubscription(Operation):
effective_from: SubscriptionEffectiveFrom | None = None
resume_at: DateTime | None = None
on_resume: SubscriptionOnResume | Undefined = Undefined()
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

from paddle_billing.Operation import Operation
from paddle_billing.Entities.DateTime import DateTime
from paddle_billing.Entities.Subscriptions import SubscriptionResumeEffectiveFrom
from paddle_billing.Entities.Subscriptions import SubscriptionResumeEffectiveFrom, SubscriptionOnResume
from paddle_billing.Undefined import Undefined


@dataclass
class ResumeSubscription(Operation):
effective_from: SubscriptionResumeEffectiveFrom | DateTime | None = None
on_resume: SubscriptionOnResume | Undefined = Undefined()
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.3.1",
version="1.4.0",
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,5 @@
{
"effective_from": "next_billing_period",
"resume_at": "2023-10-09T16:30:00.000000Z",
"on_resume": "continue_existing_billing_period"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"effective_from": "next_billing_period",
"resume_at": "2023-10-09T16:30:00.000000Z",
"on_resume": "start_new_billing_period"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"effective_from": "immediately",
"on_resume": "continue_existing_billing_period"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"effective_from": "immediately",
"on_resume": "start_new_billing_period"
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from paddle_billing.Entities.Subscriptions import (
SubscriptionEffectiveFrom,
SubscriptionOnPaymentFailure,
SubscriptionOnResume,
SubscriptionProrationBillingMode,
SubscriptionResumeEffectiveFrom,
SubscriptionScheduledChangeAction,
Expand Down Expand Up @@ -516,11 +517,37 @@ def test_get_subscription_returns_transaction_line_item_proration(
ReadsFixtures.read_raw_json_fixture("response/full_entity"),
"/subscriptions/sub_01h8bx8fmywym11t6swgzba704/pause",
),
(
"sub_01h8bx8fmywym11t6swgzba704",
PauseSubscription(
SubscriptionEffectiveFrom.NextBillingPeriod,
DateTime("2023-10-09T16:30:00Z"),
SubscriptionOnResume.ContinueExistingBillingPeriod,
),
ReadsFixtures.read_raw_json_fixture("request/pause_resume_existing_billing_period"),
200,
ReadsFixtures.read_raw_json_fixture("response/full_entity"),
"/subscriptions/sub_01h8bx8fmywym11t6swgzba704/pause",
),
(
"sub_01h8bx8fmywym11t6swgzba704",
PauseSubscription(
SubscriptionEffectiveFrom.NextBillingPeriod,
DateTime("2023-10-09T16:30:00Z"),
SubscriptionOnResume.StartNewBillingPeriod,
),
ReadsFixtures.read_raw_json_fixture("request/pause_resume_new_billing_period"),
200,
ReadsFixtures.read_raw_json_fixture("response/full_entity"),
"/subscriptions/sub_01h8bx8fmywym11t6swgzba704/pause",
),
],
ids=[
"Pause subscription",
"Pause subscription as of next billing period",
"Pause subscription as of next billing period and resume at date",
"Pause subscription resume in existing billing period",
"Pause subscription resume in new billing period",
],
)
def test_pause_subscription_uses_expected_payload(
Expand Down Expand Up @@ -583,11 +610,33 @@ def test_pause_subscription_uses_expected_payload(
ReadsFixtures.read_raw_json_fixture("response/full_entity"),
"/subscriptions/sub_01h8bx8fmywym11t6swgzba704/resume",
),
(
"sub_01h8bx8fmywym11t6swgzba704",
ResumeSubscription(
SubscriptionResumeEffectiveFrom.Immediately, SubscriptionOnResume.ContinueExistingBillingPeriod
),
ReadsFixtures.read_raw_json_fixture("request/resume_existing_billing_period"),
200,
ReadsFixtures.read_raw_json_fixture("response/full_entity"),
"/subscriptions/sub_01h8bx8fmywym11t6swgzba704/resume",
),
(
"sub_01h8bx8fmywym11t6swgzba704",
ResumeSubscription(
SubscriptionResumeEffectiveFrom.Immediately, SubscriptionOnResume.StartNewBillingPeriod
),
ReadsFixtures.read_raw_json_fixture("request/resume_new_billing_period"),
200,
ReadsFixtures.read_raw_json_fixture("response/full_entity"),
"/subscriptions/sub_01h8bx8fmywym11t6swgzba704/resume",
),
],
ids=[
"Resume subscription",
"Resume subscription with a billing period",
"Resume subscription with a new date",
"Resume subscription in existing billing period",
"Resume subscription in new billing period",
],
)
def test_resume_subscription_uses_expected_payload(
Expand Down

0 comments on commit c2ba603

Please sign in to comment.