#likhith_code

1 messages ยท Page 1 of 1 (latest)

subtle sorrelBOT
#

๐Ÿ‘‹ 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/1276141242119622760

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

velvet harness
#

What do you mean by 'status of transaction' exactly? What do you need to poll/check for?

hallow grove
#

see i am using this code session = stripe.PaymentIntent.create(
payment_method_types=['card'],
line_items=[{
'price_data': {
'currency': currency,
'product_data': {
'name': student_packages.package.name,
'metadata': {
'package_name': student_packages.package.name,
'package_details': 'Includes access to sessions',
},
},
'unit_amount': actual_amount,
},
'quantity': 1,
}],
mode='payment',
success_url=STUDENT_PACKAGE_CALLBACK_URL,
cancel_url=STUDENT_PACKAGE_CALLBACK_URL,
)

velvet harness
hallow grove
#

so i want to check the status of the transaction not through webhook rather through a function using the session.id but payment_intent is null, the requirement is i want to generate a url through which in mobile application they can complete the transaction through web

velvet harness
#

Well payment_intent field will be null for sessions that have status: 'open' as the Payment Intent is only created when a confirmation attempt is made

hallow grove
#

so could you suggest a way or a flow i need to follow from initiating payment through web and checking the status of the transaction through a fucnction using session id and updating it in my local models where the transaction is successful, or failed or still pending

velvet harness
#

As explained, this is what a webhook is for. You're code/integration will be more stable and less brittle if you just rely on the events sent by us to signify a successful payment

In any case, you can just check the status and payment_status fields on the Checkout Session to understand if it was paid or not

hallow grove
#

can you share the code structure so that i can implement

#

i will returning session.url

velvet harness
#

No we don't write code here. As explained, the best way to be notified of when a customer comples a payment on your Checkout Session is via a webhook. The guide I linked earlier (https://docs.stripe.com/checkout/fulfillment) explains how to write the code to handle that, and the doc here is a good overview of how webhooks work and how to set them up: https://docs.stripe.com/webhooks

Learn how to fulfill payments received with Checkout and Payment Links.

Listen to events in your Stripe account on your webhook endpoint so your integration can automatically trigger reactions.

hallow grove
#

but if webhook fails

#

the provided web hook url is not called then we would need a cron

velvet harness
subtle sorrelBOT
hallow grove
#

okay i have to create the logic according to our systems payment data handling in webhook how can i trigger the local url as webhook as it is not hosted in server

velvet harness
hallow grove
#

let's say webhook gets triggered but id has not updated the transaction status in our db, how will we know the webhook has ran

kindred escarp
#

hi! I'm taking over this thread.

#

but id has not updated the transaction status in our db
what do you mean by this? when you receive a webhook event, then it's up to you to write some code to update your database accordingly.

hallow grove
#

yes we know that the webhook logic has to be handled by us

#

we will take care of the logic

#

but the thing is in local server we don't have any webhooks setup

#

is there no other way to check the payment status except webhook

#

even webhook has not been hosted in a server yet then we can provide the local url which has not been hosted

kindred escarp
hallow grove
#

yes got it

#

i am looking in to it

#

is there any github repo where one has implemented this

kindred escarp
hallow grove
#

okay let me check it out.

#

i have another doubt in we need to save the payment_intent_id will i get this once session checkout happens so that i can save it our database

kindred escarp
#

are you listening to the checkout.session.completed event?

#

if so, then you'll get a Checkout Session object that doesn't directly contain the PaymentMethod: https://docs.stripe.com/api/checkout/sessions/object
instead you'll check the payment_intent (or setup_intent) property, make an extra API call to retrieve that object, which will have a payment_method property.

hallow grove
#

yes

#

session object is what i am getting

kindred escarp
#

makes sense, then check my answer above.

hallow grove
#

in this still payment_intent is null

kindred escarp
#

I just deleted your code since it contained your secret key

#

you should roll your key from the Stripe dashboard now

#

in this still payment_intent is null
Can you share an Event ID (evt_xxx), or Rquest ID (req_xxx) where you see this?

#

or Checkout Session ID (cs_xxx)?

hallow grove
#

cs_test_a1oBDkxidrOLkzXVMovidFtfRPnU4dWeZhUADC19GMcTbBpPdkzNgQQRFx

#

this is session id

#

that id was present in stripe docs

kindred escarp
#

this Checkout Session does have a PaymentIntent: payment_intent: "pi_3PqZ2mA1npjrCKK109XcDk1t"

hallow grove
#

in here payment_intent is null

#

so basically i can't retrieve the status based on this

kindred escarp
#

sure, but this Checkout Session has "status": "open"

#

you'll only get the PaymentIntent when the Checkout Session is successful

#

that's why you should listen to checkout.session.completed

hallow grove
#

open means that transaction is not yet completed

kindred escarp
#

correct

hallow grove
#

okay got it let me check this out