pinax / pinax-stripe-light

a payments Django app for Stripe
MIT License
684 stars 285 forks source link

Support for Tiered Metered Usage Plans #628

Open jksimoniii opened 5 years ago

jksimoniii commented 5 years ago

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