Support for Tiered Metered Usage Plans
jksimoniii opened this issue · 0 comments
jksimoniii commented
Issue Summary
./manage.py sync_plans
throws an error when attempting to convert a plan that uses Stripe's Metered Billing feature (docs).
Steps to Reproduce
Setup a tiered metered usage plan with metered billing in Stripe (see docs) and then run ./manage.py sync_plans
What were you expecting to happen?
New plan gets synced to Django.
What actually happened?
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/site-packages/pinax/stripe/management/commands/sync_plans.py", line 11, in handle
plans.sync_plans()
File "/usr/local/lib/python2.7/site-packages/pinax/stripe/actions/plans.py", line 12, in sync_plans
sync_plan(plan)
File "/usr/local/lib/python2.7/site-packages/pinax/stripe/actions/plans.py", line 25, in sync_plan
"amount": utils.convert_amount_for_db(plan["amount"], plan["currency"]),
File "/usr/local/lib/python2.7/site-packages/pinax/stripe/utils.py", line 36, in convert_amount_for_db
return (amount / decimal.Decimal("100")) if currency.lower() not in ZERO_DECIMAL_CURRENCIES else decimal.Decimal(amount)
TypeError: unsupported operand type(s) for /: 'NoneType' and 'Decimal'
Updates
- The error likely comes from tiered plans having
amount: null
>>> stripe.Plan.retrieve("somestring")
<Plan plan id=somestring at 0x7f8136441178> JSON: {
"active": true,
"aggregate_usage": "sum",
"amount": null,
"billing_scheme": "tiered",
"created": 1548879965,
"currency": "usd",
"id": "somestring",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {},
"name": "somestring",
"nickname": "somestring",
"object": "plan",
"product": "somestring",
"statement_descriptor": null,
"tiers": [
{
"amount": null,
"flat_amount": 14900,
"up_to": 100
},
{
"amount": 100,
"flat_amount": null,
"up_to": null
}
],
"tiers_mode": "graduated",
"transform_usage": null,
"trial_period_days": null,
"usage_type": "metered"
}