Skip to content

Commit

Permalink
Merge pull request #676 from recurly/add-revrec-for-gift-cards-and-items
Browse files Browse the repository at this point in the history
Adding RevRec Support for Gift Cards and Items
  • Loading branch information
tilley-kyle authored Feb 16, 2024
2 parents 6460df4 + 62ab220 commit a5d1001
Show file tree
Hide file tree
Showing 7 changed files with 286 additions and 0 deletions.
6 changes: 6 additions & 0 deletions recurly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,9 @@ class GiftCard(Resource):
'updated_at',
'unit_amount_in_cents',
'billing_info',
'liability_gl_account_id',
'revenue_gl_account_id',
'performance_obligation_id'
)
_classes_for_nodename = {'recipient_account': Account,'gifter_account':
Account, 'delivery': Delivery}
Expand Down Expand Up @@ -997,6 +1000,9 @@ class Item(Resource):
'created_at',
'updated_at',
'deleted_at',
'liability_gl_account_id',
'revenue_gl_account_id',
'performance_obligation_id'
)

class Adjustment(Resource):
Expand Down
39 changes: 39 additions & 0 deletions tests/fixtures/gift_cards/get.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
GET https://api.recurly.com/v2/gift_cards/3880289408739841209 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"?>
<gift_card href="https://api.recurly.com/v2/gift_cards/3880289408739841209">
<gifter_account href="https://api.recurly.com/v2/accounts/[email protected]"/>
<purchase_invoice href="https://api.recurly.com/v2/invoices/1125"/>
<id type="integer">3880289408739841209</id>
<redemption_code>ASDR63PM4JUTXW9I</redemption_code>
<product_code>test_gift_card</product_code>
<unit_amount_in_cents type="integer">1000</unit_amount_in_cents>
<currency>USD</currency>
<delivery>
<method>email</method>
<email_address>[email protected]</email_address>
<deliver_at nil="nil"></deliver_at>
<first_name>Sally</first_name>
<last_name>Smith</last_name>
<address nil="nil"></address>
<gifter_name>John</gifter_name>
<personal_message>Congrats!</personal_message>
</delivery>
<created_at type="datetime">2023-08-29T18:42:23Z</created_at>
<updated_at type="datetime">2023-08-29T18:42:23Z</updated_at>
<delivered_at type="datetime">2023-08-29T18:42:23Z</delivered_at>
<redeemed_at nil="nil"></redeemed_at>
<canceled_at nil="nil"></canceled_at>
<a name="redeem" href="https://api.recurly.com/v2/gift_cards/ASDR63PM4JUTXW9I/redeem" method="post"/>
<liability_gl_account_id>t5ejtge1xw0x</liability_gl_account_id>
<revenue_gl_account_id>t5ejtgf1vxh1</revenue_gl_account_id>
<performance_obligation_id>4</performance_obligation_id>
</gift_card>
69 changes: 69 additions & 0 deletions tests/fixtures/gift_cards/list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
GET https://api.recurly.com/v2/gift_cards 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"?>
<gift_cards type="array">
<gift_card href="https://api.recurly.com/v2/gift_cards/3880289408739841209">
<gifter_account href="https://api.recurly.com/v2/accounts/[email protected]"/>
<purchase_invoice href="https://api.recurly.com/v2/invoices/1125"/>
<id type="integer">3880289408739841209</id>
<redemption_code>ASDR63PM4JUTXW9I</redemption_code>
<product_code>test_gift_card</product_code>
<unit_amount_in_cents type="integer">1000</unit_amount_in_cents>
<currency>USD</currency>
<delivery>
<method>email</method>
<email_address>[email protected]</email_address>
<deliver_at nil="nil"></deliver_at>
<first_name>Sally</first_name>
<last_name>Smith</last_name>
<address nil="nil"></address>
<gifter_name>John</gifter_name>
<personal_message>Congrats!</personal_message>
</delivery>
<created_at type="datetime">2023-08-29T18:42:23Z</created_at>
<updated_at type="datetime">2023-08-29T18:42:23Z</updated_at>
<delivered_at type="datetime">2023-08-29T18:42:23Z</delivered_at>
<redeemed_at nil="nil"></redeemed_at>
<canceled_at nil="nil"></canceled_at>
<a name="redeem" href="https://api.recurly.com/v2/gift_cards/ASDR63PM4JUTXW9I/redeem" method="post"/>
<liability_gl_account_id>t5ejtge1xw0x</liability_gl_account_id>
<revenue_gl_account_id>t5ejtgf1vxh1</revenue_gl_account_id>
<performance_obligation_id>4</performance_obligation_id>
</gift_card>
<gift_card href="https://api.recurly.com/v2/gift_cards/3951365864235636055">
<gifter_account href="https://api.recurly.com/v2/accounts/[email protected]"/>
<purchase_invoice href="https://api.recurly.com/v2/invoices/1254"/>
<id type="integer">3951365864235636055</id>
<redemption_code>6HZDUC8S1AGX7WVB</redemption_code>
<product_code>test_gift_card</product_code>
<unit_amount_in_cents type="integer">1000</unit_amount_in_cents>
<currency>USD</currency>
<delivery>
<method>email</method>
<email_address>[email protected]</email_address>
<deliver_at nil="nil"></deliver_at>
<first_name>John</first_name>
<last_name>Smith</last_name>
<address nil="nil"></address>
<gifter_name>Sally</gifter_name>
<personal_message>Hi John, Happy Birthday! I hope you have a great day! Love, Sally</personal_message>
</delivery>
<created_at type="datetime">2023-12-05T20:18:37Z</created_at>
<updated_at type="datetime">2023-12-05T20:18:37Z</updated_at>
<delivered_at type="datetime">2023-12-05T20:18:37Z</delivered_at>
<redeemed_at nil="nil"></redeemed_at>
<canceled_at nil="nil"></canceled_at>
<a name="redeem" href="https://api.recurly.com/v2/gift_cards/6HZDUC8S1AGX7WVB/redeem" method="post"/>
<liability_gl_account_id>t5ejtge1xw0x</liability_gl_account_id>
<revenue_gl_account_id>t5ejtgf1vxh1</revenue_gl_account_id>
<performance_obligation_id>4</performance_obligation_id>
</gift_card>
</gift_cards>
43 changes: 43 additions & 0 deletions tests/fixtures/item/created-with-revrec.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
POST https://api.recurly.com/v2/items HTTP/1.1
X-Api-Version: {api-version}
Accept: application/xml
Authorization: Basic YXBpa2V5Og==
User-Agent: {user-agent}
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<item>
<description>An item of the mocked variety</description>
<item_code>itemmock</item_code>
<liability_gl_account_id>t5ejtge1xw0x</liability_gl_account_id>
<name>Mock Item</name>
<performance_obligation_id>5</performance_obligation_id>
<revenue_gl_account_id>t5ejtgf1vxh1</revenue_gl_account_id>
</item>

