-
Notifications
You must be signed in to change notification settings - Fork 9
feat: Add support for checkout domains #153
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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,30 @@ | ||
| from __future__ import annotations | ||
| from dataclasses import dataclass | ||
| from datetime import datetime | ||
| from typing import Any | ||
|
|
||
| from paddle_billing.Entities.Entity import Entity | ||
| from paddle_billing.Entities.CheckoutDomains import CheckoutDomainPaymentMethodVerification, CheckoutDomainStatus | ||
|
|
||
|
|
||
| @dataclass | ||
| class CheckoutDomain(Entity): | ||
| id: str | ||
| domain: str | ||
| status: CheckoutDomainStatus | ||
| payment_method_verification: CheckoutDomainPaymentMethodVerification | ||
| created_at: datetime | ||
| updated_at: datetime | ||
|
|
||
| @staticmethod | ||
| def from_dict(data: dict[str, Any]) -> CheckoutDomain: | ||
| return CheckoutDomain( | ||
| id=data["id"], | ||
| domain=data["domain"], | ||
| status=CheckoutDomainStatus(data["status"]), | ||
| payment_method_verification=CheckoutDomainPaymentMethodVerification.from_dict( | ||
| data["payment_method_verification"] | ||
| ), | ||
| created_at=datetime.fromisoformat(data["created_at"]), | ||
| updated_at=datetime.fromisoformat(data["updated_at"]), | ||
| ) |
18 changes: 18 additions & 0 deletions
18
paddle_billing/Entities/CheckoutDomains/CheckoutDomainApplePayVerification.py
This file contains hidden or 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 typing import Any | ||
|
|
||
| from paddle_billing.Entities.CheckoutDomains.CheckoutDomainPaymentMethodVerificationStatus import ( | ||
| CheckoutDomainPaymentMethodVerificationStatus, | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class CheckoutDomainApplePayVerification: | ||
| status: CheckoutDomainPaymentMethodVerificationStatus | ||
|
|
||
| @staticmethod | ||
| def from_dict(data: dict[str, Any]) -> CheckoutDomainApplePayVerification: | ||
| return CheckoutDomainApplePayVerification( | ||
| status=CheckoutDomainPaymentMethodVerificationStatus(data["status"]), | ||
| ) |
5 changes: 5 additions & 0 deletions
5
paddle_billing/Entities/CheckoutDomains/CheckoutDomainPaymentMethod.py
This file contains hidden or 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,5 @@ | ||
| from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta | ||
|
|
||
|
|
||
| class CheckoutDomainPaymentMethod(PaddleStrEnum, metaclass=PaddleStrEnumMeta): | ||
| ApplePay: "CheckoutDomainPaymentMethod" = "apple_pay" |
18 changes: 18 additions & 0 deletions
18
paddle_billing/Entities/CheckoutDomains/CheckoutDomainPaymentMethodVerification.py
This file contains hidden or 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 typing import Any | ||
|
|
||
| from paddle_billing.Entities.CheckoutDomains.CheckoutDomainApplePayVerification import ( | ||
| CheckoutDomainApplePayVerification, | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class CheckoutDomainPaymentMethodVerification: | ||
| apple_pay: CheckoutDomainApplePayVerification | ||
|
|
||
| @staticmethod | ||
| def from_dict(data: dict[str, Any]) -> CheckoutDomainPaymentMethodVerification: | ||
| return CheckoutDomainPaymentMethodVerification( | ||
| apple_pay=CheckoutDomainApplePayVerification.from_dict(data["apple_pay"]), | ||
| ) |
6 changes: 6 additions & 0 deletions
6
paddle_billing/Entities/CheckoutDomains/CheckoutDomainPaymentMethodVerificationStatus.py
This file contains hidden or 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 CheckoutDomainPaymentMethodVerificationStatus(PaddleStrEnum, metaclass=PaddleStrEnumMeta): | ||
| Verified: "CheckoutDomainPaymentMethodVerificationStatus" = "verified" | ||
| Unverified: "CheckoutDomainPaymentMethodVerificationStatus" = "unverified" |
9 changes: 9 additions & 0 deletions
9
paddle_billing/Entities/CheckoutDomains/CheckoutDomainStatus.py
This file contains hidden or 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 CheckoutDomainStatus(PaddleStrEnum, metaclass=PaddleStrEnumMeta): | ||
| PendingReview: "CheckoutDomainStatus" = "pending_review" | ||
| Approved: "CheckoutDomainStatus" = "approved" | ||
| Rejected: "CheckoutDomainStatus" = "rejected" | ||
| InReview: "CheckoutDomainStatus" = "in_review" | ||
| ActionRequired: "CheckoutDomainStatus" = "action_required" |
This file contains hidden or 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,11 @@ | ||
| from paddle_billing.Entities.CheckoutDomains.CheckoutDomainStatus import CheckoutDomainStatus | ||
| from paddle_billing.Entities.CheckoutDomains.CheckoutDomainPaymentMethod import CheckoutDomainPaymentMethod | ||
| from paddle_billing.Entities.CheckoutDomains.CheckoutDomainPaymentMethodVerificationStatus import ( | ||
| CheckoutDomainPaymentMethodVerificationStatus, | ||
| ) | ||
| from paddle_billing.Entities.CheckoutDomains.CheckoutDomainApplePayVerification import ( | ||
| CheckoutDomainApplePayVerification, | ||
| ) | ||
| from paddle_billing.Entities.CheckoutDomains.CheckoutDomainPaymentMethodVerification import ( | ||
| CheckoutDomainPaymentMethodVerification, | ||
| ) |
16 changes: 16 additions & 0 deletions
16
paddle_billing/Entities/Collections/CheckoutDomainCollection.py
This file contains hidden or 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,16 @@ | ||
| from __future__ import annotations | ||
| from typing import Any | ||
|
|
||
| from paddle_billing.Entities.Collections.Collection import Collection | ||
| from paddle_billing.Entities.Collections.Paginator import Paginator | ||
| from paddle_billing.Entities.CheckoutDomain import CheckoutDomain | ||
|
|
||
|
|
||
| class CheckoutDomainCollection(Collection[CheckoutDomain]): | ||
| @classmethod | ||
| def from_list( | ||
| cls, items_data: list[dict[str, Any]], paginator: Paginator | None = None | ||
| ) -> CheckoutDomainCollection: | ||
| items: list[CheckoutDomain] = [CheckoutDomain.from_dict(item) for item in items_data] | ||
|
|
||
| return CheckoutDomainCollection(items, paginator) |
This file contains hidden or 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: 47 additions & 0 deletions
47
paddle_billing/Resources/CheckoutDomains/CheckoutDomainsClient.py
This file contains hidden or 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,47 @@ | ||
| from paddle_billing.ResponseParser import ResponseParser | ||
|
|
||
| from paddle_billing.Entities.Collections import CheckoutDomainCollection, Paginator | ||
| from paddle_billing.Entities.CheckoutDomain import CheckoutDomain | ||
|
|
||
| from paddle_billing.Resources.CheckoutDomains.Operations import ListCheckoutDomains, VerifyCheckoutDomainPaymentMethod | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| if TYPE_CHECKING: | ||
| from paddle_billing.Client import Client | ||
|
|
||
|
|
||
| class CheckoutDomainsClient: | ||
| def __init__(self, client: "Client"): | ||
| self.client = client | ||
| self.response = None | ||
|
|
||
| def list(self, operation: ListCheckoutDomains | None = None) -> CheckoutDomainCollection: | ||
| if operation is None: | ||
| operation = ListCheckoutDomains() | ||
|
|
||
| self.response = self.client.get_raw("/checkout-domains", operation.get_parameters()) | ||
| parser = ResponseParser(self.response) | ||
|
|
||
| return CheckoutDomainCollection.from_list( | ||
| parser.get_list(), Paginator(self.client, parser.get_pagination(), CheckoutDomainCollection) | ||
| ) | ||
|
|
||
| def get(self, checkout_domain_id: str) -> CheckoutDomain: | ||
| self.response = self.client.get_raw(f"/checkout-domains/{checkout_domain_id}") | ||
| parser = ResponseParser(self.response) | ||
|
|
||
| return CheckoutDomain.from_dict(parser.get_dict()) | ||
|
|
||
| def delete(self, checkout_domain_id: str) -> None: | ||
| self.client.delete_raw(f"/checkout-domains/{checkout_domain_id}") | ||
|
|
||
| return None | ||
|
|
||
| def verify_payment_method( | ||
| self, checkout_domain_id: str, operation: VerifyCheckoutDomainPaymentMethod | ||
| ) -> CheckoutDomain: | ||
| self.response = self.client.post_raw(f"/checkout-domains/{checkout_domain_id}/verify-payment-method", operation) | ||
| parser = ResponseParser(self.response) | ||
|
|
||
| return CheckoutDomain.from_dict(parser.get_dict()) |
41 changes: 41 additions & 0 deletions
41
paddle_billing/Resources/CheckoutDomains/Operations/ListCheckoutDomains.py
This file contains hidden or 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,41 @@ | ||
| from paddle_billing.EnumStringify import enum_stringify | ||
| from paddle_billing.HasParameters import HasParameters | ||
|
|
||
| from paddle_billing.Entities.CheckoutDomains import CheckoutDomainStatus | ||
|
|
||
| from paddle_billing.Exceptions.SdkExceptions.InvalidArgumentException import InvalidArgumentException | ||
|
|
||
| from paddle_billing.Resources.Shared.Operations import Pager | ||
|
|
||
|
|
||
| class ListCheckoutDomains(HasParameters): | ||
| def __init__( | ||
| self, | ||
| pager: Pager | None = None, | ||
| domain: str | None = None, | ||
| statuses: list[CheckoutDomainStatus] | None = None, | ||
| ): | ||
| self.pager = pager | ||
| self.domain = domain | ||
| self.statuses = statuses if statuses is not None else [] | ||
|
|
||
| # Validation | ||
| for field_name, field_value, field_type in [ | ||
| ("statuses", self.statuses, CheckoutDomainStatus), | ||
| ]: | ||
| invalid_items = [item for item in field_value if not isinstance(item, field_type)] | ||
| if invalid_items: | ||
| raise InvalidArgumentException.array_contains_invalid_types( | ||
| field_name, field_type.__name__, invalid_items | ||
| ) | ||
|
|
||
| def get_parameters(self) -> dict[str, str]: | ||
| parameters = {} | ||
| if self.pager: | ||
| parameters.update(self.pager.get_parameters()) | ||
| if self.domain: | ||
| parameters["domain"] = self.domain | ||
| if self.statuses: | ||
| parameters["status"] = ",".join(map(enum_stringify, self.statuses)) | ||
|
|
||
| return parameters |
9 changes: 9 additions & 0 deletions
9
paddle_billing/Resources/CheckoutDomains/Operations/VerifyCheckoutDomainPaymentMethod.py
This file contains hidden or 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 dataclasses import dataclass | ||
|
|
||
| from paddle_billing.Operation import Operation | ||
| from paddle_billing.Entities.CheckoutDomains import CheckoutDomainPaymentMethod | ||
|
|
||
|
|
||
| @dataclass | ||
| class VerifyCheckoutDomainPaymentMethod(Operation): | ||
| payment_method: CheckoutDomainPaymentMethod |
4 changes: 4 additions & 0 deletions
4
paddle_billing/Resources/CheckoutDomains/Operations/__init__.py
This file contains hidden or 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,4 @@ | ||
| from paddle_billing.Resources.CheckoutDomains.Operations.ListCheckoutDomains import ListCheckoutDomains | ||
| from paddle_billing.Resources.CheckoutDomains.Operations.VerifyCheckoutDomainPaymentMethod import ( | ||
| VerifyCheckoutDomainPaymentMethod, | ||
| ) |
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions
3
tests/Functional/Resources/CheckoutDomains/_fixtures/request/verify_payment_method.json
This file contains hidden or 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,3 @@ | ||
| { | ||
| "payment_method": "apple_pay" | ||
| } |
17 changes: 17 additions & 0 deletions
17
tests/Functional/Resources/CheckoutDomains/_fixtures/response/full_entity.json
This file contains hidden or 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 @@ | ||
| { | ||
| "data": { | ||
| "id": "chedom_01hv8h6jj90jjz0d71m6hj4r9z", | ||
| "domain": "example.com", | ||
| "status": "approved", | ||
| "payment_method_verification": { | ||
| "apple_pay": { | ||
| "status": "verified" | ||
| } | ||
| }, | ||
| "created_at": "2024-04-12T06:42:58.785000Z", | ||
| "updated_at": "2024-04-12T06:42:58.785000Z" | ||
| }, | ||
| "meta": { | ||
| "request_id": "cf039cbb-6c2a-485d-b244-501894b797a6" | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
tests/Functional/Resources/CheckoutDomains/_fixtures/response/list_default.json
This file contains hidden or 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,37 @@ | ||
| { | ||
| "data": [ | ||
| { | ||
| "id": "chedom_01hv8h6jj90jjz0d71m6hj4r9z", | ||
| "domain": "example.com", | ||
| "status": "approved", | ||
| "payment_method_verification": { | ||
| "apple_pay": { | ||
| "status": "verified" | ||
| } | ||
| }, | ||
| "created_at": "2024-04-12T06:42:58.785000Z", | ||
| "updated_at": "2024-04-12T06:42:58.785000Z" | ||
| }, | ||
| { | ||
| "id": "chedom_01hv8h6jj90jjz0d71m6hj4r9y", | ||
| "domain": "checkout.example.com", | ||
| "status": "pending_review", | ||
| "payment_method_verification": { | ||
| "apple_pay": { | ||
| "status": "unverified" | ||
| } | ||
| }, | ||
| "created_at": "2024-04-11T06:42:58.785000Z", | ||
| "updated_at": "2024-04-11T06:42:58.785000Z" | ||
| } | ||
| ], | ||
| "meta": { | ||
| "request_id": "e2923a4b-6230-485f-bd7f-64cc4db2454b", | ||
| "pagination": { | ||
| "per_page": 50, | ||
| "next": "https://api.paddle.com/checkout-domains?after=chedom_01hv8h6jj90jjz0d71m6hj4r9y", | ||
| "has_more": false, | ||
| "estimated_total": 2 | ||
| } | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
tests/Functional/Resources/CheckoutDomains/_fixtures/response/list_paginated_page_one.json
This file contains hidden or 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,25 @@ | ||
| { | ||
| "data": [ | ||
| { | ||
| "id": "chedom_01hv8h6jj90jjz0d71m6hj4r9z", | ||
| "domain": "example.com", | ||
| "status": "approved", | ||
| "payment_method_verification": { | ||
| "apple_pay": { | ||
| "status": "verified" | ||
| } | ||
| }, | ||
| "created_at": "2024-04-12T06:42:58.785000Z", | ||
| "updated_at": "2024-04-12T06:42:58.785000Z" | ||
| } | ||
| ], | ||
| "meta": { | ||
| "request_id": "cf039cbb-6c2a-485d-b244-501894b797a6", | ||
| "pagination": { | ||
| "per_page": 1, | ||
| "next": "https://sandbox-api.paddle.com/checkout-domains?after=chedom_01hv8h6jj90jjz0d71m6hj4r9z", | ||
| "has_more": true, | ||
| "estimated_total": 2 | ||
| } | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
tests/Functional/Resources/CheckoutDomains/_fixtures/response/list_paginated_page_two.json
This file contains hidden or 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,25 @@ | ||
| { | ||
| "data": [ | ||
| { | ||
| "id": "chedom_01hv8h6jj90jjz0d71m6hj4r9y", | ||
| "domain": "checkout.example.com", | ||
| "status": "pending_review", | ||
| "payment_method_verification": { | ||
| "apple_pay": { | ||
| "status": "unverified" | ||
| } | ||
| }, | ||
| "created_at": "2024-04-11T06:42:58.785000Z", | ||
| "updated_at": "2024-04-11T06:42:58.785000Z" | ||
| } | ||
| ], | ||
| "meta": { | ||
| "request_id": "cf039cbb-6c2a-485d-b244-501894b797a6", | ||
| "pagination": { | ||
| "per_page": 1, | ||
| "next": "https://sandbox-api.paddle.com/checkout-domains?after=chedom_01hv8h6jj90jjz0d71m6hj4r9y", | ||
| "has_more": false, | ||
| "estimated_total": 2 | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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 is nested in apple pay option so maybe specific for only apple pay but may also possible it could be generic across other future types.
Just noting that with this placement we're leaning on it being generic across future types right?
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.
I believe this should be generic and is aligned with spec