Skip to content

Commit

Permalink
Add support proration flexibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick-Duvall committed Apr 26, 2024
1 parent 8b910a6 commit 1ce4303
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
15 changes: 14 additions & 1 deletion recurly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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,
Expand Down
42 changes: 40 additions & 2 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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('<proration_settings><charge>full_amount</charge><credit>none</credit></proration_settings>')
)

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
Expand Down

0 comments on commit 1ce4303

Please sign in to comment.