#likhith_code
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/1276141242119622760
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
What do you mean by 'status of transaction' exactly? What do you need to poll/check for?
The recommendation is to handle this async with a webhook where we notify you of successful payments: https://docs.stripe.com/checkout/fulfillment
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,
)
I'll be amazed if that code even works. You're using a Payment Intent method but with Checkout Session parameters
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
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
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
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
can you share the code structure so that i can implement
import stripe
stripe.api_key = "sk_test_tR3PYbcVNZZ796tH88S4VQ2u"
stripe.checkout.Session.create(
line_items=[{"price": '{{PRICE_ID}}', "quantity": 1}],
mode="payment",
ui_mode="embedded",
return_url="https://example.com/after-checkout?session_id={CHECKOUT_SESSION_ID}",
)
i will returning session.url
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
but if webhook fails
the provided web hook url is not called then we would need a cron
We have automatic retries in that scenario: https://docs.stripe.com/webhooks#behaviors
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
You'd use our CLI for that to forward events to your local server: https://docs.stripe.com/webhooks#local-listener
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
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.
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
but the thing is in local server we don't have any webhooks setup
as mentioned earlier:
You'd use our CLI for that to forward events to your local server: https://docs.stripe.com/webhooks#local-listener
yes got it
i am looking in to it
is there any github repo where one has implemented this
implemented what exactly? you just need to follow the steps here by running a few commands: https://docs.stripe.com/webhooks#local-listener
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
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.
makes sense, then check my answer above.
in this still payment_intent is null
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)?
cs_test_a1oBDkxidrOLkzXVMovidFtfRPnU4dWeZhUADC19GMcTbBpPdkzNgQQRFx
this is session id
that id was present in stripe docs
this Checkout Session does have a PaymentIntent: payment_intent: "pi_3PqZ2mA1npjrCKK109XcDk1t"
you can delete this object just check it
this i got when i check out a session
in here payment_intent is null
so basically i can't retrieve the status based on this
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
open means that transaction is not yet completed
correct
okay got it let me check this out