#sayori_api
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1431358063071330355
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
In particular, I was hoping to avoid using webhooks in this scenario - but if that's the only way, let me know
I would for example use the charge_id in a deferred task to send an email to the user that some automatic charge event failed, etcetc
The payment intent id should still be in the response. I see it for the above request
error.payment_intent
Here's a link to the request in your dashboard: https://dashboard.stripe.com/acct_15IR3lGQ5L54VFKV/logs/req_7zmyAsqjXqHJwu
Shows the response
Right, I see it in the dashboard, but I don't see it in the Python response. I just get a stripe._error.CardError
here's the full traceback:
File "/main_instance_shell/me/venv3.12/lib/python3.12/site-packages/IPython/core/interactiveshell.py", line 3672, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-26-d6bb320557c0>", line 1, in <module>
abc = ss.create_payment_intent_async(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "asynq/decorators.py", line 232, in asynq.decorators.AsyncDecorator.__call__
File "asynq/futures.py", line 54, in asynq.futures.FutureBase.value
File "asynq/futures.py", line 63, in asynq.futures.FutureBase.value
File "asynq/futures.py", line 153, in asynq.futures.FutureBase.raise_if_error
File "/main_instance_shell/me/venv3.12/lib/python3.12/site-packages/qcore/errors.py", line 92, in reraise
raise error.with_traceback(error._traceback)
___asynq_continue___
File "asynq/decorators.py", line 168, in _fn_wrapper
File "/main_instance_shell/me/web/lib/lib_monetization/apis/stripe.py", line 730, in create_payment_intent_async
return create_payment_intent(
^^^^^^^^^^^^^^^^^^^^^^
File "/main_instance_shell/me/web/lib/lib_monetization/apis/stripe.py", line 112, in inner
ret = fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/main_instance_shell/me/web/lib/lib_monetization/apis/stripe.py", line 752, in create_payment_intent
return stripe.PaymentIntent.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/main_instance_shell/me/venv3.12/lib/python3.12/site-packages/stripe/_payment_intent.py", ```
cls._static_request(
File "/main_instance_shell/me/venv3.12/lib/python3.12/site-packages/stripe/_api_resource.py", line 177, in _static_request
return _APIRequestor._global_instance().request(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/main_instance_shell/me/venv3.12/lib/python3.12/site-packages/stripe/_api_requestor.py", line 196, in request
resp = requestor._interpret_response(rbody, rcode, rheaders)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/main_instance_shell/me/venv3.12/lib/python3.12/site-packages/stripe/_api_requestor.py", line 732, in _interpret_response
self.handle_error_response(rbody, rcode, resp.data, rheaders)
File "/main_instance_shell/me/venv3.12/lib/python3.12/site-packages/stripe/_api_requestor.py", line 321, in handle_error_response
raise err
stripe._error.CardError: Request req_He3H3r8is9fbq7: Your card was declined for making repeated attempts too frequently or exceeding its amount limit.
this one's a different request id, but the same idea
Yeah you need to catch the error
Then you can inspect the fields on the error object
i've caught the error, and these are my fields:
CardError(message='Your card was declined.', param=None, code='card_declined', http_status=402, request_id='req_D0qmr3SxJiuj6M')
you should be able to access error.payment_intent
So if you do:
except stripe.error.CardError as e:
it would be e.error.payment_intent
unfortunately not - carderror object has no attribute payment_intent
was this perhaps added to a later version of the python apk?
I'm on 9.4.0
It inherits from StripeError so you can
oh wait
e.error.payment_intent, not simply e.payment_intent
yes
e is the error object
the error object contains a param called error
Also shown here: https://docs.stripe.com/error-handling?lang=python#payment-errors
try:
stripe.PaymentIntent.create(**kwargs)
except stripe.CardError as e:
charge = stripe.Charge.retrieve(e.error.payment_intent.latest_charge)
if charge.outcome.type == 'blocked':
logging.error("Payment blocked for suspected fraud.")
elif e.code == 'card_declined':
logging.error("Payment declined by the issuer.")
elif e.code == 'expired_card':
logging.error("Card expired.")
else:
logging.error("Other card error.")```
solid - i missed that there was an error object in between. thanks!