When a Price nickname attribute is set, the wrong id is sent in request
See original GitHub issueDescribe the bug
When the price has the nickname
attribute set to a string like "Test Monthly"
, and I try to create a checkout session, I get a stack trace like the following
[2021-08-03 18:01:56,317] ERROR main.views 94 create_checkout_session Creating checkout session failed
Internal Server Error: /stripe/create-checkout-session/
Traceback (most recent call last):
File "/home/psacawa/.pyenv/versions/lektprojekt/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/home/psacawa/.pyenv/versions/lektprojekt/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/psacawa/.pyenv/versions/lektprojekt/lib/python3.9/site-packages/sentry_sdk/integrations/django/views.py", line 67, in sentry_wrapped_callback
return callback(request, *args, **kwargs)
File "/home/psacawa/.pyenv/versions/lektprojekt/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/home/psacawa/.pyenv/versions/lektprojekt/lib/python3.9/site-packages/django/views/decorators/http.py", line 40, in inner
return func(request, *args, **kwargs)
File "/home/psacawa/Kody/lektprojekt/backend/main/views.py", line 95, in create_checkout_session
raise (e)
File "/home/psacawa/Kody/lektprojekt/backend/main/views.py", line 64, in create_checkout_session
stripe_session = stripe.checkout.Session.create(
File "/home/psacawa/.pyenv/versions/lektprojekt/lib/python3.9/site-packages/stripe/api_resources/abstract/createable_api_resource.py", line 22, in create
response, api_key = requestor.request("post", url, params, headers)
File "/home/psacawa/.pyenv/versions/lektprojekt/lib/python3.9/site-packages/stripe/api_requestor.py", line 122, in request
resp = self.interpret_response(rbody, rcode, rheaders)
File "/home/psacawa/.pyenv/versions/lektprojekt/lib/python3.9/site-packages/stripe/api_requestor.py", line 399, in interpret_response
self.handle_error_response(rbody, rcode, resp.data, rheaders)
File "/home/psacawa/.pyenv/versions/lektprojekt/lib/python3.9/site-packages/stripe/api_requestor.py", line 159, in handle_error_response
raise err
stripe.error.InvalidRequestError: Request req_nufdnsJ5VxmFd9: No such price: 'Test Monthly'
So it seems it is applying str()
to the price to find the data for the request?
To Reproduce
stripe price update price_123myprice123 --nickname "Some name"
./manage.py djstripe_sync_models price
Then in the code somewhere:
import stripe
...
price = "price_123myprice123"
stripe_session = stripe.checkout.Session.create(
success_url="success_url" ,
cancel_url="cancel_url"
payment_method_types=["card"],
mode="subscription",
metadata={},
line_items=[{"price": price, "quantity": 1}],
)
Software versions
- Dj-Stripe version: 2.5.1
- python-stripe vrsion: 2.60.0
- Python version: 3.9
- Django version: 3.2.6
- Stripe API version: 2020-08-27
- Database type and version: postgres13
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
QuerySet, Object has no attribute id - Django - Stack Overflow
I was getting this error because I wanted to create session from email id but it shows their is no attribute email so...
Read more >The price object – curl - Stripe API reference
nickname string. A brief description of the price, hidden from customers. product ...
Read more >MailNickname or Alias attribute in Exchange Online doesn't ...
To resolve this issue, update the Alias or Mailnickname attribute. To do this, use one of the following methods. Method 1: Use Exchange ......
Read more >Install and Configure the NPS Extension for Azure MFA
There is one event you will always see is: “NPS Extension for Azure MFA: Radius request is missing NAS Identifier and Nas IpAddress...
Read more >Change the Attributes of an Amazon Cognito User Pool
Note: You can add custom attributes to an existing user pool, but these attributes aren't required for user registration. Resolution. Set up a ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry for the delayed reply, I was OOO until today.
The issue is that you’re trying to use the price’s
nickname
in place of itsid
. When creating a Checkout Session, Stripe’s API expects theline_items.price
argument to be a price ID.E.g:
cc @ob-stripe - I agree this is unlikely to be coming from dj-stripe. Do you recognize this issue?