From 1ce4303be9c509c1b56ff0bba424ef27239c5aeb Mon Sep 17 00:00:00 2001 From: Patrick Duvall Date: Fri, 26 Apr 2024 14:05:29 -0600 Subject: [PATCH] Add support proration flexibility --- recurly/__init__.py | 15 ++++++++++++++- tests/test_resources.py | 42 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/recurly/__init__.py b/recurly/__init__.py index 677e458d..f137164e 100644 --- a/recurly/__init__.py +++ b/recurly/__init__.py @@ -1650,6 +1650,16 @@ class SubscriptionAddOn(Resource): 'tier': Tier } +class ProrationSettings(Resource): + """ProrationSettings""" + + nodename = 'proration_settings' + + attributes = ( + 'credit', + 'charge', + ) + class Subscription(Resource): """A customer account's subscription to your service.""" @@ -1723,12 +1733,15 @@ class Subscription(Resource): 'billing_info', 'billing_info_uuid', 'ramp_intervals', - 'action_result' + 'action_result', + 'proration_settings', + 'invoice_collection' ) sensitive_attributes = ('number', 'verification_value', 'bulk') _classes_for_nodename = { 'custom_field': CustomField, + 'proration_settings': ProrationSettings, 'invoice_collection': InvoiceCollection, 'plan': Plan, 'ramp_interval': SubRampInterval, diff --git a/tests/test_resources.py b/tests/test_resources.py index e5caacbb..6d1f0eaa 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -11,10 +11,11 @@ Purchase, Invoice, InvoiceCollection, CreditPayment, CustomField, ExportDate, ExportDateFile, DunningCampaign, \ DunningCycle, GeneralLedgerAccount, InvoiceTemplate, PerformanceObligation, PlanRampInterval, SubRampInterval, ExternalSubscription, ExternalProduct, \ ExternalProductReference, ExternalPaymentPhase, CustomFieldDefinition, ExternalInvoice, ExternalCharge, ExternalAccount, \ - GatewayAttributes, BusinessEntity + GatewayAttributes, BusinessEntity, ProrationSettings from recurly import Money, NotFoundError, ValidationError, BadRequestError, PageError from recurly import recurly_logging as logging -from recurlytests import RecurlyTest +from recurlytests import RecurlyTest, xml +from defusedxml import ElementTree recurly.SUBDOMAIN = 'api' @@ -2189,6 +2190,43 @@ def test_subscribe_multiple_errors(self): except e: self.fail("Failed subscription did not raise a Validation error") + def test_subscription_change_proration(self): + + plan = Plan( + plan_code='basicplan', + name='Basic Plan', + setup_fee_in_cents=Money(0), + unit_amount_in_cents=Money(1000), + ) + with self.mock_request('subscription/plan-created.xml'): + plan.save() + + account = Account(account_code='subscribe%s' % self.test_id) + with self.mock_request('subscription/account-created.xml'): + account.save() + + manualsub = Subscription( + plan_code='basicplan', + currency='USD', + net_terms=10, + net_terms_type='net', + po_number='1000', + collection_method='manual' + ) + with self.mock_request('subscription/subscribed-manual.xml'): + account.subscribe(manualsub) + + manualsub.proration_settings = ProrationSettings(credit='none', charge='full_amount') + proration_xml = ElementTree.tostring(manualsub.proration_settings.to_element(), encoding='UTF-8') + self.assertEqual( + proration_xml, + xml('full_amountnone') + ) + + assert isinstance(manualsub.proration_settings, ProrationSettings) + ElementTree.tostring(account.to_element(), encoding='UTF-8') + + def test_subscription_with_plan_ramp(self): plan_code = 'plan%s' % self.test_id logging.basicConfig(level=logging.DEBUG) # make sure it's init'ed