Skip to content

Commit

Permalink
add external payment phases
Browse files Browse the repository at this point in the history
  • Loading branch information
amandamfielding committed Nov 20, 2023
1 parent 3620376 commit 2d74f39
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 6 deletions.
36 changes: 34 additions & 2 deletions recurly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -2133,7 +2133,7 @@ class ExternalAccount(Resource):

nodename = 'external_account'
member_path = 'external_accounts/%s'

attributes = (
'id',
'external_account_code',
Expand All @@ -2154,6 +2154,7 @@ class ExternalInvoice(Resource):
attributes = (
'account',
'external_subscription',
'external_payment_phase',
'external_id',
'state',
'total',
Expand Down Expand Up @@ -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',
Expand All @@ -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. """
Expand All @@ -2223,6 +2232,29 @@ 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'

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. """
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/external-invoice/get.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Content-Type: application/xml; charset=utf-8
<external_invoice href="https://api.recurly.com/v2/external_invoices/sd28t3zdm59r">
<account href="https://api.recurly.com/v2/accounts/1"/>
<external_subscription href="https://api.recurly.com/v2/external_subscriptions/1"/>
<external_payment_phase href="https://pcc.recurly.dev:3000/v2/external_payment_phases/sdam2lfeop3e"/>
<external_id>external-id</external_id>
<state>paid</state>
<currency>USD</currency>
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/external-invoice/list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Content-Type: application/xml; charset=utf-8
<external_invoice href="https://api.recurly.com/v2/external_invoices/sd28t3zdm59r">
<account href="https://api.recurly.com/v2/accounts/1"/>
<external_subscription href="https://api.recurly.com/v2/external_subscriptions/1"/>
<external_payment_phase href="https://pcc.recurly.dev:3000/v2/external_payment_phases/sdam2lfeop3e"/>
<external_id>external-id</external_id>
<state>paid</state>
<currency>USD</currency>
Expand Down
26 changes: 26 additions & 0 deletions tests/fixtures/external-payment-phases/get.xml
Original file line number Diff line number Diff line change
@@ -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

<?xml version="1.0" encoding="UTF-8"?>
<external_payment_phase href="https://pcc.recurly.dev:3000/v2/external_subscriptions/sd28t3zdm59r/external_payment_phases/sk0bmpw0wbby">
<id>sk0bmpw0wbby</id>
<started_at type="datetime">2023-03-14T19:55:07Z</started_at>
<ends_at type="datetime">2023-04-14T19:55:07Z</ends_at>
<starting_billing_period_index>1</starting_billing_period_index>
<ending_billing_period_index>4</ending_billing_period_index>
<offer_type></offer_type>
<offer_name></offer_name>
<period_count>1</period_count>
<period_length>2 MONTHS</period_length>
<amount>0.00</amount>
<currency>USD</currency>
<created_at type="datetime">2023-03-14T19:55:07Z</created_at>
<updated_at type="datetime">2023-04-14T19:55:07Z</updated_at>
</external_payment_phase>
2 changes: 2 additions & 0 deletions tests/fixtures/external-subscription/external-invoices.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Content-Type: application/xml; charset=utf-8
<external_invoice href="https://api.recurly.com/v2/external_invoices/sd28t3zdm59r">
<account href="https://api.recurly.com/v2/accounts/1"/>
<external_subscription href="https://api.recurly.com/v2/external_subscriptions/1"/>
<external_payment_phase href="https://pcc.recurly.dev:3000/v2/external_payment_phases/sdam2lfeop3e"/>
<external_id>external-id</external_id>
<state>paid</state>
<currency>USD</currency>
Expand Down Expand Up @@ -43,6 +44,7 @@ Content-Type: application/xml; charset=utf-8
<external_invoice href="https://api.recurly.com/v2/external_invoices/sd28t3zdm59p">
<account href="https://api.recurly.com/v2/accounts/2"/>
<external_subscription href="https://api.recurly.com/v2/external_subscriptions/1"/>
<external_payment_phase href="https://pcc.recurly.dev:3000/v2/external_payment_phases/sdam2lfeop3e"/>
<external_id>external-id2</external_id>
<state>paid</state>
<currency>USD</currency>
Expand Down
28 changes: 28 additions & 0 deletions tests/fixtures/external-subscription/external-payment-phases.xml
Original file line number Diff line number Diff line change
@@ -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

<?xml version="1.0" encoding="UTF-8"?>
<external_payment_phases type="array">
<external_payment_phase href="https://pcc.recurly.dev:3000/v2/external_payment_phases/sk0bmpw0wbby">
<id>sk0bmpw0wbby</id>
<started_at type="datetime">2023-03-14T19:55:07Z</started_at>
<ends_at type="datetime">2023-04-14T19:55:07Z</ends_at>
<starting_billing_period_index>1</starting_billing_period_index>
<ending_billing_period_index>4</ending_billing_period_index>
<offer_type></offer_type>
<offer_name></offer_name>
<period_count>1</period_count>
<period_length>2 MONTHS</period_length>
<amount>0.00</amount>
<currency>USD</currency>
<created_at type="datetime">2023-03-14T19:55:07Z</created_at>
<updated_at type="datetime">2023-04-14T19:55:07Z</updated_at>
</external_payment_phase>
</external_payment_phases>
1 change: 1 addition & 0 deletions tests/fixtures/external-subscription/get.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Content-Type: application/xml; charset=utf-8
<external_subscription href="https://api.recurly.com/v2/external_subscriptions/sd28t3zdm59r">
<account href="https://api.recurly.com/v2/accounts/pphino"/>
<external_invoices href="https://api.recurly.com/v2/external_subscriptions/sd28t3zdm59r/external_invoices"/>
<external_payment_phases href="https://api.recurly.com/v2/external_subscriptions/sd28t3zdm59r/external_payment_phases"/>
<external_id>abcd1234</external_id>
<external_product_reference nil="nil"></external_product_reference>
<last_purchased nil="nil"></last_purchased>
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/external-subscription/list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Content-Type: application/xml; charset=utf-8
<external_subscriptions type="array">
<external_subscription href="https://paulo.recurly.dev:3000/v2/external_subscriptions/ru8jbrg7i3c0">
<account href="https://paulo.recurly.dev:3000/v2/accounts/pphino"/>
<external_invoices href="https://api.recurly.com/v2/external_subscriptions/ru8jbrg7i3c0/external_invoices"/>
<external_payment_phases href="https://api.recurly.com/v2/external_subscriptions/ru8jbrg7i3c0/external_payment_phases"/>
<external_id>abcd1234</external_id>
<external_product_reference nil="nil"></external_product_reference>
<last_purchased nil="nil"></last_purchased>
Expand All @@ -30,6 +32,8 @@ Content-Type: application/xml; charset=utf-8
</external_subscription>
<external_subscription href="https://paulo.recurly.dev:3000/v2/external_subscriptions/ru2208s6hmf0">
<account href="https://paulo.recurly.dev:3000/v2/accounts/pphino"/>
<external_invoices href="https://api.recurly.com/v2/external_subscriptions/ru2208s6hmf0/external_invoices"/>
<external_payment_phases href="https://api.recurly.com/v2/external_subscriptions/ru2208s6hmf0/external_payment_phases"/>
<external_id>efgh5678</external_id>
<external_product_reference nil="nil"></external_product_reference>
<last_purchased nil="nil"></last_purchased>
Expand Down
39 changes: 35 additions & 4 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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'):
Expand Down

0 comments on commit 2d74f39

Please sign in to comment.