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

Support for Tiered Metered Usage Plans #628

Open
jksimoniii opened this issue Jan 30, 2019 · 0 comments · May be fixed by #629
Open

Support for Tiered Metered Usage Plans #628

jksimoniii opened this issue Jan 30, 2019 · 0 comments · May be fixed by #629

Comments

@jksimoniii
Copy link

jksimoniii commented Jan 30, 2019

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"
}

@jksimoniii jksimoniii changed the title Support for Metered Usage Plan Support for Tiered Metered Usage Plans Jan 30, 2019
@jksimoniii jksimoniii linked a pull request Feb 3, 2019 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant