-
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: Introduce simulation payload entity type with optional properties
- Loading branch information
1 parent
a3ecbfa
commit 07b9a94
Showing
22 changed files
with
1,001 additions
and
15 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
52 changes: 52 additions & 0 deletions
52
paddle_billing/Notifications/Entities/Simulations/Address.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,52 @@ | ||
from __future__ import annotations | ||
from dataclasses import dataclass | ||
from datetime import datetime | ||
|
||
from paddle_billing.Undefined import Undefined | ||
from paddle_billing.Notifications.Entities.Shared import CountryCode, CustomData, ImportMeta, Status | ||
from paddle_billing.Notifications.Entities.Simulations.SimulationEntity import SimulationEntity | ||
|
||
|
||
@dataclass | ||
class Address(SimulationEntity): | ||
id: str | Undefined = Undefined() | ||
description: str | None | Undefined = Undefined() | ||
first_line: str | None | Undefined = Undefined() | ||
second_line: str | None | Undefined = Undefined() | ||
city: str | None | Undefined = Undefined() | ||
postal_code: str | None | Undefined = Undefined() | ||
region: str | None | Undefined = Undefined() | ||
country_code: CountryCode | Undefined = Undefined() | ||
status: Status | Undefined = Undefined() | ||
created_at: datetime | Undefined = Undefined() | ||
updated_at: datetime | Undefined = Undefined() | ||
custom_data: CustomData | None | Undefined = Undefined() | ||
import_meta: ImportMeta | None | Undefined = Undefined() | ||
customer_id: str | None | Undefined = Undefined() | ||
|
||
@staticmethod | ||
def from_dict(data: dict) -> Address: | ||
return Address( | ||
id=data.get("id", Undefined()), | ||
customer_id=data.get("customer_id", Undefined()), | ||
description=data.get("description", Undefined()), | ||
first_line=data.get("first_line", Undefined()), | ||
second_line=data.get("second_line", Undefined()), | ||
city=data.get("city", Undefined()), | ||
postal_code=data.get("postal_code", Undefined()), | ||
region=data.get("region", Undefined()), | ||
country_code=CountryCode(data["country_code"]) if data.get("country_code") else Undefined(), | ||
status=Status(data["status"]) if data.get("status") else Undefined(), | ||
created_at=datetime.fromisoformat(data["created_at"]) if data.get("created_at") else Undefined(), | ||
updated_at=datetime.fromisoformat(data["updated_at"]) if data.get("updated_at") else Undefined(), | ||
custom_data=( | ||
CustomData(data["custom_data"]) | ||
if isinstance(data.get("custom_data"), dict) | ||
else data.get("custom_data", Undefined()) | ||
), | ||
import_meta=( | ||
ImportMeta.from_dict(data["import_meta"]) | ||
if isinstance(data.get("import_meta"), dict) | ||
else data.get("import_meta", Undefined()) | ||
), | ||
) |
65 changes: 65 additions & 0 deletions
65
paddle_billing/Notifications/Entities/Simulations/Adjustment.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,65 @@ | ||
from __future__ import annotations | ||
from dataclasses import dataclass | ||
from datetime import datetime | ||
|
||
from paddle_billing.Undefined import Undefined | ||
from paddle_billing.Notifications.Entities.Adjustments import AdjustmentItem, AdjustmentTaxRatesUsed | ||
from paddle_billing.Notifications.Entities.Shared import ( | ||
Action, | ||
AdjustmentStatus, | ||
CurrencyCode, | ||
PayoutTotalsAdjustment, | ||
AdjustmentTotals, | ||
) | ||
from paddle_billing.Notifications.Entities.Simulations.SimulationEntity import SimulationEntity | ||
|
||
|
||
@dataclass | ||
class Adjustment(SimulationEntity): | ||
id: str | Undefined = Undefined() | ||
action: Action | Undefined = Undefined() | ||
transaction_id: str | Undefined = Undefined() | ||
subscription_id: str | None | Undefined = Undefined() | ||
customer_id: str | Undefined = Undefined() | ||
reason: str | Undefined = Undefined() | ||
credit_applied_to_balance: bool | None | Undefined = Undefined() | ||
currency_code: CurrencyCode | Undefined = Undefined() | ||
status: AdjustmentStatus | Undefined = Undefined() | ||
items: list[AdjustmentItem] | Undefined = Undefined() | ||
totals: AdjustmentTotals | Undefined = Undefined() | ||
payout_totals: PayoutTotalsAdjustment | None | Undefined = Undefined() | ||
created_at: datetime | Undefined = Undefined() | ||
updated_at: datetime | None | Undefined = Undefined() | ||
tax_rates_used: list[AdjustmentTaxRatesUsed] | None | Undefined = Undefined() | ||
|
||
@staticmethod | ||
def from_dict(data: dict) -> Adjustment: | ||
return Adjustment( | ||
id=data.get("id", Undefined()), | ||
action=Action(data["action"]) if data.get("action") else Undefined(), | ||
transaction_id=data.get("transaction_id", Undefined()), | ||
subscription_id=data.get("subscription_id", Undefined()), | ||
customer_id=data.get("customer_id", Undefined()), | ||
reason=data.get("reason", Undefined()), | ||
credit_applied_to_balance=data.get("credit_applied_to_balance", Undefined()), | ||
currency_code=CurrencyCode(data["currency_code"]) if data.get("currency_code") else Undefined(), | ||
status=AdjustmentStatus(data["status"]) if data.get("status") else Undefined(), | ||
totals=AdjustmentTotals.from_dict(data["totals"]) if data.get("totals") else Undefined(), | ||
created_at=datetime.fromisoformat(data["created_at"]) if data.get("created_at") else Undefined(), | ||
items=[AdjustmentItem.from_dict(item) for item in data["items"]] if data.get("items") else Undefined(), | ||
payout_totals=( | ||
PayoutTotalsAdjustment.from_dict(data["payout_totals"]) | ||
if data.get("payout_totals") | ||
else data.get("payout_totals", Undefined()) | ||
), | ||
updated_at=( | ||
datetime.fromisoformat(data["updated_at"]) | ||
if data.get("updated_at") | ||
else data.get("updated_at", Undefined()) | ||
), | ||
tax_rates_used=( | ||
[AdjustmentTaxRatesUsed.from_dict(item) for item in data["tax_rates_used"]] | ||
if data.get("tax_rates_used") | ||
else data.get("tax_rates_used", Undefined()) | ||
), | ||
) |
51 changes: 51 additions & 0 deletions
51
paddle_billing/Notifications/Entities/Simulations/Business.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,51 @@ | ||
from __future__ import annotations | ||
from dataclasses import dataclass | ||
from datetime import datetime | ||
|
||
from paddle_billing.Undefined import Undefined | ||
from paddle_billing.Notifications.Entities.Businesses import BusinessesContacts | ||
from paddle_billing.Notifications.Entities.Shared import CustomData, ImportMeta, Status | ||
from paddle_billing.Notifications.Entities.Simulations.SimulationEntity import SimulationEntity | ||
|
||
|
||
@dataclass | ||
class Business(SimulationEntity): | ||
id: str | Undefined = Undefined() | ||
name: str | Undefined = Undefined() | ||
company_number: str | None | Undefined = Undefined() | ||
tax_identifier: str | None | Undefined = Undefined() | ||
status: Status | Undefined = Undefined() | ||
contacts: list[BusinessesContacts] | Undefined = Undefined() | ||
created_at: datetime | Undefined = Undefined() | ||
updated_at: datetime | Undefined = Undefined() | ||
custom_data: CustomData | None | Undefined = Undefined() | ||
import_meta: ImportMeta | None | Undefined = Undefined() | ||
customer_id: str | None | Undefined = Undefined() | ||
|
||
@staticmethod | ||
def from_dict(data: dict) -> Business: | ||
return Business( | ||
id=data.get("id", Undefined()), | ||
customer_id=data.get("customer_id", Undefined()), | ||
name=data.get("name", Undefined()), | ||
company_number=data.get("company_number", Undefined()), | ||
tax_identifier=data.get("tax_identifier", Undefined()), | ||
status=Status(data["status"]) if data.get("status") else Undefined(), | ||
created_at=datetime.fromisoformat(data["created_at"]) if data.get("created_at") else Undefined(), | ||
updated_at=datetime.fromisoformat(data["updated_at"]) if data.get("updated_at") else Undefined(), | ||
contacts=( | ||
[BusinessesContacts.from_dict(contact) for contact in data["contacts"]] | ||
if data.get("contacts") | ||
else Undefined() | ||
), | ||
custom_data=( | ||
CustomData(data["custom_data"]) | ||
if isinstance(data.get("custom_data"), dict) | ||
else data.get("custom_data", Undefined()) | ||
), | ||
import_meta=( | ||
ImportMeta.from_dict(data["import_meta"]) | ||
if isinstance(data.get("import_meta"), dict) | ||
else data.get("import_meta", Undefined()) | ||
), | ||
) |
44 changes: 44 additions & 0 deletions
44
paddle_billing/Notifications/Entities/Simulations/Customer.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,44 @@ | ||
from __future__ import annotations | ||
from dataclasses import dataclass | ||
from datetime import datetime | ||
|
||
from paddle_billing.Undefined import Undefined | ||
from paddle_billing.Notifications.Entities.Shared import CustomData, ImportMeta, Status | ||
from paddle_billing.Notifications.Entities.Simulations.SimulationEntity import SimulationEntity | ||
|
||
|
||
@dataclass | ||
class Customer(SimulationEntity): | ||
id: str | Undefined = Undefined() | ||
name: str | None | Undefined = Undefined() | ||
email: str | Undefined = Undefined() | ||
marketing_consent: bool | Undefined = Undefined() | ||
status: Status | Undefined = Undefined() | ||
locale: str | Undefined = Undefined() | ||
created_at: datetime | Undefined = Undefined() | ||
updated_at: datetime | Undefined = Undefined() | ||
custom_data: CustomData | None | Undefined = Undefined() | ||
import_meta: ImportMeta | None | Undefined = Undefined() | ||
|
||
@staticmethod | ||
def from_dict(data: dict) -> Customer: | ||
return Customer( | ||
id=data.get("id", Undefined()), | ||
name=data.get("name", Undefined()), | ||
email=data.get("email", Undefined()), | ||
marketing_consent=data.get("marketing_consent", Undefined()), | ||
status=Status(data["status"]) if data.get("status") else Undefined(), | ||
locale=data.get("locale", Undefined()), | ||
created_at=datetime.fromisoformat(data["created_at"]) if data.get("created_at") else Undefined(), | ||
updated_at=datetime.fromisoformat(data["updated_at"]) if data.get("updated_at") else Undefined(), | ||
custom_data=( | ||
CustomData(data["custom_data"]) | ||
if isinstance(data.get("custom_data"), dict) | ||
else data.get("custom_data", Undefined()) | ||
), | ||
import_meta=( | ||
ImportMeta.from_dict(data["import_meta"]) | ||
if isinstance(data.get("import_meta"), dict) | ||
else data.get("import_meta", Undefined()) | ||
), | ||
) |
67 changes: 67 additions & 0 deletions
67
paddle_billing/Notifications/Entities/Simulations/Discount.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,67 @@ | ||
from __future__ import annotations | ||
from dataclasses import dataclass | ||
from datetime import datetime | ||
|
||
from paddle_billing.Undefined import Undefined | ||
from paddle_billing.Notifications.Entities.Discounts import DiscountStatus, DiscountType | ||
from paddle_billing.Notifications.Entities.Shared import CurrencyCode, CustomData, ImportMeta | ||
from paddle_billing.Notifications.Entities.Simulations.SimulationEntity import SimulationEntity | ||
|
||
|
||
@dataclass | ||
class Discount(SimulationEntity): | ||
amount: str | Undefined = Undefined() | ||
created_at: datetime | Undefined = Undefined() | ||
description: str | Undefined = Undefined() | ||
enabled_for_checkout: bool | Undefined = Undefined() | ||
id: str | Undefined = Undefined() | ||
recur: bool | Undefined = Undefined() | ||
status: DiscountStatus | Undefined = Undefined() | ||
type: DiscountType | Undefined = Undefined() | ||
updated_at: datetime | Undefined = Undefined() | ||
code: str | None | Undefined = Undefined() | ||
currency_code: CurrencyCode | None | Undefined = Undefined() | ||
custom_data: CustomData | None | Undefined = Undefined() | ||
expires_at: datetime | None | Undefined = Undefined() | ||
import_meta: ImportMeta | None | Undefined = Undefined() | ||
maximum_recurring_intervals: int | None | Undefined = Undefined() | ||
restrict_to: list | None | Undefined = Undefined() | ||
usage_limit: int | None | Undefined = Undefined() | ||
|
||
@staticmethod | ||
def from_dict(data: dict) -> Discount: | ||
return Discount( | ||
amount=data.get("amount", Undefined()), | ||
code=data.get("code", Undefined()), | ||
created_at=datetime.fromisoformat(data["created_at"]) if data.get("created_at") else Undefined(), | ||
description=data.get("description", Undefined()), | ||
enabled_for_checkout=data.get("enabled_for_checkout", Undefined()), | ||
id=data.get("id", Undefined()), | ||
maximum_recurring_intervals=data.get("maximum_recurring_intervals", Undefined()), | ||
usage_limit=data.get("usage_limit", Undefined()), | ||
recur=data.get("recur", Undefined()), | ||
restrict_to=data.get("restrict_to", Undefined()), | ||
status=DiscountStatus(data["status"]) if data.get("status") else Undefined(), | ||
type=DiscountType(data["type"]) if data.get("type") else Undefined(), | ||
updated_at=datetime.fromisoformat(data["updated_at"]) if data.get("updated_at") else Undefined(), | ||
currency_code=( | ||
CurrencyCode(data["currency_code"]) | ||
if data.get("currency_code") | ||
else data.get("currency_code", Undefined()) | ||
), | ||
custom_data=( | ||
CustomData(data["custom_data"]) | ||
if isinstance(data.get("custom_data"), dict) | ||
else data.get("custom_data", Undefined()) | ||
), | ||
expires_at=( | ||
datetime.fromisoformat(data["expires_at"]) | ||
if data.get("expires_at") | ||
else data.get("expires_at", Undefined()) | ||
), | ||
import_meta=( | ||
ImportMeta.from_dict(data["import_meta"]) | ||
if isinstance(data.get("import_meta"), dict) | ||
else data.get("import_meta", Undefined()) | ||
), | ||
) |
33 changes: 33 additions & 0 deletions
33
paddle_billing/Notifications/Entities/Simulations/PaymentMethod.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,33 @@ | ||
from __future__ import annotations | ||
from dataclasses import dataclass | ||
from datetime import datetime | ||
|
||
from paddle_billing.Undefined import Undefined | ||
from paddle_billing.Notifications.Entities.Shared import ( | ||
SavedPaymentMethodOrigin, | ||
SavedPaymentMethodType, | ||
) | ||
from paddle_billing.Notifications.Entities.Simulations.SimulationEntity import SimulationEntity | ||
|
||
|
||
@dataclass | ||
class PaymentMethod(SimulationEntity): | ||
id: str | Undefined = Undefined() | ||
customer_id: str | Undefined = Undefined() | ||
address_id: str | Undefined = Undefined() | ||
type: SavedPaymentMethodType | Undefined = Undefined() | ||
origin: SavedPaymentMethodOrigin | Undefined = Undefined() | ||
saved_at: datetime | Undefined = Undefined() | ||
updated_at: datetime | Undefined = Undefined() | ||
|
||
@staticmethod | ||
def from_dict(data: dict) -> PaymentMethod: | ||
return PaymentMethod( | ||
id=data.get("id", Undefined()), | ||
customer_id=data.get("customer_id", Undefined()), | ||
address_id=data.get("address_id", Undefined()), | ||
type=SavedPaymentMethodType(data["type"]) if data.get("type") else Undefined(), | ||
origin=SavedPaymentMethodOrigin(data["origin"]) if data.get("origin") else Undefined(), | ||
saved_at=datetime.fromisoformat(data["saved_at"]) if data.get("saved_at") else Undefined(), | ||
updated_at=datetime.fromisoformat(data["updated_at"]) if data.get("updated_at") else Undefined(), | ||
) |
40 changes: 40 additions & 0 deletions
40
paddle_billing/Notifications/Entities/Simulations/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,40 @@ | ||
from __future__ import annotations | ||
from dataclasses import dataclass | ||
from datetime import datetime | ||
|
||
from paddle_billing.Undefined import Undefined | ||
from paddle_billing.Notifications.Entities.Shared import ( | ||
SavedPaymentMethodDeletionReason, | ||
SavedPaymentMethodOrigin, | ||
SavedPaymentMethodType, | ||
) | ||
from paddle_billing.Notifications.Entities.Simulations.SimulationEntity import SimulationEntity | ||
|
||
|
||
@dataclass | ||
class PaymentMethodDeleted(SimulationEntity): | ||
id: str | Undefined = Undefined() | ||
customer_id: str | Undefined = Undefined() | ||
address_id: str | Undefined = Undefined() | ||
type: SavedPaymentMethodType | Undefined = Undefined() | ||
origin: SavedPaymentMethodOrigin | Undefined = Undefined() | ||
saved_at: datetime | Undefined = Undefined() | ||
updated_at: datetime | Undefined = Undefined() | ||
deletion_reason: SavedPaymentMethodDeletionReason | Undefined = Undefined() | ||
|
||
@staticmethod | ||
def from_dict(data: dict) -> PaymentMethodDeleted: | ||
return PaymentMethodDeleted( | ||
id=data.get("id", Undefined()), | ||
customer_id=data.get("customer_id", Undefined()), | ||
address_id=data.get("address_id", Undefined()), | ||
type=SavedPaymentMethodType(data["type"]) if data.get("type") else Undefined(), | ||
origin=SavedPaymentMethodOrigin(data["origin"]) if data.get("origin") else Undefined(), | ||
saved_at=datetime.fromisoformat(data["saved_at"]) if data.get("saved_at") else Undefined(), | ||
updated_at=datetime.fromisoformat(data["updated_at"]) if data.get("updated_at") else Undefined(), | ||
deletion_reason=( | ||
SavedPaymentMethodDeletionReason(data["deletion_reason"]) | ||
if data.get("deletion_reason") | ||
else Undefined() | ||
), | ||
) |
Oops, something went wrong.