HTTP/1.1 201 Created
Content-Type: application/xml; charset=utf-8
Location: https://api.recurly.com/v2/items/itemmock

<?xml version="1.0" encoding="UTF-8"?>
<item href="https://api.recurly.com/v2/items/itemmock">
<item_code>itemmock</item_code>
<name>Mock Item</name>
<external_sku>handcrafted-plastic-soap</external_sku>
<description>An item of the mocked variety</description>
<tax_exempt>true</tax_exempt>
<accounting_code>1569273867</accounting_code>
<revenue_schedule_type>never</revenue_schedule_type>
<custom_fields>
<custom_field>
<name>color</name>
<value>blue</value>
</custom_field>
</custom_fields>
<created_at type="datetime">2019-09-23T21:25:45Z</created_at>
<updated_at type="datetime">2019-09-23T21:25:45Z</updated_at>
<deleted_at nil="nil"/>
<liability_gl_account_id>t5ejtge1xw0x</liability_gl_account_id>
<revenue_gl_account_id>t5ejtgf1vxh1</revenue_gl_account_id>
<performance_obligation_id>5</performance_obligation_id>
</item>
19 changes: 19 additions & 0 deletions tests/fixtures/item/exists-with-revrec.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
GET https://api.recurly.com/v2/items/itemmock 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"?>
<item>
<item_code>itemmock</item_code>
<name>Mock Item</name>
<description>Sleek Plastic</description>
<liability_gl_account_id>t5ejtge1xw0x</liability_gl_account_id>
<revenue_gl_account_id>t5ejtgf1vxh1</revenue_gl_account_id>
<performance_obligation_id>5</performance_obligation_id>
</item>
40 changes: 40 additions & 0 deletions tests/fixtures/item/updated-with-revrec.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
PUT https://api.recurly.com/v2/items/itemmock HTTP/1.1
X-Api-Version: {api-version}
Accept: application/xml
Authorization: Basic YXBpa2V5Og==
User-Agent: {user-agent}
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<item>
<description>A mocked description</description>
<liability_gl_account_id nil="nil"></liability_gl_account_id>
<performance_obligation_id nil="nil"></performance_obligation_id>
<revenue_gl_account_id nil="nil"></revenue_gl_account_id>
</item>

HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<item href="https://api.recurly.com/v2/items/itemmock">
<item_code>itemmock</item_code>
<name>Mock Item</name>
<external_sku>handcrafted-plastic-soap</external_sku>
<description>A mocked description</description>
<tax_exempt>true</tax_exempt>
<accounting_code>1569273867</accounting_code>
<revenue_schedule_type>never</revenue_schedule_type>
<custom_fields>
<custom_field>
<name>color</name>
<value>blue</value>
</custom_field>
</custom_fields>
<created_at type="datetime">2019-09-23T21:25:45Z</created_at>
<updated_at type="datetime">2019-09-23T21:25:45Z</updated_at>
<deleted_at nil="nil"/>
<liability_gl_account_id nil="nil"></liability_gl_account_id>
<revenue_gl_account_id nil="nil"></revenue_gl_account_id>
<performance_obligation_id>6</performance_obligation_id>
</item>
70 changes: 70 additions & 0 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,49 @@ def test_item(self):
with self.mock_request('item/deleted.xml'):
item.delete()

def test_item_with_revrec(self):
item_code = 'item%s' % self.test_id
with self.mock_request('item/does-not-exist.xml'):
self.assertRaises(NotFoundError, Item.get, item_code)

item = Item(
item_code=item_code,
name='Mock Item',
description='An item of the mocked variety',
liability_gl_account_id='t5ejtge1xw0x',
revenue_gl_account_id='t5ejtgf1vxh1',
performance_obligation_id='5'
)

with self.mock_request('item/created-with-revrec.xml'):
item.save()

self.assertEqual(item.item_code, item_code)
self.assertEqual(item.liability_gl_account_id, 't5ejtge1xw0x')
self.assertEqual(item.revenue_gl_account_id, 't5ejtgf1vxh1')
self.assertEqual(item.performance_obligation_id, '5')

with self.mock_request('item/exists-with-revrec.xml'):
same_item = Item.get(item_code)

self.assertEqual(same_item.item_code, item_code)
self.assertEqual(same_item.liability_gl_account_id, 't5ejtge1xw0x')
self.assertEqual(same_item.revenue_gl_account_id, 't5ejtgf1vxh1')
self.assertEqual(same_item.performance_obligation_id, '5')

item.description = 'A mocked description'
item.liability_gl_account_id = None
item.revenue_gl_account_id = None
item.performance_obligation_id = None

with self.mock_request('item/updated-with-revrec.xml'):
item.save()

self.assertEqual(item.description, 'A mocked description')
self.assertEqual(item.liability_gl_account_id, None)
self.assertEqual(item.revenue_gl_account_id, None)
self.assertEqual(item.performance_obligation_id, '6')

def test_custom_field_definition(self):
"""Test custom field definitions list"""
with self.mock_request('custom_field_definitions/list.xml'):
Expand Down Expand Up @@ -2901,6 +2944,33 @@ def _build_gift_card(self):
gift_card.gifter_account = account
return gift_card

def test_get_gift_card(self):
with self.mock_request('gift_cards/get.xml'):
gift_card = GiftCard.get(3880289408739841209)

self.assertEqual(gift_card.id, 3880289408739841209)
self.assertEqual(gift_card.redemption_code, 'ASDR63PM4JUTXW9I')
self.assertEqual(gift_card.product_code, 'test_gift_card')
self.assertEqual(gift_card.unit_amount_in_cents, 1000)
self.assertEqual(gift_card.currency, 'USD')
self.assertEqual(gift_card.delivery.method, 'email')
self.assertEqual(gift_card.delivery.email_address, '[email protected]')
self.assertEqual(gift_card.delivery.first_name, 'Sally')
self.assertEqual(gift_card.delivery.last_name, 'Smith')
self.assertEqual(gift_card.delivery.gifter_name, 'John')
self.assertEqual(gift_card.delivery.personal_message, 'Congrats!')
self.assertEqual(gift_card.liability_gl_account_id, 't5ejtge1xw0x')
self.assertEqual(gift_card.revenue_gl_account_id, 't5ejtgf1vxh1')
self.assertEqual(gift_card.performance_obligation_id, '4')

def test_list_gift_cards(self):
with self.mock_request('gift_cards/list.xml'):
gift_cards = GiftCard.all()

self.assertEqual(len(gift_cards), 2)
self.assertIsInstance(gift_cards[0], GiftCard)
self.assertIsInstance(gift_cards[1], GiftCard)

def test_gift_cards_purchase(self):
gift_card = self._build_gift_card()

Expand Down

0 comments on commit a5d1001

Please sign in to comment.