Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(subscriptions): add option 'proration_behavior.always_invoice' for updates #207

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ To quickly run localstripe from source, and reload when a file changed:

.. code:: shell

find -name '*.py' | entr -r python3 -m localstripe --from-scratch
pip3 install -r requirements.txt
find . -name '*.py' | entr -r python3 -m localstripe --from-scratch

To quickly build and run localstripe from source:

Expand Down
11 changes: 7 additions & 4 deletions localstripe/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -2734,7 +2734,7 @@ def __init__(self, customer=None, metadata=None, items=None,
assert type(billing_cycle_anchor) is int
assert billing_cycle_anchor > int(time.time())
if proration_behavior is not None:
assert proration_behavior in ['create_prorations', 'none']
assert proration_behavior in ['create_prorations', 'always_invoice', 'none']
assert type(items) is list
for item in items:
assert type(item.get('plan')) is str
Expand Down Expand Up @@ -2890,7 +2890,7 @@ def _update(self, metadata=None, items=None, trial_end=None,
default_tax_rates=None, tax_percent=None,
plan=None, quantity=None, # legacy support
prorate=None, proration_date=None, cancel_at_period_end=None,
cancel_at=None,
cancel_at=None, proration_behavior=None,
# Currently unimplemented, only False works as expected:
enable_incomplete_payments=False):

Expand Down Expand Up @@ -2931,6 +2931,8 @@ def _update(self, metadata=None, items=None, trial_end=None,
if cancel_at is not None:
assert type(cancel_at) is int
assert cancel_at > 1500000000
if proration_behavior is not None:
assert proration_behavior in ['create_prorations', 'always_invoice', 'none']
if items is not None:
assert type(items) is list
for item in items:
Expand Down Expand Up @@ -3028,9 +3030,10 @@ def _update(self, metadata=None, items=None, trial_end=None,
# If the subscription is updated to a more expensive plan, an invoice
# is not automatically generated. To achieve that, an invoice has to
# be manually created using the POST /invoices route.
create_an_invoice = self.plan.billing_scheme == 'per_unit' and (
create_an_invoice = proration_behavior == 'always_invoice' or (
self.plan.billing_scheme == 'per_unit' and (
self.plan.interval != old_plan.interval or
self.plan.interval_count != old_plan.interval_count)
self.plan.interval_count != old_plan.interval_count))
if create_an_invoice:
self._create_invoice()

Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
aiohttp >=2.3.2
python-dateutil >=2.6.1