Skip to content

Commit

Permalink
add-revrec-for-add-ons
Browse files Browse the repository at this point in the history
  • Loading branch information
8eth committed Feb 21, 2024
1 parent a5d1001 commit 264b577
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 1 deletion.
5 changes: 4 additions & 1 deletion recurly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2132,7 +2132,10 @@ class AddOn(Resource):
'updated_at',
'tier_type',
'tiers',
'percentage_tiers'
'percentage_tiers',
'liability_gl_account_id',
'revenue_gl_account_id',
'performance_obligation_id'
)

_classes_for_nodename = {
Expand Down
45 changes: 45 additions & 0 deletions tests/fixtures/add-on/created-with-revrec.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
POST https://api.recurly.com/v2/plans/planmock/add_ons 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"?>
<add_on>
<add_on_code>addonrevrec</add_on_code>
<liability_gl_account_id>t5ejtge1xw0x</liability_gl_account_id>
<name>Add-On with RevRec</name>
<performance_obligation_id>5</performance_obligation_id>
<revenue_gl_account_id>t5ejtgf1vxh1</revenue_gl_account_id>
<unit_amount_in_cents>
<USD type="integer">40</USD>
</unit_amount_in_cents>
</add_on>

HTTP/1.1 201 Created
Content-Type: application/xml; charset=utf-8
Location: https://api.recurly.com/v2/plans/planmock/add_ons/addonrevrec

<?xml version="1.0" encoding="UTF-8"?>
<add_on href="https://api.recurly.com/v2/plans/planmock/add_ons/addonrevrec">
<plan href="https://api.recurly.com/v2/plans/planmock"/>
<add_on_code>addonrevrec</add_on_code>
<name>Add-On with RevRec</name>
<default_quantity type="integer">1</default_quantity>
<display_quantity_on_hosted_page type="boolean">false</display_quantity_on_hosted_page>
<tax_code nil="nil"></tax_code>
<unit_amount_in_cents>
<USD type="integer">40</USD>
</unit_amount_in_cents>
<accounting_code nil="nil"></accounting_code>
<add_on_type>fixed</add_on_type>
<optional type="boolean">true</optional>
<revenue_schedule_type>evenly</revenue_schedule_type>
<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>
<tier_type>flat</tier_type>
<created_at type="datetime">2024-02-20T23:06:46Z</created_at>
<updated_at type="datetime">2024-02-20T23:06:46Z</updated_at>
</add_on>
32 changes: 32 additions & 0 deletions tests/fixtures/add-on/exists-with-revrec.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
GET https://api.recurly.com/v2/plans/planmock/add_ons/addonrevrec 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"?>
<add_on href="https://api.recurly.com/v2/plans/planmock/add_ons/addonrevrec">
<plan href="https://api.recurly.com/v2/plans/planmock"/>
<add_on_code>addonrevrec</add_on_code>
<name>Add-On with RevRec</name>
<default_quantity type="integer">1</default_quantity>
<display_quantity_on_hosted_page type="boolean">false</display_quantity_on_hosted_page>
<tax_code nil="nil"></tax_code>
<unit_amount_in_cents>
<USD type="integer">40</USD>
</unit_amount_in_cents>
<accounting_code nil="nil"></accounting_code>
<add_on_type>fixed</add_on_type>
<optional type="boolean">true</optional>
<revenue_schedule_type>evenly</revenue_schedule_type>
<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>
<tier_type>flat</tier_type>
<created_at type="datetime">2024-02-20T23:06:46Z</created_at>
<updated_at type="datetime">2024-02-20T23:06:46Z</updated_at>
</add_on>
39 changes: 39 additions & 0 deletions tests/fixtures/add-on/updated-with-revrec.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
PUT https://api.recurly.com/v2/plans/planmock/add_ons/addonrevrec 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"?>
<add_on>
<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>
</add_on>

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

<?xml version="1.0" encoding="UTF-8"?>
<add_on href="https://api.recurly.com/v2/plans/planmock/add_ons/addonrevrec">
<plan href="https://api.recurly.com/v2/plans/planmock"/>
<add_on_code>addonrevrec</add_on_code>
<name>Add-On with RevRec</name>
<default_quantity type="integer">1</default_quantity>
<display_quantity_on_hosted_page type="boolean">false</display_quantity_on_hosted_page>
<tax_code nil="nil"></tax_code>
<unit_amount_in_cents>
<USD type="integer">40</USD>
</unit_amount_in_cents>
<accounting_code nil="nil"></accounting_code>
<add_on_type>fixed</add_on_type>
<optional type="boolean">true</optional>
<revenue_schedule_type>evenly</revenue_schedule_type>
<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>
<tier_type>flat</tier_type>
<created_at type="datetime">2024-02-20T23:06:46Z</created_at>
<updated_at type="datetime">2024-02-20T23:14:00Z</updated_at>
</add_on>
50 changes: 50 additions & 0 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,56 @@ def test_item_backed_add_on(self):
with self.mock_request('add-on/plan-deleted.xml'):
plan.delete()

def test_add_on_with_revrec(self):
plan_code = 'plan%s' % self.test_id
add_on_code = 'addonrevrec'

plan = Plan(
plan_code=plan_code,
name='Mock Plan',
setup_fee_in_cents=Money(0),
unit_amount_in_cents=Money(1000),
)
with self.mock_request('add-on/plan-created.xml'):
plan.save()

add_on = AddOn(
add_on_code=add_on_code,
name='Add-On with RevRec',
liability_gl_account_id='t5ejtge1xw0x',
revenue_gl_account_id='t5ejtgf1vxh1',
performance_obligation_id='5',
unit_amount_in_cents=Money(40)
)

with self.mock_request('add-on/created-with-revrec.xml'):
plan.create_add_on(add_on)

self.assertEqual(add_on.add_on_code, add_on_code)
self.assertEqual(add_on.name, 'Add-On with RevRec')
self.assertEqual(add_on.liability_gl_account_id, 't5ejtge1xw0x')
self.assertEqual(add_on.revenue_gl_account_id, 't5ejtgf1vxh1')
self.assertEqual(add_on.performance_obligation_id, '5')

with self.mock_request('add-on/exists-with-revrec.xml'):
same_add_on = plan.get_add_on(add_on_code)

self.assertEqual(same_add_on.add_on_code, add_on_code)
self.assertEqual(same_add_on.liability_gl_account_id, 't5ejtge1xw0x')
self.assertEqual(same_add_on.revenue_gl_account_id, 't5ejtgf1vxh1')
self.assertEqual(same_add_on.performance_obligation_id, '5')

add_on.liability_gl_account_id = None
add_on.revenue_gl_account_id = None
add_on.performance_obligation_id = None

with self.mock_request('add-on/updated-with-revrec.xml'):
add_on.save()

self.assertEqual(add_on.liability_gl_account_id, None)
self.assertEqual(add_on.revenue_gl_account_id, None)
self.assertEqual(add_on.performance_obligation_id, '6')

def test_billing_info(self):
logging.basicConfig(level=logging.DEBUG) # make sure it's init'ed
logger = logging.getLogger('recurly.http.request')
Expand Down

0 comments on commit 264b577

Please sign in to comment.