-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: Saved Payment Methods #67
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a3913ec
feat: Add Payment Method entities and endpoints
davidgrayston-paddle 739e905
feat: Move payment methods endpoints into separate client
davidgrayston-paddle 091d97f
feat: Change saved payment method type prefixes
davidgrayston-paddle 0efb7ec
feat: Add test coverage for payment method endpoints
davidgrayston-paddle c76c0fc
feat: Add test coverage for payment method events
davidgrayston-paddle 4b63b27
docs: Update changelog
davidgrayston-paddle e123a27
feat: Remove card and paypal from payment method notification entities
davidgrayston-paddle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 13 additions & 0 deletions
13
paddle_billing/Entities/Collections/PaymentMethodCollection.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,13 @@ | ||
from __future__ import annotations | ||
|
||
from paddle_billing.Entities.Collections.Collection import Collection | ||
from paddle_billing.Entities.Collections.Paginator import Paginator | ||
from paddle_billing.Entities.PaymentMethod import PaymentMethod | ||
|
||
|
||
class PaymentMethodCollection(Collection[PaymentMethod]): | ||
@classmethod | ||
def from_list(cls, items_data: list, paginator: Paginator | None = None) -> PaymentMethodCollection: | ||
items: list[PaymentMethod] = [PaymentMethod.from_dict(item) for item in items_data] | ||
|
||
return PaymentMethodCollection(items, paginator) |
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,18 @@ | ||
from __future__ import annotations | ||
from dataclasses import dataclass | ||
from datetime import datetime | ||
|
||
from paddle_billing.Entities.Entity import Entity | ||
|
||
|
||
@dataclass | ||
class CustomerAuthToken(Entity): | ||
customer_auth_token: str | ||
expires_at: datetime | ||
|
||
@staticmethod | ||
def from_dict(data: dict) -> CustomerAuthToken: | ||
return CustomerAuthToken( | ||
customer_auth_token=data["customer_auth_token"], | ||
expires_at=datetime.fromisoformat(data["expires_at"]), | ||
) |
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,38 @@ | ||
from __future__ import annotations | ||
from dataclasses import dataclass | ||
from datetime import datetime | ||
|
||
from paddle_billing.Entities.Entity import Entity | ||
from paddle_billing.Entities.Shared import ( | ||
Card, | ||
Paypal, | ||
SavedPaymentMethodOrigin, | ||
SavedPaymentMethodType, | ||
) | ||
|
||
|
||
@dataclass | ||
class PaymentMethod(Entity): | ||
id: str | ||
customer_id: str | ||
address_id: str | ||
type: SavedPaymentMethodType | None | ||
card: Card | None | ||
paypal: Paypal | None | ||
origin: SavedPaymentMethodOrigin | ||
saved_at: datetime | ||
updated_at: datetime | ||
|
||
@staticmethod | ||
def from_dict(data: dict) -> PaymentMethod: | ||
return PaymentMethod( | ||
id=data["id"], | ||
customer_id=data["customer_id"], | ||
address_id=data["address_id"], | ||
type=SavedPaymentMethodType(data["type"]), | ||
card=Card.from_dict(data["card"]) if data.get("card") else None, | ||
paypal=Paypal.from_dict(data["paypal"]) if data.get("paypal") else None, | ||
origin=SavedPaymentMethodOrigin(data["origin"]), | ||
saved_at=datetime.fromisoformat(data["saved_at"]), | ||
updated_at=datetime.fromisoformat(data["updated_at"]), | ||
) |
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,15 @@ | ||
from __future__ import annotations | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class Paypal: | ||
email: str | ||
reference: str | ||
|
||
@staticmethod | ||
def from_dict(data: dict) -> Paypal: | ||
return Paypal( | ||
email=data["email"], | ||
reference=data["reference"], | ||
) |
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 SavedPaymentMethodOrigin(PaddleStrEnum, metaclass=PaddleStrEnumMeta): | ||
SavedDuringPurchase: "SavedPaymentMethodOrigin" = "saved_during_purchase" | ||
Subscription: "SavedPaymentMethodOrigin" = "subscription" |
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,9 @@ | ||
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta | ||
|
||
|
||
class SavedPaymentMethodType(PaddleStrEnum, metaclass=PaddleStrEnumMeta): | ||
Alipay: "SavedPaymentMethodType" = "alipay" | ||
ApplePay: "SavedPaymentMethodType" = "apple_pay" | ||
Card: "SavedPaymentMethodType" = "card" | ||
GooglePay: "SavedPaymentMethodType" = "google_pay" | ||
Paypal: "SavedPaymentMethodType" = "paypal" |
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,32 @@ | ||
from __future__ import annotations | ||
from dataclasses import dataclass | ||
from datetime import datetime | ||
|
||
from paddle_billing.Notifications.Entities.Entity import Entity | ||
from paddle_billing.Notifications.Entities.Shared import ( | ||
SavedPaymentMethodOrigin, | ||
SavedPaymentMethodType, | ||
) | ||
|
||
|
||
@dataclass | ||
class PaymentMethod(Entity): | ||
id: str | ||
customer_id: str | ||
address_id: str | ||
type: SavedPaymentMethodType | None | ||
origin: SavedPaymentMethodOrigin | ||
saved_at: datetime | ||
updated_at: datetime | ||
|
||
@staticmethod | ||
def from_dict(data: dict) -> PaymentMethod: | ||
return PaymentMethod( | ||
id=data["id"], | ||
customer_id=data["customer_id"], | ||
address_id=data["address_id"], | ||
type=SavedPaymentMethodType(data["type"]), | ||
origin=SavedPaymentMethodOrigin(data["origin"]), | ||
saved_at=datetime.fromisoformat(data["saved_at"]), | ||
updated_at=datetime.fromisoformat(data["updated_at"]), | ||
) |
35 changes: 35 additions & 0 deletions
35
paddle_billing/Notifications/Entities/PaymentMethodDeleted.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,35 @@ | ||
from __future__ import annotations | ||
from dataclasses import dataclass | ||
from datetime import datetime | ||
|
||
from paddle_billing.Notifications.Entities.Entity import Entity | ||
from paddle_billing.Notifications.Entities.Shared import ( | ||
SavedPaymentMethodDeletionReason, | ||
SavedPaymentMethodOrigin, | ||
SavedPaymentMethodType, | ||
) | ||
|
||
|
||
@dataclass | ||
class PaymentMethodDeleted(Entity): | ||
id: str | ||
customer_id: str | ||
address_id: str | ||
type: SavedPaymentMethodType | None | ||
origin: SavedPaymentMethodOrigin | ||
saved_at: datetime | ||
updated_at: datetime | ||
deletion_reason: SavedPaymentMethodDeletionReason | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
@staticmethod | ||
def from_dict(data: dict) -> PaymentMethodDeleted: | ||
return PaymentMethodDeleted( | ||
id=data["id"], | ||
customer_id=data["customer_id"], | ||
address_id=data["address_id"], | ||
type=SavedPaymentMethodType(data["type"]), | ||
origin=SavedPaymentMethodOrigin(data["origin"]), | ||
saved_at=datetime.fromisoformat(data["saved_at"]), | ||
updated_at=datetime.fromisoformat(data["updated_at"]), | ||
deletion_reason=SavedPaymentMethodDeletionReason(data["deletion_reason"]), | ||
) |
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,15 @@ | ||
from __future__ import annotations | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class Paypal: | ||
email: str | ||
reference: str | ||
|
||
@staticmethod | ||
def from_dict(data: dict) -> Paypal: | ||
return Paypal( | ||
email=data["email"], | ||
reference=data["reference"], | ||
) |
6 changes: 6 additions & 0 deletions
6
paddle_billing/Notifications/Entities/Shared/SavedPaymentMethodDeletionReason.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 SavedPaymentMethodDeletionReason(PaddleStrEnum, metaclass=PaddleStrEnumMeta): | ||
ReplacedByNewerVersion: "SavedPaymentMethodDeletionReason" = "replaced_by_newer_version" | ||
Api: "SavedPaymentMethodDeletionReason" = "api" |
6 changes: 6 additions & 0 deletions
6
paddle_billing/Notifications/Entities/Shared/SavedPaymentMethodOrigin.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 SavedPaymentMethodOrigin(PaddleStrEnum, metaclass=PaddleStrEnumMeta): | ||
SavedDuringPurchase: "SavedPaymentMethodOrigin" = "saved_during_purchase" | ||
Subscription: "SavedPaymentMethodOrigin" = "subscription" |
9 changes: 9 additions & 0 deletions
9
paddle_billing/Notifications/Entities/Shared/SavedPaymentMethodType.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,9 @@ | ||
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta | ||
|
||
|
||
class SavedPaymentMethodType(PaddleStrEnum, metaclass=PaddleStrEnumMeta): | ||
Alipay: "SavedPaymentMethodType" = "alipay" | ||
ApplePay: "SavedPaymentMethodType" = "apple_pay" | ||
Card: "SavedPaymentMethodType" = "card" | ||
GooglePay: "SavedPaymentMethodType" = "google_pay" | ||
Paypal: "SavedPaymentMethodType" = "paypal" |
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
17 changes: 17 additions & 0 deletions
17
paddle_billing/Notifications/Events/PaymentMethodDeleted.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,17 @@ | ||
from datetime import datetime | ||
|
||
from paddle_billing.Entities.Event import Event | ||
from paddle_billing.Entities.Events import EventTypeName | ||
|
||
from paddle_billing.Notifications.Entities.Customer import PaymentMethod | ||
|
||
|
||
class PaymentMethodDeleted(Event): | ||
def __init__( | ||
self, | ||
event_id: str, | ||
event_type: EventTypeName, | ||
occurred_at: datetime, | ||
data: PaymentMethod, | ||
): | ||
super().__init__(event_id, event_type, occurred_at, data) |
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,17 @@ | ||
from datetime import datetime | ||
|
||
from paddle_billing.Entities.Event import Event | ||
from paddle_billing.Entities.Events import EventTypeName | ||
|
||
from paddle_billing.Notifications.Entities.PaymentMethod import PaymentMethod | ||
|
||
|
||
class PaymentMethodSaved(Event): | ||
def __init__( | ||
self, | ||
event_id: str, | ||
event_type: EventTypeName, | ||
occurred_at: datetime, | ||
data: PaymentMethod, | ||
): | ||
super().__init__(event_id, event_type, occurred_at, data) |
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
32 changes: 32 additions & 0 deletions
32
paddle_billing/Resources/PaymentMethods/Operations/ListPaymentMethods.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,32 @@ | ||
from paddle_billing.HasParameters import HasParameters | ||
from paddle_billing.Exceptions.SdkExceptions.InvalidArgumentException import InvalidArgumentException | ||
from paddle_billing.Resources.Shared.Operations import Pager | ||
|
||
|
||
class ListPaymentMethods(HasParameters): | ||
def __init__( | ||
self, | ||
pager: Pager | None = None, | ||
address_ids: list[str] = None, | ||
supports_checkout: bool = None, | ||
): | ||
self.pager = pager | ||
self.address_ids = address_ids | ||
self.supports_checkout = supports_checkout | ||
|
||
# Validation | ||
if address_ids is not None: | ||
invalid_items = [id for id in address_ids if not isinstance(id, str)] | ||
if invalid_items: | ||
raise InvalidArgumentException.array_contains_invalid_types("ids", str.__name__, invalid_items) | ||
|
||
def get_parameters(self) -> dict: | ||
parameters = {} | ||
if self.pager: | ||
parameters.update(self.pager.get_parameters()) | ||
if self.address_ids: | ||
parameters["address_id"] = ",".join(self.address_ids) | ||
if self.supports_checkout is not None: | ||
parameters["supports_checkout"] = "true" if self.supports_checkout else "false" | ||
|
||
return parameters |
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 @@ | ||
from paddle_billing.Resources.PaymentMethods.Operations.ListPaymentMethods import ListPaymentMethods |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This replacement is needed to convert
payment_method
→PaymentMethod