#jacyespinosa-payment_intent

1 messages ยท Page 1 of 1 (latest)

sharp oasis
#

Hi there, are you using checkout session for this payment?

stray tangle
#

yes I am.

sharp oasis
#

Great, you can listen to the checkout session event -> checkout.session.completed and you can get the payment_intent ID from the session object.

stray tangle
#

but i dont know how to access that payment_intent when I am redirected to success.html

sharp oasis
#

If you are listening to the payment_intent.succeeded event, you can get the payment_intent from the object itself

So in your code it should be `payment_intent = event['data']['object']

stray tangle
#

i am able to fetch the data while in webhook route, but I'm having trouble query'ing my db while in webhook route.

#

Therefore, I am trying to retrieve the payment_intent when I am redirected to success.html, but I used this stripe.checkout.Session.list(limit=1), it is a totally different payment_intent data compare to the one that the webhook route spit out. I checked my dashboard after everything, the payment_intent from the thanks route says that payment is Incomplete, however, the webhook route's payment_intent says 'Completed' according to my dashboard.

#

Sorry, it sounds confusing...

sharp oasis
#

the payment_intent from the thanks route says -> How did you get this payment_intent? from checkout.session.completed webhook ?

stray tangle
#

I'm so sorry... can you please elaborate?

sharp oasis
#

You mentioned that you have retrieved two payment_intents and their status are different, one is from the 'thanks route' and the other is via the webhook route.

So I would like to understand more on the 'thanks route' and see how did you retrieve the payment_intent.

stray tangle
#

Oh okay. So I retrieved the payment_intent data in thanks route by using the above code.

#

pi_3K646jLsctVhWk9r18cwIhDa was retrieved while in thanks route, yet when I checked my Dashboard, the payment is incomplete. But the other payment_intent pi_3K646iLsctVhWk9r0zY2uhPb, was retrieved in webhook route.

#

please ignore that first 3 payment_intents in the db screenshot.

#

thanks route:

checkout_session = stripe.checkout.Session.list(limit=1)
print(checkout_session)
This is what it looks like.
payment_intent = checkout_session['data'][0]['payment_intent']
Is how I was able to grabbed the payment_intent data.

sharp oasis
#

They are different payment_intents.

#

Give me a second, let me take a look on your PIs

stray tangle
#

appreciate you a lot

sharp oasis
#

It seems like you have created two checkout sessions at the same time and only one checkout session is proceeded.

stray tangle
#

which part did I create another checkout session? was it because of this line: checkout_session = stripe.checkout.Session.list(limit=1) ?

sharp oasis
#

The timestamps of these two checkout sessions are the same.

stray tangle
#

I see.. uhmm where do you think I created the second checkout session based on the screenshot that I've shared with you?

sharp oasis
#

I don't see any codes related to session creation in the screenshot, if you can share with me the code, I am happy to help.

BTW, I noticed that your fulfillment logic is based on the success page, and I highly recommend you to use webhook instead.

stray tangle
#

Oh sure. Let me try my best to capture everything Stripe related here. Just a sec:

sharp oasis
stray tangle
#

Here are the screenshots that's all stripe related

#

I hope this one helps with finding root of the problem... Thank you so much again for helping me out.. I've been stuck with problem for almost the whole day.. ๐Ÿ˜ฆ

sharp oasis
#

in the create-checkout-session route, why do you need both 'GET' and 'POST' methods?

stray tangle
#

to be honest with you, it's just a habit for me to add both methods... ๐Ÿ˜

sharp oasis
#

I would suggest you to put some log in he create-checkout-session route, to observe and figure out why it is invoked twice.

stray tangle
#

what do you mean by that? sorry i'm a beginner... ๐Ÿ˜ really appreciate your patience

sharp oasis
#

Are you using Flask?

stray tangle
#

yes

sharp oasis
stray tangle
#

so you would sugges to have the users/customers log in to their own account?

#

to be able to access the create-checkout-session?

sharp oasis
#

Sorry for the confusion, I mean logging, not log in.

stray tangle
#

could you give me an example of how i would incorporate that?

sharp oasis
stray tangle
sharp oasis
#

Hi @stray tangle I am unable to help to you debug your own Flask application.

So far we can conclude that the checkout session is created twice and that's why you see two different payment_intents with different status, and now you need to troubleshooting your app to avoid duplicate checkout session creation.