Skip to content

Commit

Permalink
- Only use payment method object type to determine payment method type
Browse files Browse the repository at this point in the history
  • Loading branch information
nwithan8 committed Apr 10, 2024
1 parent 38631fe commit 77225d1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
4 changes: 2 additions & 2 deletions easypost/services/billing_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ def _get_payment_method_info(self, priority: str = "primary") -> List[str]:
if payment_method_to_use and payment_methods[payment_method_to_use]:
payment_method_id = payment_methods[payment_method_to_use]["id"]
payment_method_object_type = payment_methods[payment_method_to_use].get("object", None)
if payment_method_id.startswith("card_") or payment_method_object_type == "CreditCard":
if payment_method_object_type == "CreditCard":
endpoint = "/credit_cards"
elif payment_method_id.startswith("bank_") or payment_method_object_type == "BankAccount":
elif payment_method_object_type == "BankAccount":
endpoint = "/bank_accounts"
else:
raise InvalidObjectError(message=INVALID_PAYMENT_METHOD_ERROR)
Expand Down
20 changes: 0 additions & 20 deletions tests/test_billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,3 @@ def test_billing__get_payment_method_info_by_object_type(mock_request, prod_clie

assert endpoint == "/bank_accounts"
assert payment_method_id == "pm_456"


@patch(
"easypost.services.billing_service.BillingService.retrieve_payment_methods",
return_value={
"primary_payment_method": {"id": "card_123", "object": None},
"secondary_payment_method": {"id": "bank_123", "object": None},
},
)
def test_billing__get_payment_method_info_by_legacy_id_prefix(mock_request, prod_client):
"""Tests we can determine the payment method type/endpoint by legacy ID prefix."""
endpoint, payment_method_id = prod_client.billing._get_payment_method_info(priority="primary")

assert endpoint == "/credit_cards"
assert payment_method_id == "card_123"

endpoint, payment_method_id = prod_client.billing._get_payment_method_info(priority="secondary")

assert endpoint == "/bank_accounts"
assert payment_method_id == "bank_123"

0 comments on commit 77225d1

Please sign in to comment.