Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
added Entities/PricingPreviews
Browse files Browse the repository at this point in the history
  • Loading branch information
Invincibear committed Jan 23, 2024
1 parent 0ad5ce7 commit 1bf3ae4
Show file tree
Hide file tree
Showing 15 changed files with 312 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='paddle-billing-python-sdk',
version='0.0.1a14',
version='0.0.1a15',
author='Corey Regan',
author_email='[email protected]',
description='A Python wrapper for the Paddle Billing API',
Expand Down
2 changes: 1 addition & 1 deletion src/Entities/Address.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def from_dict(cls, data: dict) -> Address:
postal_code = data.get('postal_code'),
region = data.get('region'),
country_code = CountryCode(data['country_code']),
custom_data = CustomData(data['custom_data']) if 'custom_data' in data else None,
custom_data = CustomData(data['custom_data']) if data.get('custom_data') else None,
status = Status(data['status']),
created_at = datetime.fromisoformat(data['created_at']),
updated_at = datetime.fromisoformat(data['updated_at']),
Expand Down
4 changes: 2 additions & 2 deletions src/Entities/Adjustment.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def from_dict(cls, data: dict) -> Adjustment:
status = StatusAdjustment(data['status']),
items = [AdjustmentItemTotals(item) for item in data['items']],
totals = TotalAdjustments.from_dict(data['totals']),
payoutTotals = PayoutTotalsAdjustment.from_dict(data['payout_totals']) if 'payout_totals' in data else None,
payoutTotals = PayoutTotalsAdjustment.from_dict(data['payout_totals']) if data.get('payout_totals') else None,
createdAt = datetime.fromisoformat(data['created_at']),
updatedAt = datetime.fromisoformat(data['updated_at']) if 'updated_at' in data else None,
updatedAt = datetime.fromisoformat(data['updated_at']) if data.get('updated_at') else None,
)
24 changes: 24 additions & 0 deletions src/Entities/CreditBalance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from __future__ import annotations
from dataclasses import dataclass

from src.Entities.Entity import Entity

from src.Entities.Shared.CurrencyCode import CurrencyCode

from src.Entities.Adjustments.AdjustmentCustomerBalance import AdjustmentCustomerBalance


@dataclass
class CreditBalance(Entity):
customerId: str
currencyCode: CurrencyCode
balance: AdjustmentCustomerBalance


@classmethod
def from_dict(cls, data: dict) -> CreditBalance:
return CreditBalance(
customerId = data['customer_id'],
currencyCode = CurrencyCode(data['currency_code']),
balance = AdjustmentCustomerBalance.from_dict(data['balance']),
)
36 changes: 36 additions & 0 deletions src/Entities/CustomerIncludes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from __future__ import annotations
from dataclasses import dataclass
from datetime import datetime

from src.Entities.Entity import Entity

from src.Entities.Shared.CustomData import CustomData
from src.Entities.Shared.Status import Status


@dataclass
class CustomerIncludes(Entity):
id: str
name: str | None
email: str
marketingConsent: bool
status: Status
customData: CustomData | None
locale: str
createdAt: datetime
updatedAt: datetime


@classmethod
def from_dict(cls, data: dict) -> CustomerIncludes:
return CustomerIncludes(
id = data['id'],
name = data.get('name'),
email = data['email'],
marketingConsent = data['marketing_consent'],
status = Status(data['status']),
customData = CustomData(data['custom_data']) if data.get('custom_data') else None,
locale = data['locale'],
createdAt = datetime.fromisoformat(data['created_at']),
updatedAt = datetime.fromisoformat(data['updated_at']),
)
1 change: 1 addition & 0 deletions src/Entities/DateTime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TODO
24 changes: 24 additions & 0 deletions src/Entities/EventType.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from __future__ import annotations
from dataclasses import dataclass

from src.Entities.Entity import Entity

from src.Entities.Events.EventTypeName import EventTypeName


