dj-stripe: Unable to subscribe a customer in 2.6.0c1

Describe the bug

In 2.6.0c1, I’m not able to subscribe a customer to a price/plan as described in documentation. Instead I get

stripe.error.InvalidRequestError: Request req_k0ZUHR6WvUV5Ze: No such price: '$0.00 USD/month for Foo (0 subscriptions)'

To Reproduce

  1. Clone https://gitlab.com/bufke/dj-stripe-subscribe-bug
  2. Enter a test secret key env var/setting STRIPE_TEST_SECRET_KEY
  3. Ensure at least one plan and one customer exist in test stripe account
  4. Sync stripe models
  5. Run the following
price_1 = Price.objects.filter(livemode=False).first()
customer = Customer.objects.first()
customer.subscribe(items=[{"price": price_1}])

We expect this to subscribe the first customer to the first price where livemode is false. Instead we get

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.10/site-packages/djstripe/models/core.py", line 883, in subscribe
    stripe_subscription = Subscription._api_create(
  File "/usr/local/lib/python3.10/site-packages/djstripe/models/base.py", line 213, in _api_create
    return cls.stripe_class.create(api_key=api_key, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/stripe/api_resources/abstract/createable_api_resource.py", line 22, in create
    response, api_key = requestor.request("post", url, params, headers)
  File "/usr/local/lib/python3.10/site-packages/stripe/api_requestor.py", line 122, in request
    resp = self.interpret_response(rbody, rcode, rheaders)
  File "/usr/local/lib/python3.10/site-packages/stripe/api_requestor.py", line 399, in interpret_response
    self.handle_error_response(rbody, rcode, resp.data, rheaders)
  File "/usr/local/lib/python3.10/site-packages/stripe/api_requestor.py", line 159, in handle_error_response
    raise err
stripe.error.InvalidRequestError: Request req_k0ZUHR6WvUV5Ze: No such price: '$0.00 USD/month for Foo (0 subscriptions)'

The same test stripe account was working in 2.5.1 using the prior syntax customer.subscribe(plan) which is no longer supported in 2.6. I tried a few different plans and prices but got the same results. It seems like Stripe is receiving the string representation of the price instead of it’s ID. I also tried subscribing to price_1.id which makes the stripe API call work fine, but then dj-stripe is unable to find the subscription.

Software versions

  • Dj-Stripe version: 2.6.0c1
  • Python version: 3.10
  • Django version: 4.0.1
  • Stripe API version: 2020-08-27
  • Database type and version: Postgres 13

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18 (2 by maintainers)

Commits related to this issue

Most upvoted comments

We will get this backported to 2.6.1 as soon as possible.

Look good, thank you!

@bufke PR #1553 should fix this issue