Skip to content

Commit

Permalink
add-revrec-for-plans
Browse files Browse the repository at this point in the history
  • Loading branch information
8eth committed Feb 7, 2024
1 parent 24d77f6 commit b2ff1a1
Show file tree
Hide file tree
Showing 5 changed files with 267 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 @@ -1527,6 +1527,12 @@ class Plan(Resource):
'trial_interval_unit',
'accounting_code',
'setup_fee_accounting_code',
'liability_gl_account_id',
'revenue_gl_account_id',
'performance_obligation_id',
'setup_fee_liability_gl_account_id',
'setup_fee_revenue_gl_account_id',
'setup_fee_performance_obligation_id',
'created_at',
'updated_at',
'tax_exempt',
Expand Down
76 changes: 76 additions & 0 deletions tests/fixtures/plan/created-with-revrec.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
POST https://api.recurly.com/v2/plans 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"?>
<plan>
<liability_gl_account_id>t5ejtge1xw0x</liability_gl_account_id>
<name>RevRec Plan</name>
<performance_obligation_id>5</performance_obligation_id>
<plan_code>planmock</plan_code>
<revenue_gl_account_id>t5ejtgf1vxh1</revenue_gl_account_id>
<setup_fee_in_cents>
<USD type="integer">200</USD>
</setup_fee_in_cents>
<setup_fee_liability_gl_account_id>t5ejtge1xw0x</setup_fee_liability_gl_account_id>
<setup_fee_performance_obligation_id>5</setup_fee_performance_obligation_id>
<setup_fee_revenue_gl_account_id>t5ejtgf1vxh1</setup_fee_revenue_gl_account_id>
<unit_amount_in_cents>
<USD type="integer">1000</USD>
</unit_amount_in_cents>
</plan>

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

