Unable to subscribe a customer in 2.6.0c1
See original GitHub issueDescribe 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
- Clone https://gitlab.com/bufke/dj-stripe-subscribe-bug
- Enter a test secret key env var/setting
STRIPE_TEST_SECRET_KEY
- Ensure at least one plan and one customer exist in test stripe account
- Sync stripe models
- 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:
- Created 2 years ago
- Comments:18 (10 by maintainers)
Top GitHub Comments
We will get this backported to 2.6.1 as soon as possible.
Look good, thank you!