Skip to content

Commit 8c70444

Browse files
authored
Merge pull request #689 from recurly/proration_flexibility
Add support proration flexibility
2 parents 8b910a6 + 1ce4303 commit 8c70444

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

recurly/__init__.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,16 @@ class SubscriptionAddOn(Resource):
16501650
'tier': Tier
16511651
}
16521652

1653+
class ProrationSettings(Resource):
1654+
"""ProrationSettings"""
1655+
1656+
nodename = 'proration_settings'
1657+
1658+
attributes = (
1659+
'credit',
1660+
'charge',
1661+
)
1662+
16531663
class Subscription(Resource):
16541664

16551665
"""A customer account's subscription to your service."""
@@ -1723,12 +1733,15 @@ class Subscription(Resource):
17231733
'billing_info',
17241734
'billing_info_uuid',
17251735
'ramp_intervals',
1726-
'action_result'
1736+
'action_result',
1737+
'proration_settings',
1738+
'invoice_collection'
17271739
)
17281740

17291741
sensitive_attributes = ('number', 'verification_value', 'bulk')
17301742
_classes_for_nodename = {
17311743
'custom_field': CustomField,
1744+
'proration_settings': ProrationSettings,
17321745
'invoice_collection': InvoiceCollection,
17331746
'plan': Plan,
17341747
'ramp_interval': SubRampInterval,

tests/test_resources.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
Purchase, Invoice, InvoiceCollection, CreditPayment, CustomField, ExportDate, ExportDateFile, DunningCampaign, \
1212
DunningCycle, GeneralLedgerAccount, InvoiceTemplate, PerformanceObligation, PlanRampInterval, SubRampInterval, ExternalSubscription, ExternalProduct, \
1313
ExternalProductReference, ExternalPaymentPhase, CustomFieldDefinition, ExternalInvoice, ExternalCharge, ExternalAccount, \
14-
GatewayAttributes, BusinessEntity
14+
GatewayAttributes, BusinessEntity, ProrationSettings
1515
from recurly import Money, NotFoundError, ValidationError, BadRequestError, PageError
1616
from recurly import recurly_logging as logging
17-
from recurlytests import RecurlyTest
17+
from recurlytests import RecurlyTest, xml
18+
from defusedxml import ElementTree
1819

1920
recurly.SUBDOMAIN = 'api'
2021

@@ -2189,6 +2190,43 @@ def test_subscribe_multiple_errors(self):
21892190
except e:
21902191
self.fail("Failed subscription did not raise a Validation error")
21912192

2193+
def test_subscription_change_proration(self):
2194+
2195+
plan = Plan(
2196+
plan_code='basicplan',
2197+
name='Basic Plan',
2198+
setup_fee_in_cents=Money(0),
2199+
unit_amount_in_cents=Money(1000),
2200+
)
2201+
with self.mock_request('subscription/plan-created.xml'):
2202+
plan.save()
2203+
2204+
account = Account(account_code='subscribe%s' % self.test_id)
2205+
with self.mock_request('subscription/account-created.xml'):
2206+
account.save()
2207+
2208+
manualsub = Subscription(
2209+
plan_code='basicplan',
2210+
currency='USD',
2211+
net_terms=10,
2212+
net_terms_type='net',
2213+
po_number='1000',
2214+
collection_method='manual'
2215+
)
2216+
with self.mock_request('subscription/subscribed-manual.xml'):
2217+
account.subscribe(manualsub)
2218+
2219+
manualsub.proration_settings = ProrationSettings(credit='none', charge='full_amount')
2220+
proration_xml = ElementTree.tostring(manualsub.proration_settings.to_element(), encoding='UTF-8')
2221+
self.assertEqual(
2222+
proration_xml,
2223+
xml('<proration_settings><charge>full_amount</charge><credit>none</credit></proration_settings>')
2224+
)
2225+
2226+
assert isinstance(manualsub.proration_settings, ProrationSettings)
2227+
ElementTree.tostring(account.to_element(), encoding='UTF-8')
2228+
2229+
21922230
def test_subscription_with_plan_ramp(self):
21932231
plan_code = 'plan%s' % self.test_id
21942232
logging.basicConfig(level=logging.DEBUG) # make sure it's init'ed

0 commit comments

Comments
 (0)