Skip to content

Commit

Permalink
feat: Replace AvailablePaymentMethods with PaymentMethodType
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgrayston-paddle committed Sep 24, 2024
1 parent 7bf4baa commit 75b207e
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 36 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Check our main [developer changelog](https://developer.paddle.com/?utm_source=dx
- `PreviewPrice` operation no longer allows empty `items`
- `CustomersClient.credit_balances` can now be filtered by `currency_code`

### Removed

- `AvailablePaymentMethods` - replaced by `PaymentMethodType`

## 0.2.2 - 2024-09-03

### Fixed
Expand Down
8 changes: 8 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All breaking changes prior to v1 will be documented in this file to assist with upgrading.

## v0.3.0

1. `paddle_billing.Entities.Shared.AvailablePaymentMethods` has been replaced by `paddle_billing.Entities.Shared.PaymentMethodType`.

`Transaction` `available_payment_methods` will now return a list of `PaymentMethodType`.

All usage of `AvailablePaymentMethods` will need to be replaced with `PaymentMethodType`.

## v0.2.0

This release includes a few breaking changes. These changes should be limited impact on most integrations but may cause problems in some circumstances.
Expand Down
6 changes: 3 additions & 3 deletions paddle_billing/Entities/PricePreview.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from dataclasses import dataclass

from paddle_billing.Entities.Entity import Entity
from paddle_billing.Entities.Shared import AddressPreview, AvailablePaymentMethods, CurrencyCode
from paddle_billing.Entities.Shared import AddressPreview, CurrencyCode, PaymentMethodType
from paddle_billing.Entities.PricingPreviews import PricePreviewDetails


Expand All @@ -16,7 +16,7 @@ class PricePreview(Entity):
address: AddressPreview | None
customer_ip_address: str | None
details: PricePreviewDetails
available_payment_methods: list[AvailablePaymentMethods]
available_payment_methods: list[PaymentMethodType]


@staticmethod
Expand All @@ -30,5 +30,5 @@ def from_dict(data: dict) -> PricePreview:
address = AddressPreview.from_dict(data['address']) if data.get('address') else None,
customer_ip_address = data.get('customer_ip_address'),
details = PricePreviewDetails.from_dict(data['details']),
available_payment_methods = [AvailablePaymentMethods(item) for item in data['available_payment_methods']],
available_payment_methods = [PaymentMethodType(item) for item in data['available_payment_methods']],
)
11 changes: 0 additions & 11 deletions paddle_billing/Entities/Shared/AvailablePaymentMethods.py

This file was deleted.

1 change: 0 additions & 1 deletion paddle_billing/Entities/Shared/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from paddle_billing.Entities.Shared.AdjustmentTimePeriod import AdjustmentTimePeriod
from paddle_billing.Entities.Shared.AdjustmentTotals import AdjustmentTotals
from paddle_billing.Entities.Shared.AdjustmentType import AdjustmentType
from paddle_billing.Entities.Shared.AvailablePaymentMethods import AvailablePaymentMethods
from paddle_billing.Entities.Shared.BillingDetails import BillingDetails
from paddle_billing.Entities.Shared.BillingDetailsUpdate import BillingDetailsUpdate
from paddle_billing.Entities.Shared.Card import Card
Expand Down
6 changes: 3 additions & 3 deletions paddle_billing/Entities/Transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
from paddle_billing.Entities.Discount import Discount

from paddle_billing.Entities.Shared import (
AvailablePaymentMethods,
BillingDetails,
Checkout,
CollectionMode,
CurrencyCode,
CustomData,
PaymentMethodType,
TransactionOrigin,
TransactionPaymentAttempt,
TransactionStatus,
Expand Down Expand Up @@ -57,7 +57,7 @@ class Transaction(Entity):
business: Business | None = None
customer: Customer | None = None
discount: Discount | None = None
available_payment_methods: list[AvailablePaymentMethods] | None = None
available_payment_methods: list[PaymentMethodType] | None = None
receipt_data: str | None = None


Expand Down Expand Up @@ -93,6 +93,6 @@ def from_dict(data: dict) -> Transaction:
customer = Customer.from_dict(data['customer']) if data.get('customer') else None,
discount = Discount.from_dict(data['discount']) if data.get('discount') else None,

available_payment_methods = [AvailablePaymentMethods(item) for item in data.get('available_payment_methods', [])],
available_payment_methods = [PaymentMethodType(item) for item in data.get('available_payment_methods', [])],
adjustment_totals = TransactionAdjustmentsTotals.from_dict(data['adjustment_totals']) if data.get('adjustment_totals') else None,
)
6 changes: 3 additions & 3 deletions paddle_billing/Entities/TransactionPreview.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from dataclasses import dataclass

from paddle_billing.Entities.Entity import Entity
from paddle_billing.Entities.Shared import AddressPreview, AvailablePaymentMethods, CurrencyCode
from paddle_billing.Entities.Shared import AddressPreview, CurrencyCode, PaymentMethodType

from paddle_billing.Entities.Shared.TransactionDetailsPreview import TransactionDetailsPreview
from paddle_billing.Entities.Transactions.TransactionItemPreviewWithPrice import TransactionItemPreviewWithPrice
Expand All @@ -20,7 +20,7 @@ class TransactionPreview(Entity):
ignore_trials: bool
items: list[TransactionItemPreviewWithPrice]
details: TransactionDetailsPreview
available_payment_methods: list[AvailablePaymentMethods]
available_payment_methods: list[PaymentMethodType]


