-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for adjustment type and VND currency
- Loading branch information
1 parent
0ef3a03
commit e0999fc
Showing
20 changed files
with
227 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta | ||
|
||
|
||
class AdjustmentActionType(PaddleStrEnum, metaclass=PaddleStrEnumMeta): | ||
Full: "AdjustmentActionType" = "full" | ||
Partial: "AdjustmentActionType" = "partial" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
paddle_billing/Notifications/Entities/Shared/AdjustmentActionType.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta | ||
|
||
|
||
class AdjustmentActionType(PaddleStrEnum, metaclass=PaddleStrEnumMeta): | ||
Full: "AdjustmentActionType" = "full" | ||
Partial: "AdjustmentActionType" = "partial" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 45 additions & 2 deletions
47
paddle_billing/Resources/Adjustments/Operations/CreateAdjustment.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,58 @@ | ||
from dataclasses import dataclass | ||
|
||
from paddle_billing.Undefined import Undefined | ||
|
||
from paddle_billing.Operation import Operation | ||
|
||
from paddle_billing.Entities.Shared import Action | ||
from paddle_billing.Entities.Shared import Action, AdjustmentActionType | ||
|
||
from paddle_billing.Resources.Adjustments.Operations import CreateAdjustmentItem | ||
|
||
from paddle_billing.Exceptions.SdkExceptions.InvalidArgumentException import InvalidArgumentException | ||
|
||
|
||
@dataclass | ||
class CreateAdjustment(Operation): | ||
action: Action | ||
items: list[CreateAdjustmentItem] | ||
items: list[CreateAdjustmentItem] | None | Undefined | ||
reason: str | ||
transaction_id: str | ||
type: AdjustmentActionType | Undefined = Undefined() | ||
|
||
def __post_init__(self): | ||
if self.type != AdjustmentActionType.Full and ( | ||
self.items is None or isinstance(self.items, Undefined) or len(self.items) == 0 | ||
): | ||
raise InvalidArgumentException.array_is_empty("items") | ||
|
||
if self.type == AdjustmentActionType.Full and isinstance(self.items, list): | ||
raise InvalidArgumentException("items are not allowed when the adjustment type is full") | ||
|
||
@staticmethod | ||
def full( | ||
action: Action, | ||
reason: str, | ||
transaction_id: str, | ||
) -> "CreateAdjustment": | ||
return CreateAdjustment( | ||
action=action, | ||
reason=reason, | ||
transaction_id=transaction_id, | ||
items=Undefined(), | ||
type=AdjustmentActionType.Full, | ||
) | ||
|
||
@staticmethod | ||
def partial( | ||
action: Action, | ||
items: list[CreateAdjustmentItem], | ||
reason: str, | ||
transaction_id: str, | ||
) -> "CreateAdjustment": | ||
return CreateAdjustment( | ||
action=action, | ||
reason=reason, | ||
transaction_id=transaction_id, | ||
items=items, | ||
type=AdjustmentActionType.Partial, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
|
||
setup( | ||
version="1.2.2", | ||
version="1.3.0", | ||
author="Paddle and contributors", | ||
author_email="[email protected]", | ||
description="Paddle's Python SDK for Paddle Billing", | ||
|
6 changes: 6 additions & 0 deletions
6
tests/Functional/Resources/Adjustments/_fixtures/request/create_type_full_with_no_items.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"action": "refund", | ||
"type": "full", | ||
"reason": "error", | ||
"transaction_id": "txn_01h8bxpvx398a7zbawb77y0kp5" | ||
} |
7 changes: 7 additions & 0 deletions
7
.../Functional/Resources/Adjustments/_fixtures/request/create_type_full_with_null_items.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"action": "refund", | ||
"type": "full", | ||
"items": null, | ||
"reason": "error", | ||
"transaction_id": "txn_01h8bxpvx398a7zbawb77y0kp5" | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/Functional/Resources/Adjustments/_fixtures/request/create_type_partial_with_items.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"action": "refund", | ||
"type": "partial", | ||
"items": [ | ||
{ | ||
"item_id": "txnitm_01h8bxryv3065dyh6103p3yg28", | ||
"type": "partial", | ||
"amount": "100" | ||
} | ||
], | ||
"reason": "error", | ||
"transaction_id": "txn_01h8bxpvx398a7zbawb77y0kp5" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.