Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Graceful fallback with PaddleStrEnum #20

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions paddle_billing/Client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from json import dumps as json_dumps
from json import dumps as json_dumps, JSONEncoder
from logging import Logger, getLogger
from requests import Response, RequestException, Session
from requests.adapters import HTTPAdapter
Expand All @@ -9,6 +9,7 @@
from paddle_billing.FiltersUndefined import FiltersUndefined
from paddle_billing.HasParameters import HasParameters
from paddle_billing.Options import Options
from paddle_billing.PaddleStrEnum import PaddleStrEnum
from paddle_billing.ResponseParser import ResponseParser

from paddle_billing.Logger.NullHandler import NullHandler
Expand All @@ -30,6 +31,12 @@
from paddle_billing.Resources.Subscriptions.SubscriptionsClient import SubscriptionsClient
from paddle_billing.Resources.Transactions.TransactionsClient import TransactionsClient

class PayloadEncoder(JSONEncoder):
def default(self, z):
if hasattr(z, 'to_json') and callable(z.to_json):
return z.to_json()

return super().default(z)

class Client:
"""
Expand Down Expand Up @@ -100,7 +107,7 @@ def serialize_json_payload(payload: dict) -> str:
if payload.get('custom_data') and 'data' in payload['custom_data']:
payload['custom_data'] = payload['custom_data']['data']

json_payload = json_dumps(payload)
json_payload = json_dumps(payload, cls=PayloadEncoder)
final_json = json_payload if json_payload != '[]' else '{}'

return final_json
Expand Down
12 changes: 6 additions & 6 deletions paddle_billing/Entities/Discounts/DiscountStatus.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from paddle_billing.PaddleStrEnum import PaddleStrEnum
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta


class DiscountStatus(PaddleStrEnum):
Active = 'active'
Archived = 'archived'
Expired = 'expired'
Used = 'used'
class DiscountStatus(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
Active: "DiscountStatus" = 'active'
Archived: "DiscountStatus" = 'archived'
Expired: "DiscountStatus" = 'expired'
Used: "DiscountStatus" = 'used'
10 changes: 5 additions & 5 deletions paddle_billing/Entities/Discounts/DiscountType.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from paddle_billing.PaddleStrEnum import PaddleStrEnum
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta


class DiscountType(PaddleStrEnum):
Flat = 'flat'
FlatPerSeat = 'flat_per_seat'
Percentage = 'percentage'
class DiscountType(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
Flat: "DiscountType" = 'flat'
FlatPerSeat: "DiscountType" = 'flat_per_seat'
Percentage: "DiscountType" = 'percentage'
100 changes: 50 additions & 50 deletions paddle_billing/Entities/Events/EventTypeName.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
from paddle_billing.PaddleStrEnum import PaddleStrEnum
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta


class EventTypeName(PaddleStrEnum):
AddressCreated = 'address.created'
AddressImported = 'address.imported'
AddressUpdated = 'address.updated'
AdjustmentCreated = 'adjustment.created'
AdjustmentUpdated = 'adjustment.updated'
BusinessCreated = 'business.created'
BusinessImported = 'business.imported'
BusinessUpdated = 'business.updated'
CustomerCreated = 'customer.created'
CustomerImported = 'customer.imported'
CustomerUpdated = 'customer.updated'
DiscountCreated = 'discount.created'
DiscountImported = 'discount.imported'
DiscountUpdated = 'discount.updated'
InvoiceCanceled = 'invoice.canceled'
InvoiceCreated = 'invoice.created'
InvoiceIssued = 'invoice.issued'
InvoiceOverdue = 'invoice.overdue'
InvoicePaid = 'invoice.paid'
InvoiceScheduled = 'invoice.scheduled'
PayoutCreated = 'payout.created'
PayoutPaid = 'payout.paid'
PriceCreated = 'price.created'
PriceUpdated = 'price.updated'
PriceImported = 'price.imported'
ProductCreated = 'product.created'
ProductUpdated = 'product.updated'
ProductImported = 'product.imported'
SubscriptionActivated = 'subscription.activated'
SubscriptionCanceled = 'subscription.canceled'
SubscriptionCreated = 'subscription.created'
SubscriptionImported = 'subscription.imported'
SubscriptionPastDue = 'subscription.past_due'
SubscriptionPaused = 'subscription.paused'
SubscriptionResumed = 'subscription.resumed'
SubscriptionTrialing = 'subscription.trialing'
SubscriptionUpdated = 'subscription.updated'
TransactionBilled = 'transaction.billed'
TransactionCanceled = 'transaction.canceled'
TransactionCompleted = 'transaction.completed'
TransactionCreated = 'transaction.created'
TransactionPaid = 'transaction.paid'
TransactionPastDue = 'transaction.past_due'
TransactionPaymentFailed = 'transaction.payment_failed'
TransactionReady = 'transaction.ready'
TransactionUpdated = 'transaction.updated'
ReportCreated = 'report.created'
ReportUpdated = 'report.updated'
class EventTypeName(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
AddressCreated: "EventTypeName" = 'address.created'
AddressImported: "EventTypeName" = 'address.imported'
AddressUpdated: "EventTypeName" = 'address.updated'
AdjustmentCreated: "EventTypeName" = 'adjustment.created'
AdjustmentUpdated: "EventTypeName" = 'adjustment.updated'
BusinessCreated: "EventTypeName" = 'business.created'
BusinessImported: "EventTypeName" = 'business.imported'
BusinessUpdated: "EventTypeName" = 'business.updated'
CustomerCreated: "EventTypeName" = 'customer.created'
CustomerImported: "EventTypeName" = 'customer.imported'
CustomerUpdated: "EventTypeName" = 'customer.updated'
DiscountCreated: "EventTypeName" = 'discount.created'
DiscountImported: "EventTypeName" = 'discount.imported'
DiscountUpdated: "EventTypeName" = 'discount.updated'
InvoiceCanceled: "EventTypeName" = 'invoice.canceled'
InvoiceCreated: "EventTypeName" = 'invoice.created'
InvoiceIssued: "EventTypeName" = 'invoice.issued'
InvoiceOverdue: "EventTypeName" = 'invoice.overdue'
InvoicePaid: "EventTypeName" = 'invoice.paid'
InvoiceScheduled: "EventTypeName" = 'invoice.scheduled'
PayoutCreated: "EventTypeName" = 'payout.created'
PayoutPaid: "EventTypeName" = 'payout.paid'
PriceCreated: "EventTypeName" = 'price.created'
PriceUpdated: "EventTypeName" = 'price.updated'
PriceImported: "EventTypeName" = 'price.imported'
ProductCreated: "EventTypeName" = 'product.created'
ProductUpdated: "EventTypeName" = 'product.updated'
ProductImported: "EventTypeName" = 'product.imported'
SubscriptionActivated: "EventTypeName" = 'subscription.activated'
SubscriptionCanceled: "EventTypeName" = 'subscription.canceled'
SubscriptionCreated: "EventTypeName" = 'subscription.created'
SubscriptionImported: "EventTypeName" = 'subscription.imported'
SubscriptionPastDue: "EventTypeName" = 'subscription.past_due'
SubscriptionPaused: "EventTypeName" = 'subscription.paused'
SubscriptionResumed: "EventTypeName" = 'subscription.resumed'
SubscriptionTrialing: "EventTypeName" = 'subscription.trialing'
SubscriptionUpdated: "EventTypeName" = 'subscription.updated'
TransactionBilled: "EventTypeName" = 'transaction.billed'
TransactionCanceled: "EventTypeName" = 'transaction.canceled'
TransactionCompleted: "EventTypeName" = 'transaction.completed'
TransactionCreated: "EventTypeName" = 'transaction.created'
TransactionPaid: "EventTypeName" = 'transaction.paid'
TransactionPastDue: "EventTypeName" = 'transaction.past_due'
TransactionPaymentFailed: "EventTypeName" = 'transaction.payment_failed'
TransactionReady: "EventTypeName" = 'transaction.ready'
TransactionUpdated: "EventTypeName" = 'transaction.updated'
ReportCreated: "EventTypeName" = 'report.created'
ReportUpdated: "EventTypeName" = 'report.updated'
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from paddle_billing.PaddleStrEnum import PaddleStrEnum
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta


class NotificationSettingType(PaddleStrEnum):
Email = 'email'
Url = 'url'
class NotificationSettingType(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
Email: "NotificationSettingType" = 'email'
Url: "NotificationSettingType" = 'url'
8 changes: 4 additions & 4 deletions paddle_billing/Entities/Notifications/NotificationOrigin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from paddle_billing.PaddleStrEnum import PaddleStrEnum
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta


class NotificationOrigin(PaddleStrEnum):
Event = 'event'
Replay = 'replay'
class NotificationOrigin(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
Event: "NotificationOrigin" = 'event'
Replay: "NotificationOrigin" = 'replay'
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from paddle_billing.PaddleStrEnum import PaddleStrEnum
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta


class NotificationPayoutStatus(PaddleStrEnum):
Unpaid = 'unpaid'
Paid = 'paid'
class NotificationPayoutStatus(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
Unpaid: "NotificationPayoutStatus" = 'unpaid'
Paid: "NotificationPayoutStatus" = 'paid'
12 changes: 6 additions & 6 deletions paddle_billing/Entities/Notifications/NotificationStatus.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from paddle_billing.PaddleStrEnum import PaddleStrEnum
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta


class NotificationStatus(PaddleStrEnum):
NotAttempted = 'not_attempted'
NeedsRetry = 'needs_retry'
Delivered = 'delivered'
Failed = 'failed'
class NotificationStatus(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
NotAttempted: "NotificationStatus" = 'not_attempted'
NeedsRetry: "NotificationStatus" = 'needs_retry'
Delivered: "NotificationStatus" = 'delivered'
Failed: "NotificationStatus" = 'failed'
30 changes: 15 additions & 15 deletions paddle_billing/Entities/Reports/ReportFilterName.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from paddle_billing.PaddleStrEnum import PaddleStrEnum
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta


class ReportFilterName(PaddleStrEnum):
Action = 'action'
CollectionMode = 'collection_mode'
CurrencyCode = 'currency_code'
Origin = 'origin'
PriceStatus = 'price_status'
PriceType = 'price_type'
PriceUpdatedAt = 'price_updated_at'
ProductStatus = 'product_status'
ProductType = 'product_type'
ProductUpdatedAt = 'product_updated_at'
Status = 'status'
Type = 'type'
UpdatedAt = 'updated_at'
class ReportFilterName(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
Action: "ReportFilterName" = 'action'
CollectionMode: "ReportFilterName" = 'collection_mode'
CurrencyCode: "ReportFilterName" = 'currency_code'
Origin: "ReportFilterName" = 'origin'
PriceStatus: "ReportFilterName" = 'price_status'
PriceType: "ReportFilterName" = 'price_type'
PriceUpdatedAt: "ReportFilterName" = 'price_updated_at'
ProductStatus: "ReportFilterName" = 'product_status'
ProductType: "ReportFilterName" = 'product_type'
ProductUpdatedAt: "ReportFilterName" = 'product_updated_at'
Status: "ReportFilterName" = 'status'
Type: "ReportFilterName" = 'type'
UpdatedAt: "ReportFilterName" = 'updated_at'
8 changes: 4 additions & 4 deletions paddle_billing/Entities/Reports/ReportFilterOperator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from paddle_billing.PaddleStrEnum import PaddleStrEnum
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta


class ReportFilterOperator(PaddleStrEnum):
Lt = 'lt'
Gte = 'gte'
class ReportFilterOperator(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
Lt: "ReportFilterOperator" = 'lt'
Gte: "ReportFilterOperator" = 'gte'
12 changes: 6 additions & 6 deletions paddle_billing/Entities/Reports/ReportStatus.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from paddle_billing.PaddleStrEnum import PaddleStrEnum
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta


class ReportStatus(PaddleStrEnum):
Pending = 'pending'
Ready = 'ready'
Failed = 'failed'
Expired = 'expired'
class ReportStatus(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
Pending: "ReportStatus" = 'pending'
Ready: "ReportStatus" = 'ready'
Failed: "ReportStatus" = 'failed'
Expired: "ReportStatus" = 'expired'
16 changes: 8 additions & 8 deletions paddle_billing/Entities/Reports/ReportType.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from paddle_billing.PaddleStrEnum import PaddleStrEnum
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta


class ReportType(PaddleStrEnum):
Adjustments = 'adjustments'
AdjustmentLineItems = 'adjustment_line_items'
Discounts = 'discounts'
ProductsPrices = 'products_prices'
Transactions = 'transactions'
TransactionLineItems = 'transaction_line_items'
class ReportType(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
Adjustments: "ReportType" = 'adjustments'
AdjustmentLineItems: "ReportType" = 'adjustment_line_items'
Discounts: "ReportType" = 'discounts'
ProductsPrices: "ReportType" = 'products_prices'
Transactions: "ReportType" = 'transactions'
TransactionLineItems: "ReportType" = 'transaction_line_items'
16 changes: 8 additions & 8 deletions paddle_billing/Entities/Shared/Action.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from paddle_billing.PaddleStrEnum import PaddleStrEnum
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta


class Action(PaddleStrEnum):
Credit = 'credit'
CreditReverse = 'credit_reverse'
Refund = 'refund'
Chargeback = 'chargeback'
ChargebackReverse = 'chargeback_reverse'
ChargebackWarning = 'chargeback_warning'
class Action(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
Credit: "Action" = 'credit'
CreditReverse: "Action" = 'credit_reverse'
Refund: "Action" = 'refund'
Chargeback: "Action" = 'chargeback'
ChargebackReverse: "Action" = 'chargeback_reverse'
ChargebackWarning: "Action" = 'chargeback_warning'
12 changes: 6 additions & 6 deletions paddle_billing/Entities/Shared/AdjustmentStatus.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from paddle_billing.PaddleStrEnum import PaddleStrEnum
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta


class AdjustmentStatus(PaddleStrEnum):
PendingApproval = 'pending_approval'
Approved = 'approved'
Rejected = 'rejected'
Reversed = 'reversed'
class AdjustmentStatus(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
PendingApproval: "AdjustmentStatus" = 'pending_approval'
Approved: "AdjustmentStatus" = 'approved'
Rejected: "AdjustmentStatus" = 'rejected'
Reversed: "AdjustmentStatus" = 'reversed'
12 changes: 6 additions & 6 deletions paddle_billing/Entities/Shared/AdjustmentType.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from paddle_billing.PaddleStrEnum import PaddleStrEnum
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta


class AdjustmentType(PaddleStrEnum):
Full = 'full'
Partial = 'partial'
Tax = 'tax'
Proration = 'proration'
class AdjustmentType(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
Full: "AdjustmentType" = 'full'
Partial: "AdjustmentType" = 'partial'
Tax: "AdjustmentType" = 'tax'
Proration: "AdjustmentType" = 'proration'
18 changes: 9 additions & 9 deletions paddle_billing/Entities/Shared/AvailablePaymentMethods.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from paddle_billing.PaddleStrEnum import PaddleStrEnum
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta


class AvailablePaymentMethods(PaddleStrEnum):
Alipay = 'alipay'
ApplePay = 'apple_pay'
Bancontact = 'bancontact'
Card = 'card'
GooglePay = 'google_pay'
Ideal = 'ideal'
Paypal = 'paypal'
class AvailablePaymentMethods(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
Alipay: "AvailablePaymentMethods" = 'alipay'
ApplePay: "AvailablePaymentMethods" = 'apple_pay'
Bancontact: "AvailablePaymentMethods" = 'bancontact'
Card: "AvailablePaymentMethods" = 'card'
GooglePay: "AvailablePaymentMethods" = 'google_pay'
Ideal: "AvailablePaymentMethods" = 'ideal'
Paypal: "AvailablePaymentMethods" = 'paypal'
8 changes: 4 additions & 4 deletions paddle_billing/Entities/Shared/CatalogType.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from paddle_billing.PaddleStrEnum import PaddleStrEnum
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta


class CatalogType(PaddleStrEnum):
Standard = 'standard'
Custom = 'custom'
class CatalogType(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
Standard: "CatalogType" = 'standard'
Custom: "CatalogType" = 'custom'
8 changes: 4 additions & 4 deletions paddle_billing/Entities/Shared/CollectionMode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from paddle_billing.PaddleStrEnum import PaddleStrEnum
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta


class CollectionMode(PaddleStrEnum):
Automatic = 'automatic'
Manual = 'manual'
class CollectionMode(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
Automatic: "CollectionMode" = 'automatic'
Manual: "CollectionMode" = 'manual'
Loading
Loading