<?xml version="1.0" encoding="UTF-8"?>
<plan href="https://api.recurly.com/v2/plans/planmock">
<add_ons href="https://api.recurly.com/v2/plans/planmock/add_ons"/>
<plan_code>planmock</plan_code>
<name>RevRec Plan</name>
<description nil="nil"></description>
<success_url nil="nil"></success_url>
<cancel_url nil="nil"></cancel_url>
<display_donation_amounts type="boolean">false</display_donation_amounts>
<display_quantity type="boolean">false</display_quantity>
<display_phone_number type="boolean">false</display_phone_number>
<bypass_hosted_confirmation type="boolean">false</bypass_hosted_confirmation>
<unit_name>unit</unit_name>
<payment_page_tos_link nil="nil"></payment_page_tos_link>
<plan_interval_length type="integer">1</plan_interval_length>
<plan_interval_unit>months</plan_interval_unit>
<trial_interval_length type="integer">0</trial_interval_length>
<trial_interval_unit>days</trial_interval_unit>
<total_billing_cycles type="integer">1</total_billing_cycles>
<accounting_code nil="nil"></accounting_code>
<setup_fee_accounting_code nil="nil"></setup_fee_accounting_code>
<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>
<setup_fee_liability_gl_account_id>t5ejtge1xw0x</setup_fee_liability_gl_account_id>
<setup_fee_revenue_gl_account_id>t5ejtgf1vxh1</setup_fee_revenue_gl_account_id>
<setup_fee_performance_obligation_id>5</setup_fee_performance_obligation_id>
<allow_any_item_on_subscriptions type="boolean">false</allow_any_item_on_subscriptions>
<created_at type="datetime">2024-02-06T21:47:46Z</created_at>
<updated_at type="datetime">2024-02-06T21:47:46Z</updated_at>
<auto_renew type="boolean">true</auto_renew>
<pricing_model>fixed</pricing_model>
<custom_fields type="array">
</custom_fields>
<revenue_schedule_type>evenly</revenue_schedule_type>
<setup_fee_revenue_schedule_type>evenly</setup_fee_revenue_schedule_type>
<trial_requires_billing_info type="boolean">true</trial_requires_billing_info>
<tax_exempt type="boolean">false</tax_exempt>
<tax_code nil="nil"></tax_code>
<unit_amount_in_cents>
<USD type="integer">1000</USD>
</unit_amount_in_cents>
<setup_fee_in_cents>
<USD type="integer">200</USD>
</setup_fee_in_cents>
<dunning_campaign_id nil="nil"></dunning_campaign_id>
</plan>
57 changes: 57 additions & 0 deletions tests/fixtures/plan/exists_with_revrec.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
GET https://api.recurly.com/v2/plans/planmock 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"?>
<plan href="https://api.recurly.com/v2/plans/planmock">
<add_ons href="https://api.recurly.com/v2/plans/planmock/add_ons"/>
<plan_code>planmock</plan_code>
<name>RevRec Plan</name>
<description nil="nil"></description>
<success_url nil="nil"></success_url>
<cancel_url nil="nil"></cancel_url>
<display_donation_amounts type="boolean">false</display_donation_amounts>
<display_quantity type="boolean">false</display_quantity>
<display_phone_number type="boolean">false</display_phone_number>
<bypass_hosted_confirmation type="boolean">false</bypass_hosted_confirmation>
<unit_name>unit</unit_name>
<payment_page_tos_link nil="nil"></payment_page_tos_link>
<plan_interval_length type="integer">1</plan_interval_length>
<plan_interval_unit>months</plan_interval_unit>
<trial_interval_length type="integer">0</trial_interval_length>
<trial_interval_unit>days</trial_interval_unit>
<total_billing_cycles type="integer">1</total_billing_cycles>
<accounting_code nil="nil"></accounting_code>
<setup_fee_accounting_code nil="nil"></setup_fee_accounting_code>
<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>
<setup_fee_liability_gl_account_id>t5ejtge1xw0x</setup_fee_liability_gl_account_id>
<setup_fee_revenue_gl_account_id>t5ejtgf1vxh1</setup_fee_revenue_gl_account_id>
<setup_fee_performance_obligation_id>5</setup_fee_performance_obligation_id>
<allow_any_item_on_subscriptions type="boolean">false</allow_any_item_on_subscriptions>
<created_at type="datetime">2024-02-06T21:47:46Z</created_at>
<updated_at type="datetime">2024-02-06T21:47:46Z</updated_at>
<auto_renew type="boolean">true</auto_renew>
<pricing_model>fixed</pricing_model>
<custom_fields type="array">
</custom_fields>
<revenue_schedule_type>evenly</revenue_schedule_type>
<setup_fee_revenue_schedule_type>evenly</setup_fee_revenue_schedule_type>
<trial_requires_billing_info type="boolean">true</trial_requires_billing_info>
<tax_exempt type="boolean">false</tax_exempt>
<tax_code nil="nil"></tax_code>
<unit_amount_in_cents>
<USD type="integer">1000</USD>
</unit_amount_in_cents>
<setup_fee_in_cents>
<USD type="integer">200</USD>
</setup_fee_in_cents>
<dunning_campaign_id nil="nil"></dunning_campaign_id>
</plan>
67 changes: 67 additions & 0 deletions tests/fixtures/plan/updated_with_revrec.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
PUT https://api.recurly.com/v2/plans/planmock 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"?>
<plan>
<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>
<setup_fee_liability_gl_account_id nil="nil"></setup_fee_liability_gl_account_id>
<setup_fee_performance_obligation_id nil="nil"></setup_fee_performance_obligation_id>
<setup_fee_revenue_gl_account_id nil="nil"></setup_fee_revenue_gl_account_id>
</plan>

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

<?xml version="1.0" encoding="UTF-8"?>
<plan href="https://api.recurly.com/v2/plans/planmock">
<add_ons href="https://api.recurly.com/v2/plans/planmock/add_ons"/>
<plan_code>planmock</plan_code>
<name>RevRec Plan</name>
<description nil="nil"></description>
<success_url nil="nil"></success_url>
<cancel_url nil="nil"></cancel_url>
<display_donation_amounts type="boolean">false</display_donation_amounts>
<display_quantity type="boolean">false</display_quantity>
<display_phone_number type="boolean">false</display_phone_number>
<bypass_hosted_confirmation type="boolean">false</bypass_hosted_confirmation>
<unit_name>unit</unit_name>
<payment_page_tos_link nil="nil"></payment_page_tos_link>
<plan_interval_length type="integer">1</plan_interval_length>
<plan_interval_unit>months</plan_interval_unit>
<trial_interval_length type="integer">0</trial_interval_length>
<trial_interval_unit>days</trial_interval_unit>
<total_billing_cycles type="integer">1</total_billing_cycles>
<accounting_code nil="nil"></accounting_code>
<setup_fee_accounting_code nil="nil"></setup_fee_accounting_code>
<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>
<setup_fee_liability_gl_account_id nil="nil"></setup_fee_liability_gl_account_id>
<setup_fee_revenue_gl_account_id nil="nil"></setup_fee_revenue_gl_account_id>
<setup_fee_performance_obligation_id>4</setup_fee_performance_obligation_id>
<allow_any_item_on_subscriptions type="boolean">false</allow_any_item_on_subscriptions>
<created_at type="datetime">2024-02-06T22:01:53Z</created_at>
<updated_at type="datetime">2024-02-06T22:01:53Z</updated_at>
<auto_renew type="boolean">true</auto_renew>
<pricing_model>fixed</pricing_model>
<custom_fields type="array">
</custom_fields>
<revenue_schedule_type>evenly</revenue_schedule_type>
<setup_fee_revenue_schedule_type>evenly</setup_fee_revenue_schedule_type>
<trial_requires_billing_info type="boolean">true</trial_requires_billing_info>
<tax_exempt type="boolean">false</tax_exempt>
<tax_code nil="nil"></tax_code>
<unit_amount_in_cents>
<USD type="integer">1000</USD>
</unit_amount_in_cents>
<setup_fee_in_cents>
<USD type="integer">200</USD>
</setup_fee_in_cents>
<dunning_campaign_id nil="nil"></dunning_campaign_id>
</plan>
61 changes: 61 additions & 0 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1841,6 +1841,67 @@ def test_plan_with_ramps(self):
with self.mock_request('plan/updated_with_ramps.xml'):
plan.save()

