Skip to content

Commit 385c359

Browse files
feat: Add support for adjustment type and VND currency (#83)
1 parent 0ef3a03 commit 385c359

File tree

21 files changed

+296
-5
lines changed

21 files changed

+296
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
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.
88

9+
## 1.3.0 - 2024-12-17
10+
11+
### Added
12+
13+
- Support for adjustment type, see [related changelog](https://developer.paddle.com/changelog/2024/refund-credit-full-total?utm_source=dx&utm_medium=paddle-python-sdk)
14+
- Added Vietnamese Dong (`VND`) as a supported currency for payments [related changelog](https://developer.paddle.com/changelog/2024/vietnamese-dong-vnd-supported-currency?utm_source=dx&utm_medium=paddle-python-sdk)
15+
916
## 1.2.2 - 2024-12-17
1017

1118
### Fixed

examples/adjustments.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from logging import getLogger
2+
from os import getenv
3+
from sys import exit # You should use classes/functions that returns instead of exits
4+
5+
from paddle_billing import Client, Environment, Options
6+
7+
from paddle_billing.Entities.Shared import (
8+
Action,
9+
AdjustmentType,
10+
)
11+
12+
from paddle_billing.Exceptions.ApiError import ApiError
13+
14+
from paddle_billing.Resources.Adjustments.Operations import CreateAdjustment, CreateAdjustmentItem
15+
16+
log = getLogger("my_app")
17+
18+
# Verify your Paddle API key was provided by a PADDLE_SECRET_API_KEY environment variable
19+
# It is strongly advised that you do not include secrets in your source code
20+
# Use environment variables, and/or secrets management like Vault to obtain your secrets
21+
api_key: str = getenv("PADDLE_SECRET_API_KEY", None)
22+
if not api_key:
23+
raise ValueError("You must provide the PADDLE_SECRET_API_KEY in your environment variables")
24+
25+
transaction_id: str = getenv("PADDLE_TRANSACTION_ID", None)
26+
transaction_item_id: str = getenv("PADDLE_TRANSACTION_ITEM_ID", None)
27+
full_adjustment_transaction_id: str = getenv("PADDLE_FULL_ADJUSTMENT_TRANSACTION_ID", None)
28+
29+
# Determine the environment, defaulting to sandbox
30+
environment = Environment(getenv("PADDLE_ENVIRONMENT", "sandbox"))
31+
32+
# Initialize the Paddle client
33+
paddle = Client(api_key, options=Options(environment), logger=log)
34+
35+
36+
# ┌───
37+
# │ Create Partial Adjustment │
38+
# └───────────────────────────┘
39+
try:
40+
partial_adjustment = paddle.adjustments.create(
41+
CreateAdjustment.partial(
42+
Action.Refund,
43+
[CreateAdjustmentItem(transaction_item_id, AdjustmentType.Partial, "100")],
44+
"error",
45+
transaction_id,
46+
)
47+
)
48+
except ApiError as error:
49+
print(error)
50+
exit(1)
51+
52+
print(f"Partial Adjustment '{partial_adjustment.id}'")
53+
54+
# ┌───
55+
# │ Create Full Adjustment │
56+
# └────────────────────────┘
57+
try:
58+
full_adjustment = paddle.adjustments.create(
59+
CreateAdjustment.full(
60+
Action.Refund,
61+
"error",
62+
full_adjustment_transaction_id,
63+
)
64+
)
65+
except ApiError as error:
66+
print(error)
67+
exit(1)
68+
69+
print(f"Full Adjustment '{full_adjustment.id}'")

paddle_billing/Client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def build_request_session(self) -> Session:
204204
"Authorization": f"Bearer {self.__api_key}",
205205
"Content-Type": "application/json",
206206
"Paddle-Version": str(self.use_api_version),
207-
"User-Agent": "PaddleSDK/python 1.2.2",
207+
"User-Agent": "PaddleSDK/python 1.3.0",
208208
}
209209
)
210210

paddle_billing/Entities/Adjustment.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from paddle_billing.Entities.Adjustments import AdjustmentItem, AdjustmentTaxRatesUsed
77
from paddle_billing.Entities.Shared import (
88
Action,
9+
AdjustmentActionType,
910
AdjustmentStatus,
1011
CurrencyCode,
1112
PayoutTotalsAdjustment,
@@ -30,6 +31,7 @@ class Adjustment(Entity):
3031
created_at: datetime
3132
updated_at: datetime | None
3233
tax_rates_used: list[AdjustmentTaxRatesUsed]
34+
type: AdjustmentActionType
3335

3436
@staticmethod
3537
def from_dict(data: dict) -> Adjustment:
@@ -51,4 +53,5 @@ def from_dict(data: dict) -> Adjustment:
5153
),
5254
updated_at=datetime.fromisoformat(data["updated_at"]) if data.get("updated_at") else None,
5355
tax_rates_used=[AdjustmentTaxRatesUsed.from_dict(item) for item in data["tax_rates_used"]],
56+
type=AdjustmentStatus(data["type"]),
5457
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta
2+
3+
4+
class AdjustmentActionType(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
5+
Full: "AdjustmentActionType" = "full"
6+
Partial: "AdjustmentActionType" = "partial"

paddle_billing/Entities/Shared/CurrencyCode.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ class CurrencyCode(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
3131
TRY: "CurrencyCode" = "TRY"
3232
TWD: "CurrencyCode" = "TWD"
3333
UAH: "CurrencyCode" = "UAH"
34+
VND: "CurrencyCode" = "VND"
3435
ZAR: "CurrencyCode" = "ZAR"

paddle_billing/Entities/Shared/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from paddle_billing.Entities.Shared.Action import Action
22
from paddle_billing.Entities.Shared.AddressPreview import AddressPreview
3+
from paddle_billing.Entities.Shared.AdjustmentActionType import AdjustmentActionType
34
from paddle_billing.Entities.Shared.AdjustmentItemTotals import AdjustmentItemTotals
45
from paddle_billing.Entities.Shared.AdjustmentStatus import AdjustmentStatus
56
from paddle_billing.Entities.Shared.AdjustmentTotals import AdjustmentTotals

paddle_billing/Notifications/Entities/Adjustment.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from paddle_billing.Notifications.Entities.Entity import Entity
77
from paddle_billing.Notifications.Entities.Shared import (
88
Action,
9+
AdjustmentActionType,
910
AdjustmentStatus,
1011
CurrencyCode,
1112
PayoutTotalsAdjustment,
@@ -30,6 +31,7 @@ class Adjustment(Entity):
3031
created_at: datetime
3132
updated_at: datetime | None
3233
tax_rates_used: list[AdjustmentTaxRatesUsed] | None
34+
type: AdjustmentActionType | None
3335

3436
@staticmethod
3537
def from_dict(data: dict) -> Adjustment:
@@ -55,4 +57,5 @@ def from_dict(data: dict) -> Adjustment:
5557
if data.get("tax_rates_used")
5658
else None
5759
),
60+
type=AdjustmentActionType(data["type"]) if data.get("type") else None,
5861
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta
2+
3+
4+
class AdjustmentActionType(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
5+
Full: "AdjustmentActionType" = "full"
6+
Partial: "AdjustmentActionType" = "partial"

paddle_billing/Notifications/Entities/Shared/CurrencyCode.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ class CurrencyCode(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
3131
TRY: "CurrencyCode" = "TRY"
3232
TWD: "CurrencyCode" = "TWD"
3333
UAH: "CurrencyCode" = "UAH"
34+
VND: "CurrencyCode" = "VND"
3435
ZAR: "CurrencyCode" = "ZAR"

0 commit comments

Comments
 (0)