@dataclass
class EventType(Entity):
name: EventTypeName
description: str
group: str
availableVersions: list


@classmethod
def from_dict(cls, data: dict) -> EventType:
return EventType(
name = EventTypeName(data['name']),
description = data['description'],
group = data['group'],
availableVersions= data['available_versions'],
)
45 changes: 45 additions & 0 deletions src/Entities/Notification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from __future__ import annotations
from dataclasses import dataclass
from datetime import datetime

from src.Entities.Entity import Entity
from src.Entities.Event import Event

from src.Entities.Events.EventTypeName import EventTypeName

from src.Entities.Notifications.NotificationOrigin import NotificationOrigin
from src.Entities.Notifications.NotificationStatus import NotificationStatus


@dataclass
class Notification(Entity):
id: str
type: EventTypeName
status: NotificationStatus
payload: Event
occurredAt: datetime
deliveredAt: datetime | None
replayedAt: datetime | None
origin: NotificationOrigin
lastAttemptAt: datetime | None
retryAt: datetime | None
timesAttempted: int
notificationSettingId: str


@classmethod
def from_dict(cls, data: dict) -> Notification:
return Notification(
id = data['id'],
type = EventTypeName(data['type']),
status = NotificationStatus(data['status']),
payload = Event.from_dict(data['payload']),
occurredAt = datetime.fromisoformat(data['occurred_at']),
deliveredAt = datetime.fromisoformat(data['delivered_at']) if 'delivered_at' in data else None,
replayedAt = datetime.fromisoformat(data['replayed_at']) if 'replayed_at' in data else None,
origin = NotificationOrigin(data['origin']),
lastAttemptAt = datetime.fromisoformat(data['last_attempt_at']) if 'last_attempt_at' in data else None,
retryAt = datetime.fromisoformat(data['retry_at']) if 'retry_at' in data else None,
timesAttempted = data['times_attempted'],
notificationSettingId = data['notification_setting_id']
)
38 changes: 38 additions & 0 deletions src/Entities/PricePreview.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from __future__ import annotations
from dataclasses import dataclass

from src.Entities.Entity import Entity

from src.Entities.Shared.AddressPreview import AddressPreview
from src.Entities.Shared.AvailablePaymentMethods import AvailablePaymentMethods
from src.Entities.Shared.CurrencyCode import CurrencyCode

from src.Entities.PricingPreviews.PricePreviewDetails import PricePreviewDetails


@dataclass
class PricePreview(Entity):
customerId: str | None
addressId: str | None
businessId: str | None
currencyCode: CurrencyCode
discountId: str | None
address: AddressPreview | None
customerIpAddress: str | None
details: PricePreviewDetails
availablePaymentMethods: list[AvailablePaymentMethods]


@classmethod
def from_dict(cls, data: dict) -> PricePreview:
return PricePreview(
customerId = data.get('customer_id'),
addressId = data.get('address_id'),
businessId = data.get('business_id'),
currencyCode = CurrencyCode(data['currency_code']),
discountId = data.get('discount_id'),
address = AddressPreview.from_dict(data['address']) if 'address' in data else None,
customerIpAddress = data.get('customer_ip_address'),
details = PricePreviewDetails.from_dict(data['details']),
availablePaymentMethods = [AvailablePaymentMethods(item) for item in data['available_payment_methods']],
)
16 changes: 16 additions & 0 deletions src/Entities/PricingPreviews/PricePreviewDetails.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from __future__ import annotations
from dataclasses import dataclass

from src.Entities.Entity import Entity

from src.Entities.PricingPreviews.PricePreviewLineItem import PricePreviewLineItem


@dataclass
class PricePreviewDetails(Entity):
lineItems: list[PricePreviewLineItem]


@classmethod
def from_dict(cls, data: dict) -> PricePreviewDetails:
return PricePreviewDetails(lineItems=[PricePreviewLineItem.from_dict(item) for item in data['line_items']])
21 changes: 21 additions & 0 deletions src/Entities/PricingPreviews/PricePreviewDiscounts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from __future__ import annotations
from dataclasses import dataclass