def test_plan_with_revrec(self):
plan_code = 'plan%s' % self.test_id
with self.mock_request('plan/does-not-exist.xml'):
self.assertRaises(NotFoundError, Plan.get, plan_code)

plan = Plan(
name='RevRec Plan',
plan_code=plan_code,
setup_fee_in_cents=Money(200),
unit_amount_in_cents=Money(1000),
liability_gl_account_id='t5ejtge1xw0x',
revenue_gl_account_id='t5ejtgf1vxh1',
performance_obligation_id='5',
setup_fee_liability_gl_account_id='t5ejtge1xw0x',
setup_fee_revenue_gl_account_id='t5ejtgf1vxh1',
setup_fee_performance_obligation_id='5'
)

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

self.assertEqual(plan.plan_code, plan_code)
self.assertEqual(plan.name, 'RevRec Plan')
self.assertEqual(plan.liability_gl_account_id, 't5ejtge1xw0x')
self.assertEqual(plan.revenue_gl_account_id, 't5ejtgf1vxh1')
self.assertEqual(plan.performance_obligation_id, '5')
self.assertEqual(plan.setup_fee_liability_gl_account_id, 't5ejtge1xw0x')
self.assertEqual(plan.setup_fee_revenue_gl_account_id, 't5ejtgf1vxh1')
self.assertEqual(plan.setup_fee_performance_obligation_id, '5')

with self.mock_request('plan/exists_with_revrec.xml'):
same_plan = Plan.get(plan_code)

self.assertEqual(plan.plan_code, plan_code)
self.assertEqual(plan.name, 'RevRec Plan')
self.assertEqual(plan.liability_gl_account_id, 't5ejtge1xw0x')
self.assertEqual(plan.revenue_gl_account_id, 't5ejtgf1vxh1')
self.assertEqual(plan.performance_obligation_id, '5')
self.assertEqual(plan.setup_fee_liability_gl_account_id, 't5ejtge1xw0x')
self.assertEqual(plan.setup_fee_revenue_gl_account_id, 't5ejtgf1vxh1')
self.assertEqual(plan.setup_fee_performance_obligation_id, '5')

plan.liability_gl_account_id = None
plan.revenue_gl_account_id = None
plan.performance_obligation_id = None
plan.setup_fee_liability_gl_account_id = None
plan.setup_fee_revenue_gl_account_id = None
plan.setup_fee_performance_obligation_id = None

with self.mock_request('plan/updated_with_revrec.xml'):
plan.save()

self.assertEqual(plan.plan_code, plan_code)
self.assertEqual(plan.name, 'RevRec Plan')
self.assertEqual(plan.liability_gl_account_id, None)
self.assertEqual(plan.revenue_gl_account_id, None)
self.assertEqual(plan.performance_obligation_id, '6')
self.assertEqual(plan.setup_fee_liability_gl_account_id, None)
self.assertEqual(plan.setup_fee_revenue_gl_account_id, None)
self.assertEqual(plan.setup_fee_performance_obligation_id, '4')

def test_preview_subscription_change(self):
with self.mock_request('subscription/show.xml'):
sub = Subscription.get('123456789012345678901234567890ab')
Expand Down

0 comments on commit b2ff1a1

Please sign in to comment.