From f13901c93b84df6f457e8cf425e5562a16ce95b6 Mon Sep 17 00:00:00 2001 From: Amanda Fielding Date: Mon, 20 Nov 2023 13:51:36 -0800 Subject: [PATCH] add external payment phases --- recurly/__init__.py | 37 +++++++++++++++++- tests/fixtures/external-invoice/get.xml | 1 + tests/fixtures/external-invoice/list.xml | 1 + .../fixtures/external-payment-phases/get.xml | 26 +++++++++++++ .../external-invoices.xml | 2 + .../external-payment-phases.xml | 28 +++++++++++++ tests/fixtures/external-subscription/get.xml | 1 + tests/fixtures/external-subscription/list.xml | 4 ++ tests/test_resources.py | 39 +++++++++++++++++-- 9 files changed, 133 insertions(+), 6 deletions(-) create mode 100644 tests/fixtures/external-payment-phases/get.xml create mode 100644 tests/fixtures/external-subscription/external-payment-phases.xml diff --git a/recurly/__init__.py b/recurly/__init__.py index bca4103a..92a3336b 100644 --- a/recurly/__init__.py +++ b/recurly/__init__.py @@ -588,7 +588,7 @@ def verify(self, account_code, gateway_code = None): def verify_cvv(self, account_code, verification_value = None): recurly.Account.get(account_code).verify_cvv(verification_value) - + class ShippingAddress(Resource): """Shipping Address information""" @@ -2133,7 +2133,7 @@ class ExternalAccount(Resource): nodename = 'external_account' member_path = 'external_accounts/%s' - + attributes = ( 'id', 'external_account_code', @@ -2154,6 +2154,7 @@ class ExternalInvoice(Resource): attributes = ( 'account', 'external_subscription', + 'external_payment_phase', 'external_id', 'state', 'total', @@ -2196,6 +2197,8 @@ class ExternalSubscription(Resource): 'account', 'external_id', 'external_product_reference', + 'external_invoices', + 'external_payment_phases', 'last_purchased', 'auto_renew', 'in_grace_period', @@ -2211,6 +2214,12 @@ class ExternalSubscription(Resource): 'updated_at' ) + def get_external_payment_phase(self, external_payment_phase_uuid): + """Fetch an external payment phase from an external subscription.""" + url = urljoin(self._url, '/external_payment_phases/{}'.format(external_payment_phase_uuid)) + resp, elem = ExternalPaymentPhase().element_for_url(url) + return ExternalPaymentPhase().from_element(elem) + class ExternalProductReference(Resource): """ A reference of a product from an external resource that is not managed by the Recurly platform and instead is managed by third-party platforms like Apple Store and Google Play. """ @@ -2223,6 +2232,30 @@ class ExternalProductReference(Resource): 'external_connection_type' ) +class ExternalPaymentPhase(Resource): + + """ Payment details in the lifecycle of a subscription that is not managed by the Recurly platform and instead is managed by third-party platforms like Apple Store and Google Play. """ + + nodename = 'external_payment_phase' + collection_path = 'external_payment_phases' + member_path = 'external_payment_phases/%s' + + attributes = ( + 'id', + 'started_at', + 'ends_at', + 'starting_billing_period_index', + 'ending_billing_period_index', + 'offer_type', + 'offer_name', + 'period_count', + 'period_length', + 'amount', + 'currency', + 'created_at', + 'updated_at' + ) + class ExternalProduct(Resource): """ A product from an external resource that is not managed by the Recurly platform and instead is managed by third-party platforms like Apple Store and Google Play. """ diff --git a/tests/fixtures/external-invoice/get.xml b/tests/fixtures/external-invoice/get.xml index 93716110..fa8d4c9e 100644 --- a/tests/fixtures/external-invoice/get.xml +++ b/tests/fixtures/external-invoice/get.xml @@ -12,6 +12,7 @@ Content-Type: application/xml; charset=utf-8 + external-id paid USD diff --git a/tests/fixtures/external-invoice/list.xml b/tests/fixtures/external-invoice/list.xml index 2ffc7c00..0fd809aa 100644 --- a/tests/fixtures/external-invoice/list.xml +++ b/tests/fixtures/external-invoice/list.xml @@ -13,6 +13,7 @@ Content-Type: application/xml; charset=utf-8 + external-id paid USD diff --git a/tests/fixtures/external-payment-phases/get.xml b/tests/fixtures/external-payment-phases/get.xml new file mode 100644 index 00000000..7ebea15e --- /dev/null +++ b/tests/fixtures/external-payment-phases/get.xml @@ -0,0 +1,26 @@ +GET https://api.recurly.com/v2/external_subscriptions/sd28t3zdm59r/external_payment_phases/sk0bmpw0wbby HTTP/1.1 +X-Api-Version: {api-version} +Accept: application/xml +Authorization: Basic YXBpa2V5Og== +User-Agent: {user-agent} + + +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + sk0bmpw0wbby + 2023-03-14T19:55:07Z + 2023-04-14T19:55:07Z + 1 + 4 + + + 1 + 2 MONTHS + 0.00 + USD + 2023-03-14T19:55:07Z + 2023-04-14T19:55:07Z + diff --git a/tests/fixtures/external-subscription/external-invoices.xml b/tests/fixtures/external-subscription/external-invoices.xml index 33bc28c1..6d13ceb7 100644 --- a/tests/fixtures/external-subscription/external-invoices.xml +++ b/tests/fixtures/external-subscription/external-invoices.xml @@ -13,6 +13,7 @@ Content-Type: application/xml; charset=utf-8 + external-id paid USD @@ -43,6 +44,7 @@ Content-Type: application/xml; charset=utf-8 + external-id2 paid USD diff --git a/tests/fixtures/external-subscription/external-payment-phases.xml b/tests/fixtures/external-subscription/external-payment-phases.xml new file mode 100644 index 00000000..9eba4c26 --- /dev/null +++ b/tests/fixtures/external-subscription/external-payment-phases.xml @@ -0,0 +1,28 @@ +GET https://api.recurly.com/v2/external_subscriptions/sd28t3zdm59r/external_payment_phases HTTP/1.1 +X-Api-Version: {api-version} +Accept: application/xml +Authorization: Basic YXBpa2V5Og== +User-Agent: {user-agent} + + +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + + sk0bmpw0wbby + 2023-03-14T19:55:07Z + 2023-04-14T19:55:07Z + 1 + 4 + + + 1 + 2 MONTHS + 0.00 + USD + 2023-03-14T19:55:07Z + 2023-04-14T19:55:07Z + + diff --git a/tests/fixtures/external-subscription/get.xml b/tests/fixtures/external-subscription/get.xml index 32d5f2b3..476a7f99 100644 --- a/tests/fixtures/external-subscription/get.xml +++ b/tests/fixtures/external-subscription/get.xml @@ -12,6 +12,7 @@ Content-Type: application/xml; charset=utf-8 + abcd1234 diff --git a/tests/fixtures/external-subscription/list.xml b/tests/fixtures/external-subscription/list.xml index 215cf1f4..cbe5c7a9 100644 --- a/tests/fixtures/external-subscription/list.xml +++ b/tests/fixtures/external-subscription/list.xml @@ -12,6 +12,8 @@ Content-Type: application/xml; charset=utf-8 + + abcd1234 @@ -30,6 +32,8 @@ Content-Type: application/xml; charset=utf-8 + + efgh5678 diff --git a/tests/test_resources.py b/tests/test_resources.py index 48da23e4..b2cfaa00 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -10,7 +10,7 @@ SubscriptionAddOn, Transaction, MeasuredUnit, Usage, GiftCard, Delivery, ShippingAddress, AccountAcquisition, \ Purchase, Invoice, InvoiceCollection, CreditPayment, CustomField, ExportDate, ExportDateFile, DunningCampaign, \ DunningCycle, InvoiceTemplate, PlanRampInterval, SubRampInterval, ExternalSubscription, ExternalProduct, \ - ExternalProductReference, CustomFieldDefinition, ExternalInvoice, ExternalCharge, ExternalAccount, \ + ExternalProductReference, ExternalPaymentPhase, CustomFieldDefinition, ExternalInvoice, ExternalCharge, ExternalAccount, \ GatewayAttributes, BusinessEntity from recurly import Money, NotFoundError, ValidationError, BadRequestError, PageError from recurly import recurly_logging as logging @@ -3195,7 +3195,7 @@ def test_get_external_product(self): self.assertEqual(second_external_product_reference.created_at, datetime(2022, 11, 3, 21, 12, 35, tzinfo=second_external_product_reference.created_at.tzinfo)) self.assertEqual(second_external_product_reference.updated_at, datetime(2022, 11, 3, 21, 12, 35, tzinfo=second_external_product_reference.updated_at.tzinfo)) - + def test_get_business_entity(self): with self.mock_request('business_entity/get.xml'): entity = BusinessEntity.get('sy8yqpgxmeqc') @@ -3237,7 +3237,7 @@ def test_business_entity_for_account(self): with self.mock_request('business_entity/get.xml'): entity = account.business_entity() - + self.assertIsInstance(entity, BusinessEntity) def test_business_entity_for_invoice(self): @@ -3246,7 +3246,7 @@ def test_business_entity_for_invoice(self): with self.mock_request('business_entity/get.xml'): entity = invoice.business_entity() - + self.assertIsInstance(entity, BusinessEntity) def test_update_external_product(self): @@ -3294,6 +3294,37 @@ def test_delete_external_product_reference(self): with self.mock_request('external-product-references/deleted.xml'): external_product_reference.delete() + def test_list_external_payment_phases_on_external_subscription(self): + with self.mock_request('external-subscription/get.xml'): + external_subscription = ExternalSubscription.get('sd28t3zdm59r') + + with self.mock_request('external-subscription/external-payment-phases.xml'): + external_payment_phases = external_subscription.external_payment_phases() + + self.assertEqual(len(external_payment_phases), 1) + + self.assertEqual(external_payment_phases[0].id, 'sk0bmpw0wbby') + self.assertEqual(external_payment_phases[0].starting_billing_period_index, '1') + self.assertEqual(external_payment_phases[0].ending_billing_period_index, '4') + self.assertEqual(external_payment_phases[0].currency, 'USD') + self.assertEqual(external_payment_phases[0].amount, '0.00') + self.assertEqual(external_payment_phases[0].created_at, datetime(2023, 3, 14, 19, 55, 7, tzinfo=external_payment_phases[0].created_at.tzinfo)) + self.assertEqual(external_payment_phases[0].updated_at, datetime(2023, 4, 14, 19, 55, 7, tzinfo=external_payment_phases[0].updated_at.tzinfo)) + + def test_get_external_payment_phase(self): + with self.mock_request('external-subscription/get.xml'): + external_subscription = ExternalSubscription.get('sd28t3zdm59r') + with self.mock_request('external-payment-phases/get.xml'): + external_payment_phase = external_subscription.get_external_payment_phase('sk0bmpw0wbby') + + self.assertEqual(external_payment_phase.id, "sk0bmpw0wbby") + self.assertEqual(external_payment_phase.starting_billing_period_index, '1') + self.assertEqual(external_payment_phase.ending_billing_period_index, '4') + self.assertEqual(external_payment_phase.currency, 'USD') + self.assertEqual(external_payment_phase.amount,'0.00') + self.assertEqual(external_payment_phase.created_at, datetime(2023, 3, 14, 19, 55, 7, tzinfo=external_payment_phase.created_at.tzinfo)) + self.assertEqual(external_payment_phase.updated_at, datetime(2023, 4, 14, 19, 55, 7, tzinfo=external_payment_phase.updated_at.tzinfo)) + def test_list_external_accounts(self): account_code = 'testmock' with self.mock_request('account/exists.xml'):