from src.Entities.Entity import Entity
from src.Entities.Discount import Discount


@dataclass
class PricePreviewDiscounts(Entity):
discount: Discount
total: str
formattedTotal: str


@classmethod
def from_dict(cls, data: dict) -> PricePreviewDiscounts:
return PricePreviewDiscounts(
discount = Discount.from_dict(data['discount']),
total = data['total'],
formattedTotal = data['formatted_total'],
)
18 changes: 18 additions & 0 deletions src/Entities/PricingPreviews/PricePreviewItem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import annotations
from dataclasses import dataclass

from src.Entities.Entity import Entity


@dataclass
class PricePreviewItem(Entity):
priceId: str
quantity: int


@classmethod
def from_dict(cls, data: dict) -> PricePreviewItem:
return PricePreviewItem(
priceId = data['price_id'],
quantity = data['quantity'],
)
41 changes: 41 additions & 0 deletions src/Entities/PricingPreviews/PricePreviewLineItem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from __future__ import annotations
from dataclasses import dataclass

from src.Entities.Entity import Entity
from src.Entities.Price import Price
from src.Entities.Product import Product

from src.Entities.Shared.Totals import Totals
from src.Entities.Shared.UnitTotals import UnitTotals

from src.Entities.PricingPreviews.PricePreviewUnitTotalsFormatted import PricePreviewUnitTotalsFormatted
from src.Entities.PricingPreviews.PricePreviewTotalsFormatted import PricePreviewTotalsFormatted
from src.Entities.PricingPreviews.PricePreviewDiscounts import PricePreviewDiscounts


@dataclass
class PricePreviewLineItem(Entity):
price: Price
quantity: int
taxRate: str
unitTotals: UnitTotals
formattedUnitTotals: PricePreviewUnitTotalsFormatted
totals: Totals
formattedTotals: PricePreviewTotalsFormatted
product: Product
discounts: list[PricePreviewDiscounts]


@classmethod
def from_dict(cls, data: dict) -> PricePreviewLineItem:
return PricePreviewLineItem(
price = Price.from_dict(data['price']),
quantity = data['quantity'],
taxRate = data['tax_rate'],
unitTotals = UnitTotals.from_dict(data['unit_totals']),
formattedUnitTotals = PricePreviewUnitTotalsFormatted.from_dict(data['formatted_unit_totals']),
totals = Totals.from_dict(data['totals']),
formattedTotals = PricePreviewTotalsFormatted.from_dict(data['formatted_totals']),
product = Product.from_dict(data['product']),
discounts = [PricePreviewDiscounts.from_dict(item) for item in data['discounts']],
)
22 changes: 22 additions & 0 deletions src/Entities/PricingPreviews/PricePreviewTotalsFormatted.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import annotations
from dataclasses import dataclass

from src.Entities.Entity import Entity


@dataclass
class PricePreviewTotalsFormatted(Entity):
subtotal: str
discount: str
tax: str
total: str


@classmethod
def from_dict(cls, data: dict) -> PricePreviewTotalsFormatted:
return PricePreviewTotalsFormatted(
subtotal = data['subtotal'],
discount = data['discount'],
tax = data['tax'],
total = data['total'],
)
22 changes: 22 additions & 0 deletions src/Entities/PricingPreviews/PricePreviewUnitTotalsFormatted.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import annotations
from dataclasses import dataclass

from src.Entities.Entity import Entity


@dataclass
class PricePreviewUnitTotalsFormatted(Entity):
subtotal: str
discount: str
tax: str
total: str


@classmethod
def from_dict(cls, data: dict) -> PricePreviewUnitTotalsFormatted:
return PricePreviewUnitTotalsFormatted(
subtotal = data['subtotal'],
discount = data['discount'],
tax = data['tax'],
total = data['total'],
)

0 comments on commit 1bf3ae4

Please sign in to comment.