question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to subscribe a customer in 2.6.0c1

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
jleclanchecommented, Feb 4, 2022

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

1reaction
bufkecommented, Feb 2, 2022

Look good, thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

dj-stripe 2.6.2 - PythonFix.com
dj-stripe 2.6.2 ... Sqlite3 database is locked error; Error while subscription ... Unable to subscribe a customer in 2.6.0c1; Update and Fix Formatting ......
Read more >
Why am I unable to subscribe to a creator?
If you are unable to subscribe to a creator, it may be because: Your payments account is disabled. If you are unable to...
Read more >
VERIZON TELEPHONE COMPANIES
2.2.1(B) or 2.5.1 following apply, if a customer fails to comply with 2.4.1(A) ... OC1 or a DS3 with additional Mbps devoted to...
Read more >
Transfer a customer's subscriptions to your reseller account
Select an available payment plan for each subscription, and then click Continue. Change the license and license cap values as needed for each...
Read more >
How subscriptions work | Stripe Documentation
Stripe handles recurring charges for you automatically. This includes: Automatically invoicing customers and attempting payments when new billing cycles start.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found