@staticmethod
Expand All @@ -35,6 +35,6 @@ def from_dict(data: dict) -> TransactionPreview:
ignore_trials = data['ignore_trials'],
details = TransactionDetailsPreview.from_dict(data['details']),
items = [TransactionItemPreviewWithPrice.from_dict(item) for item in data['items']],
available_payment_methods = [AvailablePaymentMethods(method) for method in data['available_payment_methods']],
available_payment_methods = [PaymentMethodType(method) for method in data['available_payment_methods']],
address = AddressPreview.from_dict(data['address']) if data.get('address') else None,
)

This file was deleted.

1 change: 0 additions & 1 deletion paddle_billing/Notifications/Entities/Shared/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from paddle_billing.Notifications.Entities.Shared.AdjustmentTimePeriod import AdjustmentTimePeriod
from paddle_billing.Notifications.Entities.Shared.AdjustmentTotals import AdjustmentTotals
from paddle_billing.Notifications.Entities.Shared.AdjustmentType import AdjustmentType
from paddle_billing.Notifications.Entities.Shared.AvailablePaymentMethods import AvailablePaymentMethods
from paddle_billing.Notifications.Entities.Shared.BillingDetails import BillingDetails
from paddle_billing.Notifications.Entities.Shared.Card import Card
from paddle_billing.Notifications.Entities.Shared.CatalogType import CatalogType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from paddle_billing.Entities.Notification import Notification
from paddle_billing.Entities.Notifications import NotificationStatus

from paddle_billing.Notifications.Entities.Adjustment import Adjustment
from paddle_billing.Notifications.Entities.Adjustment import Adjustment

from paddle_billing.Notifications.Entities.Adjustments.AdjustmentTaxRatesUsed import AdjustmentTaxRatesUsed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,19 @@
"custom_data": {
"key": "value"
}
}
},
"available_payment_methods": [
"alipay",
"apple_pay",
"bancontact",
"card",
"google_pay",
"ideal",
"offline",
"paypal",
"unknown",
"wire_transfer"
]
},
"meta": {
"request_id": "e4747324-738b-4707-ac7a-7eaabb7c7a26"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
CustomData,
TaxMode,
Money,
PaymentMethodType,
PriceQuantity,
CustomData,
TimePeriod,
Expand Down Expand Up @@ -617,6 +618,34 @@ def test_get_payment_method_change_transaction_returns_transaction_with_discount
assert discount.custom_data.data.get('key') == 'value'


def test_get_payment_method_change_transaction_returns_transaction_with_available_payment_methods(
self,
test_client,
mock_requests,
):
mock_requests.get(
f"{test_client.base_url}/subscriptions/sub_01h7zcgmdc6tmwtjehp3sh7azf/update-payment-method-transaction",
status_code=200,
text=ReadsFixtures.read_raw_json_fixture('response/get_payment_method_change_transaction_entity'),
)

response = test_client.client.subscriptions.get_payment_method_change_transaction('sub_01h7zcgmdc6tmwtjehp3sh7azf')

assert isinstance(response, Transaction)

available_payment_methods = response.available_payment_methods
assert available_payment_methods[0] == PaymentMethodType.Alipay
assert available_payment_methods[1] == PaymentMethodType.ApplePay
assert available_payment_methods[2] == PaymentMethodType.Bancontact
assert available_payment_methods[3] == PaymentMethodType.Card
assert available_payment_methods[4] == PaymentMethodType.GooglePay
assert available_payment_methods[5] == PaymentMethodType.Ideal
assert available_payment_methods[6] == PaymentMethodType.Offline
assert available_payment_methods[7] == PaymentMethodType.Paypal
assert available_payment_methods[8] == PaymentMethodType.Unknown
assert available_payment_methods[9] == PaymentMethodType.WireTransfer


@mark.parametrize(
'subscription_id, expected_response_status, expected_response_body, expected_url',
[(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,19 @@
"custom_data": {
"key": "value"
}
}
},
"available_payment_methods": [
"alipay",
"apple_pay",
"bancontact",
"card",
"google_pay",
"ideal",
"offline",
"paypal",
"unknown",
"wire_transfer"
]
},
"meta": {
"request_id": "0daa7c59-f2eb-41b6-bf2e-bb3b070873a5"
Expand Down
29 changes: 29 additions & 0 deletions tests/Functional/Resources/Transactions/test_TransactionsClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
CustomData,
Interval,
Money,
PaymentMethodType,
PriceQuantity,
TransactionStatus,
TaxMode,
Expand Down Expand Up @@ -530,6 +531,34 @@ def test_get_transaction_returns_transaction_with_discount(
assert discount.custom_data.data.get('key') == 'value'


def test_get_transaction_returns_transaction_with_available_payment_methods(
self,
test_client,
mock_requests,
):
mock_requests.get(
f"{test_client.base_url}/transactions/txn_01hen7bxc1p8ep4yk7n5jbzk9r",
status_code=200,
text=ReadsFixtures.read_raw_json_fixture('response/full_entity'),
)

response = test_client.client.transactions.get('txn_01hen7bxc1p8ep4yk7n5jbzk9r')

assert isinstance(response, Transaction)

available_payment_methods = response.available_payment_methods
assert available_payment_methods[0] == PaymentMethodType.Alipay
assert available_payment_methods[1] == PaymentMethodType.ApplePay
assert available_payment_methods[2] == PaymentMethodType.Bancontact
assert available_payment_methods[3] == PaymentMethodType.Card
assert available_payment_methods[4] == PaymentMethodType.GooglePay
assert available_payment_methods[5] == PaymentMethodType.Ideal
assert available_payment_methods[6] == PaymentMethodType.Offline
assert available_payment_methods[7] == PaymentMethodType.Paypal
assert available_payment_methods[8] == PaymentMethodType.Unknown
assert available_payment_methods[9] == PaymentMethodType.WireTransfer


@mark.parametrize(
'operation, expected_request_body, expected_response_status, expected_response_body, expected_url',
[
Expand Down

0 comments on commit 75b207e

Please sign in to comment.