diff --git a/CHANGELOG.md b/CHANGELOG.md index 0933270a..0a3b5a03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), Check our main [developer changelog](https://developer.paddle.com/?utm_source=dx&utm_medium=paddle-python-sdk) for information about changes to the Paddle Billing platform, the Paddle API, and other developer tools. +## [Unreleased] + +### Changed + +- `paddle_billing.Resources.Discounts.Operations.CreateDiscount` `expires_at` is now `paddle_billing.Entities.DateTime` +- `paddle_billing.Resources.Discounts.Operations.UpdateDiscount` `expires_at` is now `paddle_billing.Entities.DateTime` + +### Removed +- `get_parameters()` method on request operation classes is now removed or replaced by `to_json()` (see UPGRADING.md for further details) + ## 0.3.2 - 2024-11-07 ### Fixed diff --git a/UPGRADING.md b/UPGRADING.md index 99d003ed..5633a067 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -2,6 +2,66 @@ All breaking changes prior to v1 will be documented in this file to assist with upgrading. +## Unreleased + +### 1. Unused `get_parameters()` method was removed from request operation classes + +`get_parameters()` methods returned the data used for operation request payloads, but is now removed or replaced by `to_json()`. This method was intended to be internal, so should not require any changes. + +`get_parameters()` method was removed from the following classes: + - `paddle_billing.Entities.Reports.ReportFilter` + - `paddle_billing.Entities.Shared.CustomData` + - `paddle_billing.Entities.Subscriptions.SubscriptionItems` + - `paddle_billing.Entities.Subscriptions.SubscriptionItemsWithPrice` + - `paddle_billing.Notifications.Entities.Reports.ReportFilter` + - `paddle_billing.Notifications.Entities.Shared.CustomData` + - `paddle_billing.Resources.Addresses.Operations.CreateAddress` + - `paddle_billing.Resources.Addresses.Operations.UpdateAddress` + - `paddle_billing.Resources.Adjustments.Operations.CreateAdjustment` + - `paddle_billing.Resources.Businesses.Operations.CreateBusiness` + - `paddle_billing.Resources.Businesses.Operations.UpdateBusiness` + - `paddle_billing.Resources.Customers.Operations.CreateCustomer` + - `paddle_billing.Resources.Customers.Operations.UpdateCustomer` + - `paddle_billing.Resources.Discounts.Operations.CreateDiscount` + - `paddle_billing.Resources.Discounts.Operations.UpdateDiscount` + - `paddle_billing.Resources.NotificationSettings.Operations.CreateNotificationSetting` + - `paddle_billing.Resources.NotificationSettings.Operations.UpdateNotificationSetting` + - `paddle_billing.Resources.Prices.Operations.CreatePrice` + - `paddle_billing.Resources.Prices.Operations.UpdatePrice` + - `paddle_billing.Resources.PricingPreviews.Operations.PreviewPrice` + - `paddle_billing.Resources.Products.Operations.CreateProduct` + - `paddle_billing.Resources.Products.Operations.UpdateProduct` + - `paddle_billing.Resources.Reports.Operations.CreateReport` subclasses: + - `paddle_billing.Resources.Reports.Operations.CreateAdjustmentsReport` + - `paddle_billing.Resources.Reports.Operations.CreateDiscountsReport` + - `paddle_billing.Resources.Reports.Operations.CreateProductsAndPricesReport` + - `paddle_billing.Resources.Reports.Operations.CreateTransactionsReport` + - `paddle_billing.Resources.Reports.Operations.Filters.Filter` subclasses: + - `paddle_billing.Resources.Reports.Operations.Filters.AdjustmentActionFilter` + - `paddle_billing.Resources.Reports.Operations.Filters.AdjustmentStatusFilter` + - `paddle_billing.Resources.Reports.Operations.Filters.CollectionModeFilter` + - `paddle_billing.Resources.Reports.Operations.Filters.CurrencyCodeFilter` + - `paddle_billing.Resources.Reports.Operations.Filters.DiscountStatusFilter` + - `paddle_billing.Resources.Reports.Operations.Filters.DiscountTypeFilter` + - `paddle_billing.Resources.Reports.Operations.Filters.Filter` + - `paddle_billing.Resources.Reports.Operations.Filters.PriceStatusFilter` + - `paddle_billing.Resources.Reports.Operations.Filters.PriceTypeFilter` + - `paddle_billing.Resources.Reports.Operations.Filters.PriceUpdatedAtFilter` + - `paddle_billing.Resources.Reports.Operations.Filters.ProductStatusFilter` + - `paddle_billing.Resources.Reports.Operations.Filters.ProductTypeFilter` + - `paddle_billing.Resources.Reports.Operations.Filters.ProductUpdatedAtFilter` + - `paddle_billing.Resources.Reports.Operations.Filters.TransactionOriginFilter` + - `paddle_billing.Resources.Reports.Operations.Filters.TransactionStatusFilter` + - `paddle_billing.Resources.Reports.Operations.Filters.UpdatedAtFilter` + - `paddle_billing.Resources.Subscriptions.Operations.CancelSubscription` + - `paddle_billing.Resources.Subscriptions.Operations.CreateOneTimeCharge` + - `paddle_billing.Resources.Subscriptions.Operations.PauseSubscription` + - `paddle_billing.Resources.Subscriptions.Operations.PreviewOneTimeCharge` + - `paddle_billing.Resources.Subscriptions.Operations.ResumeSubscription` + - `paddle_billing.Resources.Transactions.Operations.PreviewTransactionByAddress` + - `paddle_billing.Resources.Transactions.Operations.PreviewTransactionByCustomer` + - `paddle_billing.Resources.Transactions.Operations.PreviewTransactionByIP` + ## v0.3.0 ### 1. `AvailablePaymentMethods` has been replaced by `PaymentMethodType`. diff --git a/paddle_billing/Client.py b/paddle_billing/Client.py index 87096240..9da5fcb7 100644 --- a/paddle_billing/Client.py +++ b/paddle_billing/Client.py @@ -37,6 +37,12 @@ class PayloadEncoder(JSONEncoder): def default(self, z): + if isinstance(z, Undefined): + return None + + if hasattr(z, "to_json") and callable(z.to_json): + return z.to_json() + if is_dataclass(z): data = {} for field in fields(z): @@ -44,12 +50,6 @@ def default(self, z): return FiltersUndefined.filter_undefined_values(data) - if isinstance(z, Undefined): - return None - - if hasattr(z, "to_json") and callable(z.to_json): - return z.to_json() - return super().default(z) @@ -183,17 +183,11 @@ def get_raw(self, url: str, parameters: HasParameters | dict = None) -> Response def post_raw( self, url: str, payload: dict | Operation | None = None, parameters: HasParameters | dict | None = None ) -> Response: - if isinstance(payload, dict): - payload = FiltersUndefined.filter_undefined_values(payload) # Strip Undefined items from the dict - url = Client.format_uri_parameters(url, parameters) if parameters else url return self._make_request("POST", url, payload) def patch_raw(self, url: str, payload: dict | Operation | None) -> Response: - if isinstance(payload, dict): - payload = FiltersUndefined.filter_undefined_values(payload) # Strip Undefined items from the dict - return self._make_request("PATCH", url, payload) def delete_raw(self, url: str) -> Response: diff --git a/paddle_billing/Entities/Reports/ReportFilter.py b/paddle_billing/Entities/Reports/ReportFilter.py index 143a49e5..3f6e0869 100644 --- a/paddle_billing/Entities/Reports/ReportFilter.py +++ b/paddle_billing/Entities/Reports/ReportFilter.py @@ -1,5 +1,5 @@ from __future__ import annotations -from dataclasses import asdict, dataclass +from dataclasses import dataclass from paddle_billing.Entities.Reports import ReportFilterName, ReportFilterOperator @@ -13,6 +13,3 @@ class ReportFilter: @staticmethod def from_dict(data: dict) -> ReportFilter: return ReportFilter(**data) - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Entities/Shared/CustomData.py b/paddle_billing/Entities/Shared/CustomData.py index ba969afa..6244f56e 100644 --- a/paddle_billing/Entities/Shared/CustomData.py +++ b/paddle_billing/Entities/Shared/CustomData.py @@ -4,8 +4,5 @@ class CustomData: def __init__(self, data: dict | list): self.data = data - def get_parameters(self): - return self.data - def to_json(self): return self.data diff --git a/paddle_billing/Entities/Subscriptions/SubscriptionItems.py b/paddle_billing/Entities/Subscriptions/SubscriptionItems.py index e68470cf..86e24807 100644 --- a/paddle_billing/Entities/Subscriptions/SubscriptionItems.py +++ b/paddle_billing/Entities/Subscriptions/SubscriptionItems.py @@ -1,5 +1,5 @@ from __future__ import annotations -from dataclasses import asdict, dataclass +from dataclasses import dataclass @dataclass @@ -13,6 +13,3 @@ def from_dict(data: dict) -> SubscriptionItems: price_id=data["price_id"], quantity=data["quantity"], ) - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Entities/Subscriptions/SubscriptionItemsWithPrice.py b/paddle_billing/Entities/Subscriptions/SubscriptionItemsWithPrice.py index 6ea2bdbb..78942b7e 100644 --- a/paddle_billing/Entities/Subscriptions/SubscriptionItemsWithPrice.py +++ b/paddle_billing/Entities/Subscriptions/SubscriptionItemsWithPrice.py @@ -1,5 +1,5 @@ from __future__ import annotations -from dataclasses import asdict, dataclass +from dataclasses import dataclass from paddle_billing.Entities.Subscriptions.SubscriptionNonCatalogPrice import SubscriptionNonCatalogPrice from paddle_billing.Entities.Subscriptions.SubscriptionNonCatalogPriceWithProduct import ( @@ -18,6 +18,3 @@ def from_dict(data: dict) -> SubscriptionItemsWithPrice: price=data["price"], quantity=data["quantity"], ) - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Notifications/Entities/Reports/ReportFilter.py b/paddle_billing/Notifications/Entities/Reports/ReportFilter.py index 0e410fd8..3d3e171d 100644 --- a/paddle_billing/Notifications/Entities/Reports/ReportFilter.py +++ b/paddle_billing/Notifications/Entities/Reports/ReportFilter.py @@ -1,5 +1,5 @@ from __future__ import annotations -from dataclasses import asdict, dataclass +from dataclasses import dataclass from paddle_billing.Notifications.Entities.Reports import ReportFilterName, ReportFilterOperator @@ -13,6 +13,3 @@ class ReportFilter: @staticmethod def from_dict(data: dict) -> ReportFilter: return ReportFilter(**data) - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Notifications/Entities/Shared/CustomData.py b/paddle_billing/Notifications/Entities/Shared/CustomData.py index 3dbb409c..349610fc 100644 --- a/paddle_billing/Notifications/Entities/Shared/CustomData.py +++ b/paddle_billing/Notifications/Entities/Shared/CustomData.py @@ -5,5 +5,5 @@ class CustomData: data: dict | list # JSON serializable Python types - def get_parameters(self): + def to_json(self): return self.data diff --git a/paddle_billing/Resources/Addresses/AddressesClient.py b/paddle_billing/Resources/Addresses/AddressesClient.py index 138beab5..a00d4fbd 100644 --- a/paddle_billing/Resources/Addresses/AddressesClient.py +++ b/paddle_billing/Resources/Addresses/AddressesClient.py @@ -35,15 +35,13 @@ def get(self, customer_id: str, address_id: str) -> Address: return Address.from_dict(parser.get_data()) def create(self, customer_id: str, operation: CreateAddress) -> Address: - self.response = self.client.post_raw(f"/customers/{customer_id}/addresses", operation.get_parameters()) + self.response = self.client.post_raw(f"/customers/{customer_id}/addresses", operation) parser = ResponseParser(self.response) return Address.from_dict(parser.get_data()) def update(self, customer_id: str, address_id: str, operation: UpdateAddress) -> Address: - self.response = self.client.patch_raw( - f"/customers/{customer_id}/addresses/{address_id}", operation.get_parameters() - ) + self.response = self.client.patch_raw(f"/customers/{customer_id}/addresses/{address_id}", operation) parser = ResponseParser(self.response) return Address.from_dict(parser.get_data()) diff --git a/paddle_billing/Resources/Addresses/Operations/CreateAddress.py b/paddle_billing/Resources/Addresses/Operations/CreateAddress.py index f3d14eae..ae653ee9 100644 --- a/paddle_billing/Resources/Addresses/Operations/CreateAddress.py +++ b/paddle_billing/Resources/Addresses/Operations/CreateAddress.py @@ -1,11 +1,12 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Undefined import Undefined from paddle_billing.Entities.Shared import CountryCode, CustomData @dataclass -class CreateAddress: +class CreateAddress(Operation): country_code: CountryCode description: str | None = Undefined() first_line: str | None = Undefined() @@ -14,6 +15,3 @@ class CreateAddress: postal_code: str | None = Undefined() region: str | None = Undefined() custom_data: CustomData | None = Undefined() - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Resources/Addresses/Operations/UpdateAddress.py b/paddle_billing/Resources/Addresses/Operations/UpdateAddress.py index 14285e00..3c0a2599 100644 --- a/paddle_billing/Resources/Addresses/Operations/UpdateAddress.py +++ b/paddle_billing/Resources/Addresses/Operations/UpdateAddress.py @@ -1,11 +1,12 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Undefined import Undefined from paddle_billing.Entities.Shared import CountryCode, CustomData, Status @dataclass -class UpdateAddress: +class UpdateAddress(Operation): country_code: CountryCode | Undefined = Undefined() description: str | None | Undefined = Undefined() first_line: str | None | Undefined = Undefined() @@ -15,6 +16,3 @@ class UpdateAddress: region: str | None | Undefined = Undefined() custom_data: CustomData | None | Undefined = Undefined() status: Status | None | Undefined = Undefined() - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Resources/Adjustments/AdjustmentsClient.py b/paddle_billing/Resources/Adjustments/AdjustmentsClient.py index 2f2aac2d..f263c39b 100644 --- a/paddle_billing/Resources/Adjustments/AdjustmentsClient.py +++ b/paddle_billing/Resources/Adjustments/AdjustmentsClient.py @@ -29,7 +29,7 @@ def list(self, operation: ListAdjustments = None) -> AdjustmentCollection: ) def create(self, operation: CreateAdjustment) -> Adjustment: - self.response = self.client.post_raw("/adjustments", operation.get_parameters()) + self.response = self.client.post_raw("/adjustments", operation) parser = ResponseParser(self.response) return Adjustment.from_dict(parser.get_data()) diff --git a/paddle_billing/Resources/Adjustments/Operations/CreateAdjustment.py b/paddle_billing/Resources/Adjustments/Operations/CreateAdjustment.py index b4ac34e2..48a9dba4 100644 --- a/paddle_billing/Resources/Adjustments/Operations/CreateAdjustment.py +++ b/paddle_billing/Resources/Adjustments/Operations/CreateAdjustment.py @@ -1,30 +1,15 @@ from dataclasses import dataclass +from paddle_billing.Operation import Operation + from paddle_billing.Entities.Shared import Action from paddle_billing.Resources.Adjustments.Operations import CreateAdjustmentItem @dataclass -class CreateAdjustment: +class CreateAdjustment(Operation): action: Action items: list[CreateAdjustmentItem] reason: str transaction_id: str - - def get_parameters(self) -> dict: - items = [ - { - "item_id": item.item_id, - "type": item.type, - "amount": item.amount, - } - for item in self.items - ] - - return { - "action": self.action.value, - "items": items, - "reason": self.reason, - "transaction_id": self.transaction_id, - } diff --git a/paddle_billing/Resources/Businesses/BusinessesClient.py b/paddle_billing/Resources/Businesses/BusinessesClient.py index 4107214a..571fb494 100644 --- a/paddle_billing/Resources/Businesses/BusinessesClient.py +++ b/paddle_billing/Resources/Businesses/BusinessesClient.py @@ -35,15 +35,13 @@ def get(self, customer_id: str, business_id: str) -> Business: return Business.from_dict(parser.get_data()) def create(self, customer_id: str, operation: CreateBusiness) -> Business: - self.response = self.client.post_raw(f"/customers/{customer_id}/businesses", operation.get_parameters()) + self.response = self.client.post_raw(f"/customers/{customer_id}/businesses", operation) parser = ResponseParser(self.response) return Business.from_dict(parser.get_data()) def update(self, customer_id: str, business_id: str, operation: UpdateBusiness) -> Business: - self.response = self.client.patch_raw( - f"/customers/{customer_id}/businesses/{business_id}", operation.get_parameters() - ) + self.response = self.client.patch_raw(f"/customers/{customer_id}/businesses/{business_id}", operation) parser = ResponseParser(self.response) return Business.from_dict(parser.get_data()) diff --git a/paddle_billing/Resources/Businesses/Operations/CreateBusiness.py b/paddle_billing/Resources/Businesses/Operations/CreateBusiness.py index 49ff6ebb..8dd3a35f 100644 --- a/paddle_billing/Resources/Businesses/Operations/CreateBusiness.py +++ b/paddle_billing/Resources/Businesses/Operations/CreateBusiness.py @@ -1,16 +1,14 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Undefined import Undefined from paddle_billing.Entities.Shared import Contacts, CustomData @dataclass -class CreateBusiness: +class CreateBusiness(Operation): name: str company_number: str | None | Undefined = Undefined() tax_identifier: str | None | Undefined = Undefined() contacts: list[Contacts] | Undefined = Undefined() custom_data: CustomData | None | Undefined = Undefined() - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Resources/Businesses/Operations/UpdateBusiness.py b/paddle_billing/Resources/Businesses/Operations/UpdateBusiness.py index cbf7bc4a..71376ecc 100644 --- a/paddle_billing/Resources/Businesses/Operations/UpdateBusiness.py +++ b/paddle_billing/Resources/Businesses/Operations/UpdateBusiness.py @@ -1,17 +1,15 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Undefined import Undefined from paddle_billing.Entities.Shared import Contacts, CustomData, Status @dataclass -class UpdateBusiness: +class UpdateBusiness(Operation): name: str | Undefined = Undefined() company_number: str | None | Undefined = Undefined() tax_identifier: str | None | Undefined = Undefined() contacts: list[Contacts] | Undefined = Undefined() custom_data: CustomData | None | Undefined = Undefined() status: Status | Undefined = Undefined() - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Resources/Customers/CustomersClient.py b/paddle_billing/Resources/Customers/CustomersClient.py index 1992f80c..a3a5d918 100644 --- a/paddle_billing/Resources/Customers/CustomersClient.py +++ b/paddle_billing/Resources/Customers/CustomersClient.py @@ -40,13 +40,13 @@ def get(self, customer_id: str) -> Customer: return Customer.from_dict(parser.get_data()) def create(self, operation: CreateCustomer) -> Customer: - self.response = self.client.post_raw("/customers", operation.get_parameters()) + self.response = self.client.post_raw("/customers", operation) parser = ResponseParser(self.response) return Customer.from_dict(parser.get_data()) def update(self, customer_id: str, operation: UpdateCustomer) -> Customer: - self.response = self.client.patch_raw(f"/customers/{customer_id}", operation.get_parameters()) + self.response = self.client.patch_raw(f"/customers/{customer_id}", operation) parser = ResponseParser(self.response) return Customer.from_dict(parser.get_data()) diff --git a/paddle_billing/Resources/Customers/Operations/CreateCustomer.py b/paddle_billing/Resources/Customers/Operations/CreateCustomer.py index 3a127de1..8714b397 100644 --- a/paddle_billing/Resources/Customers/Operations/CreateCustomer.py +++ b/paddle_billing/Resources/Customers/Operations/CreateCustomer.py @@ -1,15 +1,13 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Undefined import Undefined from paddle_billing.Entities.Shared import CustomData @dataclass -class CreateCustomer: +class CreateCustomer(Operation): email: str name: str | None | Undefined = Undefined() custom_data: CustomData | None | Undefined = Undefined() locale: str | Undefined = Undefined() - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Resources/Customers/Operations/UpdateCustomer.py b/paddle_billing/Resources/Customers/Operations/UpdateCustomer.py index 0350d401..efda5394 100644 --- a/paddle_billing/Resources/Customers/Operations/UpdateCustomer.py +++ b/paddle_billing/Resources/Customers/Operations/UpdateCustomer.py @@ -1,16 +1,14 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Undefined import Undefined from paddle_billing.Entities.Shared import CustomData, Status @dataclass -class UpdateCustomer: +class UpdateCustomer(Operation): email: str | Undefined = Undefined() name: str | None | Undefined = Undefined() custom_data: CustomData | None | Undefined = Undefined() locale: str | Undefined = Undefined() status: Status | Undefined = Undefined() - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Resources/Discounts/DiscountsClient.py b/paddle_billing/Resources/Discounts/DiscountsClient.py index 72b6fd7a..43ea5f8b 100644 --- a/paddle_billing/Resources/Discounts/DiscountsClient.py +++ b/paddle_billing/Resources/Discounts/DiscountsClient.py @@ -35,13 +35,13 @@ def get(self, discount_id: str) -> Discount: return Discount.from_dict(parser.get_data()) def create(self, operation: CreateDiscount) -> Discount: - self.response = self.client.post_raw("/discounts", operation.get_parameters()) + self.response = self.client.post_raw("/discounts", operation) parser = ResponseParser(self.response) return Discount.from_dict(parser.get_data()) def update(self, discount_id: str, operation: UpdateDiscount) -> Discount: - self.response = self.client.patch_raw(f"/discounts/{discount_id}", operation.get_parameters()) + self.response = self.client.patch_raw(f"/discounts/{discount_id}", operation) parser = ResponseParser(self.response) return Discount.from_dict(parser.get_data()) diff --git a/paddle_billing/Resources/Discounts/Operations/CreateDiscount.py b/paddle_billing/Resources/Discounts/Operations/CreateDiscount.py index d6c68774..c4c1331e 100644 --- a/paddle_billing/Resources/Discounts/Operations/CreateDiscount.py +++ b/paddle_billing/Resources/Discounts/Operations/CreateDiscount.py @@ -1,12 +1,14 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Undefined import Undefined +from paddle_billing.Entities.DateTime import DateTime from paddle_billing.Entities.Discounts import DiscountType from paddle_billing.Entities.Shared import CurrencyCode, CustomData @dataclass -class CreateDiscount: +class CreateDiscount(Operation): amount: str description: str type: DiscountType @@ -17,8 +19,5 @@ class CreateDiscount: maximum_recurring_intervals: int | None | Undefined = Undefined() usage_limit: int | None | Undefined = Undefined() restrict_to: list[str] | None | Undefined = Undefined() - expires_at: str | None | Undefined = Undefined() + expires_at: DateTime | None | Undefined = Undefined() custom_data: CustomData | None | Undefined = Undefined() - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Resources/Discounts/Operations/UpdateDiscount.py b/paddle_billing/Resources/Discounts/Operations/UpdateDiscount.py index dd1a9aed..835bf832 100644 --- a/paddle_billing/Resources/Discounts/Operations/UpdateDiscount.py +++ b/paddle_billing/Resources/Discounts/Operations/UpdateDiscount.py @@ -1,12 +1,14 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Undefined import Undefined +from paddle_billing.Entities.DateTime import DateTime from paddle_billing.Entities.Discounts import DiscountStatus, DiscountType from paddle_billing.Entities.Shared import CurrencyCode, CustomData @dataclass -class UpdateDiscount: +class UpdateDiscount(Operation): amount: str | Undefined = Undefined() description: str | Undefined = Undefined() type: DiscountType | Undefined = Undefined() @@ -17,9 +19,6 @@ class UpdateDiscount: maximum_recurring_intervals: int | None | Undefined = Undefined() usage_limit: int | None | Undefined = Undefined() restrict_to: list[str] | None | Undefined = Undefined() - expires_at: str | None | Undefined = Undefined() + expires_at: DateTime | None | Undefined = Undefined() status: DiscountStatus | Undefined = Undefined() custom_data: CustomData | None | Undefined = Undefined() - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Resources/NotificationSettings/NotificationSettingsClient.py b/paddle_billing/Resources/NotificationSettings/NotificationSettingsClient.py index aec26cfe..2f559463 100644 --- a/paddle_billing/Resources/NotificationSettings/NotificationSettingsClient.py +++ b/paddle_billing/Resources/NotificationSettings/NotificationSettingsClient.py @@ -39,15 +39,13 @@ def get(self, notification_setting_id: str) -> NotificationSetting: return NotificationSetting.from_dict(parser.get_data()) def create(self, operation: CreateNotificationSetting) -> NotificationSetting: - self.response = self.client.post_raw("/notification-settings", operation.get_parameters()) + self.response = self.client.post_raw("/notification-settings", operation) parser = ResponseParser(self.response) return NotificationSetting.from_dict(parser.get_data()) def update(self, notification_setting_id: str, operation: UpdateNotificationSetting) -> NotificationSetting: - self.response = self.client.patch_raw( - f"/notification-settings/{notification_setting_id}", operation.get_parameters() - ) + self.response = self.client.patch_raw(f"/notification-settings/{notification_setting_id}", operation) parser = ResponseParser(self.response) return NotificationSetting.from_dict(parser.get_data()) diff --git a/paddle_billing/Resources/NotificationSettings/Operations/CreateNotificationSetting.py b/paddle_billing/Resources/NotificationSettings/Operations/CreateNotificationSetting.py index 95875892..d23f72cc 100644 --- a/paddle_billing/Resources/NotificationSettings/Operations/CreateNotificationSetting.py +++ b/paddle_billing/Resources/NotificationSettings/Operations/CreateNotificationSetting.py @@ -1,18 +1,16 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Undefined import Undefined from paddle_billing.Entities.Events import EventTypeName from paddle_billing.Entities.NotificationSettings import NotificationSettingType @dataclass -class CreateNotificationSetting: +class CreateNotificationSetting(Operation): description: str destination: str subscribed_events: list[EventTypeName] type: NotificationSettingType include_sensitive_fields: bool api_version: int | Undefined = Undefined() - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Resources/NotificationSettings/Operations/UpdateNotificationSetting.py b/paddle_billing/Resources/NotificationSettings/Operations/UpdateNotificationSetting.py index 85f359b8..09c63710 100644 --- a/paddle_billing/Resources/NotificationSettings/Operations/UpdateNotificationSetting.py +++ b/paddle_billing/Resources/NotificationSettings/Operations/UpdateNotificationSetting.py @@ -1,17 +1,15 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Undefined import Undefined from paddle_billing.Entities.Events import EventTypeName @dataclass -class UpdateNotificationSetting: +class UpdateNotificationSetting(Operation): description: str | Undefined = Undefined() destination: str | Undefined = Undefined() active: bool | Undefined = Undefined() api_version: int | Undefined = Undefined() include_sensitive_fields: bool | Undefined = Undefined() subscribed_events: list[EventTypeName] | Undefined = Undefined() - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Resources/Prices/Operations/CreatePrice.py b/paddle_billing/Resources/Prices/Operations/CreatePrice.py index afd1db39..b526e848 100644 --- a/paddle_billing/Resources/Prices/Operations/CreatePrice.py +++ b/paddle_billing/Resources/Prices/Operations/CreatePrice.py @@ -1,5 +1,6 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Undefined import Undefined from paddle_billing.Entities.Shared import ( CatalogType, @@ -13,7 +14,7 @@ @dataclass -class CreatePrice: +class CreatePrice(Operation): description: str product_id: str unit_price: Money @@ -25,6 +26,3 @@ class CreatePrice: billing_cycle: Duration | None | Undefined = Undefined() quantity: PriceQuantity | Undefined = Undefined() custom_data: CustomData | Undefined = Undefined() - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Resources/Prices/Operations/UpdatePrice.py b/paddle_billing/Resources/Prices/Operations/UpdatePrice.py index 4eb8ee33..7b1838fd 100644 --- a/paddle_billing/Resources/Prices/Operations/UpdatePrice.py +++ b/paddle_billing/Resources/Prices/Operations/UpdatePrice.py @@ -1,5 +1,6 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Undefined import Undefined from paddle_billing.Entities.Shared import ( CatalogType, @@ -14,7 +15,7 @@ @dataclass -class UpdatePrice: +class UpdatePrice(Operation): description: str | Undefined = Undefined() name: str | None | Undefined = Undefined() type: CatalogType | Undefined = Undefined() @@ -26,6 +27,3 @@ class UpdatePrice: quantity: PriceQuantity | Undefined = Undefined() status: Status | Undefined = Undefined() custom_data: CustomData | None | Undefined = Undefined() - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Resources/Prices/PricesClient.py b/paddle_billing/Resources/Prices/PricesClient.py index f5254607..2df0ae02 100644 --- a/paddle_billing/Resources/Prices/PricesClient.py +++ b/paddle_billing/Resources/Prices/PricesClient.py @@ -47,13 +47,13 @@ def get(self, price_id: str, includes=None) -> Price: return Price.from_dict(parser.get_data()) def create(self, operation: CreatePrice) -> Price: - self.response = self.client.post_raw("/prices", operation.get_parameters()) + self.response = self.client.post_raw("/prices", operation) parser = ResponseParser(self.response) return Price.from_dict(parser.get_data()) def update(self, price_id: str, operation: UpdatePrice) -> Price: - self.response = self.client.patch_raw(f"/prices/{price_id}", operation.get_parameters()) + self.response = self.client.patch_raw(f"/prices/{price_id}", operation) parser = ResponseParser(self.response) return Price.from_dict(parser.get_data()) diff --git a/paddle_billing/Resources/PricingPreviews/Operations/PreviewPrice.py b/paddle_billing/Resources/PricingPreviews/Operations/PreviewPrice.py index b3306a32..6e4f83ef 100644 --- a/paddle_billing/Resources/PricingPreviews/Operations/PreviewPrice.py +++ b/paddle_billing/Resources/PricingPreviews/Operations/PreviewPrice.py @@ -1,5 +1,6 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Undefined import Undefined from paddle_billing.Entities.PricingPreviews import PricePreviewItem from paddle_billing.Entities.Shared import CurrencyCode, AddressPreview @@ -8,7 +9,7 @@ @dataclass -class PreviewPrice: +class PreviewPrice(Operation): items: list[PricePreviewItem] customer_id: str | None | Undefined = Undefined() address_id: str | None | Undefined = Undefined() @@ -28,6 +29,3 @@ def __post_init__(self): raise InvalidArgumentException.array_contains_invalid_types( "items", PricePreviewItem.__name__, invalid_items ) - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Resources/PricingPreviews/PricingPreviewsClient.py b/paddle_billing/Resources/PricingPreviews/PricingPreviewsClient.py index 0f4361a9..45589642 100644 --- a/paddle_billing/Resources/PricingPreviews/PricingPreviewsClient.py +++ b/paddle_billing/Resources/PricingPreviews/PricingPreviewsClient.py @@ -14,7 +14,7 @@ def __init__(self, client: "Client"): self.response = None def preview_prices(self, operation: PreviewPrice) -> PricePreview: - self.response = self.client.post_raw("/pricing-preview", operation.get_parameters()) + self.response = self.client.post_raw("/pricing-preview", operation) parser = ResponseParser(self.response) return PricePreview.from_dict(parser.get_data()) diff --git a/paddle_billing/Resources/Products/Operations/CreateProduct.py b/paddle_billing/Resources/Products/Operations/CreateProduct.py index 698ec8a2..2ffc0bd0 100644 --- a/paddle_billing/Resources/Products/Operations/CreateProduct.py +++ b/paddle_billing/Resources/Products/Operations/CreateProduct.py @@ -1,17 +1,15 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Undefined import Undefined from paddle_billing.Entities.Shared import CatalogType, CustomData, TaxCategory @dataclass -class CreateProduct: +class CreateProduct(Operation): name: str tax_category: TaxCategory type: CatalogType | None | Undefined = Undefined() description: str | None | Undefined = Undefined() image_url: str | None | Undefined = Undefined() custom_data: CustomData | None | Undefined = Undefined() - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Resources/Products/Operations/UpdateProduct.py b/paddle_billing/Resources/Products/Operations/UpdateProduct.py index e5a2a0f6..e5e0e383 100644 --- a/paddle_billing/Resources/Products/Operations/UpdateProduct.py +++ b/paddle_billing/Resources/Products/Operations/UpdateProduct.py @@ -1,11 +1,12 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Undefined import Undefined from paddle_billing.Entities.Shared import CatalogType, CustomData, Status, TaxCategory @dataclass -class UpdateProduct: +class UpdateProduct(Operation): name: str | Undefined = Undefined() description: str | None | Undefined = Undefined() type: CatalogType | None | Undefined = Undefined() @@ -13,6 +14,3 @@ class UpdateProduct: image_url: str | None | Undefined = Undefined() custom_data: CustomData | None | Undefined = Undefined() status: Status | Undefined = Undefined() - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Resources/Products/ProductsClient.py b/paddle_billing/Resources/Products/ProductsClient.py index 23448dce..b210c6fe 100644 --- a/paddle_billing/Resources/Products/ProductsClient.py +++ b/paddle_billing/Resources/Products/ProductsClient.py @@ -52,13 +52,13 @@ def get(self, product_id: str, includes=None) -> Product | Product: return Product.from_dict(parser.get_data()) def create(self, operation: CreateProduct) -> Product: - self.response = self.client.post_raw("/products", operation.get_parameters()) + self.response = self.client.post_raw("/products", operation) parser = ResponseParser(self.response) return Product.from_dict(parser.get_data()) def update(self, product_id: str, operation: UpdateProduct) -> Product: - self.response = self.client.patch_raw(f"/products/{product_id}", operation.get_parameters()) + self.response = self.client.patch_raw(f"/products/{product_id}", operation) parser = ResponseParser(self.response) return Product.from_dict(parser.get_data()) diff --git a/paddle_billing/Resources/Reports/Operations/CreateReport.py b/paddle_billing/Resources/Reports/Operations/CreateReport.py index 3c2d9f4f..5439b788 100644 --- a/paddle_billing/Resources/Reports/Operations/CreateReport.py +++ b/paddle_billing/Resources/Reports/Operations/CreateReport.py @@ -1,13 +1,15 @@ from dataclasses import dataclass, field from abc import ABC, abstractmethod +from paddle_billing.Operation import Operation + from paddle_billing.Entities.Reports import ReportType, ReportFilter from paddle_billing.Exceptions.SdkExceptions.InvalidArgumentException import InvalidArgumentException @dataclass -class CreateReport(ABC): +class CreateReport(Operation, ABC): type: ReportType filters: list[ReportFilter] = field(default_factory=list) @@ -21,11 +23,11 @@ def __post_init__(self): raise InvalidArgumentException.array_contains_invalid_types("filters", allowed_type_names, invalid_items) - def get_parameters(self) -> dict: + def to_json(self) -> dict: parameters = {"type": self.type} if self.filters is not None and self.filters != []: - parameters.update({"filters": [filter_.get_parameters() for filter_ in self.filters]}) + parameters.update({"filters": [filter_ for filter_ in self.filters]}) return parameters diff --git a/paddle_billing/Resources/Reports/Operations/Filters/Filter.py b/paddle_billing/Resources/Reports/Operations/Filters/Filter.py index 429d6499..6125e92c 100644 --- a/paddle_billing/Resources/Reports/Operations/Filters/Filter.py +++ b/paddle_billing/Resources/Reports/Operations/Filters/Filter.py @@ -9,7 +9,7 @@ @dataclass class Filter(ABC): - def get_parameters(self) -> dict: + def to_json(self) -> dict: return { "name": self.get_name(), "operator": self.get_operator(), diff --git a/paddle_billing/Resources/Reports/ReportsClient.py b/paddle_billing/Resources/Reports/ReportsClient.py index cba285a6..867f6fa7 100644 --- a/paddle_billing/Resources/Reports/ReportsClient.py +++ b/paddle_billing/Resources/Reports/ReportsClient.py @@ -41,7 +41,7 @@ def get_report_csv(self, report_id: str) -> ReportCSV: return ReportCSV.from_dict(parser.get_data()) def create(self, operation: CreateReport) -> Report: - self.response = self.client.post_raw("/reports", operation.get_parameters()) + self.response = self.client.post_raw("/reports", operation) parser = ResponseParser(self.response) return Report.from_dict(parser.get_data()) diff --git a/paddle_billing/Resources/Subscriptions/Operations/CancelSubscription.py b/paddle_billing/Resources/Subscriptions/Operations/CancelSubscription.py index 19d155c9..21924817 100644 --- a/paddle_billing/Resources/Subscriptions/Operations/CancelSubscription.py +++ b/paddle_billing/Resources/Subscriptions/Operations/CancelSubscription.py @@ -1,11 +1,9 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Entities.Subscriptions import SubscriptionEffectiveFrom @dataclass -class CancelSubscription: +class CancelSubscription(Operation): effective_from: SubscriptionEffectiveFrom = None - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Resources/Subscriptions/Operations/CreateOneTimeCharge.py b/paddle_billing/Resources/Subscriptions/Operations/CreateOneTimeCharge.py index 49e7a24b..ebe9b46d 100644 --- a/paddle_billing/Resources/Subscriptions/Operations/CreateOneTimeCharge.py +++ b/paddle_billing/Resources/Subscriptions/Operations/CreateOneTimeCharge.py @@ -1,5 +1,6 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Undefined import Undefined from paddle_billing.Entities.Subscriptions import ( @@ -11,10 +12,7 @@ @dataclass -class CreateOneTimeCharge: +class CreateOneTimeCharge(Operation): effective_from: SubscriptionEffectiveFrom items: list[SubscriptionItems | SubscriptionItemsWithPrice] on_payment_failure: SubscriptionOnPaymentFailure | Undefined = Undefined() - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Resources/Subscriptions/Operations/PauseSubscription.py b/paddle_billing/Resources/Subscriptions/Operations/PauseSubscription.py index 1f0e0c3a..2e9ed95c 100644 --- a/paddle_billing/Resources/Subscriptions/Operations/PauseSubscription.py +++ b/paddle_billing/Resources/Subscriptions/Operations/PauseSubscription.py @@ -1,16 +1,11 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Entities.DateTime import DateTime from paddle_billing.Entities.Subscriptions import SubscriptionEffectiveFrom @dataclass -class PauseSubscription: +class PauseSubscription(Operation): effective_from: SubscriptionEffectiveFrom | None = None resume_at: DateTime | None = None - - def get_parameters(self) -> dict: - parameters = asdict(self) - parameters["resume_at"] = self.resume_at.format() if isinstance(self.resume_at, DateTime) else self.resume_at - - return parameters diff --git a/paddle_billing/Resources/Subscriptions/Operations/PreviewOneTimeCharge.py b/paddle_billing/Resources/Subscriptions/Operations/PreviewOneTimeCharge.py index 1cedcfd9..6e3d2b66 100644 --- a/paddle_billing/Resources/Subscriptions/Operations/PreviewOneTimeCharge.py +++ b/paddle_billing/Resources/Subscriptions/Operations/PreviewOneTimeCharge.py @@ -1,5 +1,6 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Undefined import Undefined from paddle_billing.Entities.Subscriptions import ( @@ -11,10 +12,7 @@ @dataclass -class PreviewOneTimeCharge: +class PreviewOneTimeCharge(Operation): effective_from: SubscriptionEffectiveFrom items: list[SubscriptionItems | SubscriptionItemsWithPrice] on_payment_failure: SubscriptionOnPaymentFailure | Undefined = Undefined() - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Resources/Subscriptions/Operations/ResumeSubscription.py b/paddle_billing/Resources/Subscriptions/Operations/ResumeSubscription.py index 3e851821..d337264d 100644 --- a/paddle_billing/Resources/Subscriptions/Operations/ResumeSubscription.py +++ b/paddle_billing/Resources/Subscriptions/Operations/ResumeSubscription.py @@ -1,16 +1,10 @@ from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Entities.DateTime import DateTime from paddle_billing.Entities.Subscriptions import SubscriptionResumeEffectiveFrom @dataclass -class ResumeSubscription: +class ResumeSubscription(Operation): effective_from: SubscriptionResumeEffectiveFrom | DateTime | None = None - - def get_parameters(self) -> dict: - effective_from = ( - self.effective_from.format() if isinstance(self.effective_from, DateTime) else self.effective_from - ) - - return {"effective_from": effective_from} diff --git a/paddle_billing/Resources/Subscriptions/SubscriptionsClient.py b/paddle_billing/Resources/Subscriptions/SubscriptionsClient.py index 4348d2f0..d9e7b5d7 100644 --- a/paddle_billing/Resources/Subscriptions/SubscriptionsClient.py +++ b/paddle_billing/Resources/Subscriptions/SubscriptionsClient.py @@ -64,19 +64,19 @@ def update(self, subscription_id: str, operation: UpdateSubscription) -> Subscri return Subscription.from_dict(parser.get_data()) def pause(self, subscription_id: str, operation: PauseSubscription) -> Subscription: - self.response = self.client.post_raw(f"/subscriptions/{subscription_id}/pause", operation.get_parameters()) + self.response = self.client.post_raw(f"/subscriptions/{subscription_id}/pause", operation) parser = ResponseParser(self.response) return Subscription.from_dict(parser.get_data()) def resume(self, subscription_id: str, operation: ResumeSubscription) -> Subscription: - self.response = self.client.post_raw(f"/subscriptions/{subscription_id}/resume", operation.get_parameters()) + self.response = self.client.post_raw(f"/subscriptions/{subscription_id}/resume", operation) parser = ResponseParser(self.response) return Subscription.from_dict(parser.get_data()) def cancel(self, subscription_id: str, operation: CancelSubscription) -> Subscription: - self.response = self.client.post_raw(f"/subscriptions/{subscription_id}/cancel", operation.get_parameters()) + self.response = self.client.post_raw(f"/subscriptions/{subscription_id}/cancel", operation) parser = ResponseParser(self.response) return Subscription.from_dict(parser.get_data()) @@ -94,7 +94,7 @@ def activate(self, subscription_id: str) -> Subscription: return Subscription.from_dict(parser.get_data()) def create_one_time_charge(self, subscription_id: str, operation: CreateOneTimeCharge) -> Subscription: - self.response = self.client.post_raw(f"/subscriptions/{subscription_id}/charge", operation.get_parameters()) + self.response = self.client.post_raw(f"/subscriptions/{subscription_id}/charge", operation) parser = ResponseParser(self.response) return Subscription.from_dict(parser.get_data()) @@ -106,9 +106,7 @@ def preview_update(self, subscription_id: str, operation: PreviewUpdateSubscript return SubscriptionPreview.from_dict(parser.get_data()) def preview_one_time_charge(self, subscription_id: str, operation: PreviewOneTimeCharge) -> SubscriptionPreview: - self.response = self.client.post_raw( - f"/subscriptions/{subscription_id}/charge/preview", operation.get_parameters() - ) + self.response = self.client.post_raw(f"/subscriptions/{subscription_id}/charge/preview", operation) parser = ResponseParser(self.response) return SubscriptionPreview.from_dict(parser.get_data()) diff --git a/paddle_billing/Resources/Transactions/Operations/PreviewTransactionByAddress.py b/paddle_billing/Resources/Transactions/Operations/PreviewTransactionByAddress.py index 438cca95..a1cffe14 100644 --- a/paddle_billing/Resources/Transactions/Operations/PreviewTransactionByAddress.py +++ b/paddle_billing/Resources/Transactions/Operations/PreviewTransactionByAddress.py @@ -1,5 +1,6 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Undefined import Undefined from paddle_billing.Entities.Shared import AddressPreview, CurrencyCode from paddle_billing.Entities.Transactions import ( @@ -9,13 +10,10 @@ @dataclass -class PreviewTransactionByAddress: +class PreviewTransactionByAddress(Operation): address: AddressPreview items: list[TransactionItemPreviewWithPriceId | TransactionItemPreviewWithNonCatalogPrice] customer_id: str | None | Undefined = Undefined() currency_code: CurrencyCode | Undefined = Undefined() discount_id: str | None | Undefined = Undefined() ignore_trials: bool | Undefined = Undefined() - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Resources/Transactions/Operations/PreviewTransactionByCustomer.py b/paddle_billing/Resources/Transactions/Operations/PreviewTransactionByCustomer.py index d61802da..ad02b023 100644 --- a/paddle_billing/Resources/Transactions/Operations/PreviewTransactionByCustomer.py +++ b/paddle_billing/Resources/Transactions/Operations/PreviewTransactionByCustomer.py @@ -1,5 +1,6 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Undefined import Undefined from paddle_billing.Entities.Shared import CurrencyCode from paddle_billing.Entities.Transactions import ( @@ -9,7 +10,7 @@ @dataclass -class PreviewTransactionByCustomer: +class PreviewTransactionByCustomer(Operation): address_id: str customer_id: str items: list[TransactionItemPreviewWithPriceId | TransactionItemPreviewWithNonCatalogPrice] @@ -17,6 +18,3 @@ class PreviewTransactionByCustomer: currency_code: CurrencyCode | Undefined = Undefined() discount_id: str | None | Undefined = Undefined() ignore_trials: bool | Undefined = Undefined() - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Resources/Transactions/Operations/PreviewTransactionByIP.py b/paddle_billing/Resources/Transactions/Operations/PreviewTransactionByIP.py index 5c0fa497..61e00687 100644 --- a/paddle_billing/Resources/Transactions/Operations/PreviewTransactionByIP.py +++ b/paddle_billing/Resources/Transactions/Operations/PreviewTransactionByIP.py @@ -1,5 +1,6 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass +from paddle_billing.Operation import Operation from paddle_billing.Undefined import Undefined from paddle_billing.Entities.Shared import CurrencyCode from paddle_billing.Entities.Transactions import ( @@ -9,13 +10,10 @@ @dataclass -class PreviewTransactionByIP: +class PreviewTransactionByIP(Operation): customer_ip_address: str items: list[TransactionItemPreviewWithPriceId | TransactionItemPreviewWithNonCatalogPrice] customer_id: str | None | Undefined = Undefined() currency_code: CurrencyCode | Undefined = Undefined() discount_id: str | None | Undefined = Undefined() ignore_trials: bool | Undefined = Undefined() - - def get_parameters(self) -> dict: - return asdict(self) diff --git a/paddle_billing/Resources/Transactions/TransactionsClient.py b/paddle_billing/Resources/Transactions/TransactionsClient.py index 7af36612..a93b4147 100644 --- a/paddle_billing/Resources/Transactions/TransactionsClient.py +++ b/paddle_billing/Resources/Transactions/TransactionsClient.py @@ -81,7 +81,7 @@ def update(self, transaction_id: str, operation: UpdateTransaction) -> Transacti def preview( self, operation: PreviewTransactionByAddress | PreviewTransactionByCustomer | PreviewTransactionByIP ) -> TransactionPreview: - self.response = self.client.post_raw("/transactions/preview", operation.get_parameters()) + self.response = self.client.post_raw("/transactions/preview", operation) parser = ResponseParser(self.response) return TransactionPreview.from_dict(parser.get_data()) diff --git a/tests/Functional/Resources/Discounts/_fixtures/request/create_full.json b/tests/Functional/Resources/Discounts/_fixtures/request/create_full.json index f79dc663..a1fc573e 100644 --- a/tests/Functional/Resources/Discounts/_fixtures/request/create_full.json +++ b/tests/Functional/Resources/Discounts/_fixtures/request/create_full.json @@ -12,7 +12,7 @@ "pro_01gsz4t5hdjse780zja8vvr7jg", "pro_01gsz4s0w61y0pp88528f1wvvb" ], - "expires_at": "2025-01-01 10:00:00", + "expires_at": "2025-01-01T10:00:00.000000Z", "custom_data": { "key": "value" } diff --git a/tests/Functional/Resources/Discounts/_fixtures/request/update_full.json b/tests/Functional/Resources/Discounts/_fixtures/request/update_full.json index e52cc61a..4f58894f 100644 --- a/tests/Functional/Resources/Discounts/_fixtures/request/update_full.json +++ b/tests/Functional/Resources/Discounts/_fixtures/request/update_full.json @@ -12,7 +12,7 @@ "pro_01gsz4t5hdjse780zja8vvr7jg", "pro_01gsz4s0w61y0pp88528f1wvvb" ], - "expires_at": "2025-01-01 10:00:00", + "expires_at": "2025-01-01T10:00:00.000000Z", "status": "active", "custom_data": { "key": "value" diff --git a/tests/Functional/Resources/Discounts/test_DiscountsClient.py b/tests/Functional/Resources/Discounts/test_DiscountsClient.py index e169e5a7..d59a6bdf 100644 --- a/tests/Functional/Resources/Discounts/test_DiscountsClient.py +++ b/tests/Functional/Resources/Discounts/test_DiscountsClient.py @@ -3,6 +3,7 @@ from urllib.parse import unquote from paddle_billing.Entities.Collections import DiscountCollection +from paddle_billing.Entities.DateTime import DateTime from paddle_billing.Entities.Discount import Discount from paddle_billing.Entities.Discounts import DiscountStatus, DiscountType from paddle_billing.Entities.Shared import CurrencyCode, Status, CustomData @@ -43,7 +44,7 @@ class TestDiscountsClient: maximum_recurring_intervals=5, usage_limit=1000, restrict_to=["pro_01gsz4t5hdjse780zja8vvr7jg", "pro_01gsz4s0w61y0pp88528f1wvvb"], - expires_at="2025-01-01 10:00:00", + expires_at=DateTime("2025-01-01 10:00:00"), custom_data=CustomData({"key": "value"}), ), ReadsFixtures.read_raw_json_fixture("request/create_full"), @@ -144,7 +145,7 @@ def test_create_discount_response_has_custom_data( code="ABCDE12345", maximum_recurring_intervals=5, usage_limit=1000, - expires_at="2025-01-01 10:00:00", + expires_at=DateTime("2025-01-01 10:00:00"), status=DiscountStatus.Active, restrict_to=[ "pro_01gsz4t5hdjse780zja8vvr7jg",