#brilliam.de
1 messages · Page 1 of 1 (latest)
hi there!
Hi... you can retrieve the Payment Intent by using the 'Retrieve a PaymentIntent' API: https://stripe.com/docs/api/payment_intents/retrieve and looking at the response > status hash.
ok, and what status would i be specifically looking for to know if the charge was a success?
It would be 'succeeded'.
gotcha. so i’m looking for something similar right now, mind if i share some code?
Here is a bit more information how Payment Intents work: https://stripe.com/docs/payments/intents
You can share a snippet of your code. What is the issue? Are you not seeing the status? Or else? Can you share the request id for this Payment Intent? Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
so im wondering what the drawback is in checking the payment status like this
const session = await stripe.checkout.sessions.retrieve(
req.query.session_id
);
var slug = session.metadata.slug
var url = session.metadata.url
if(!db.get(slug) && session.payment_status !== 'unpaid') { ... ```
Ah you're using Stripe Checkout. You'd want to retrieve the Checkout Session: https://stripe.com/docs/api/checkout/sessions/retrieve and look at the payment status : https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-payment_status instead.
so would i check payment_status or just status?
You'd want 'paid' in this case.
ah ok
so is 'paid' a "universal" status that will always show if the funds were successfully transfered or not?
That is correct, it would show when it's paid.
so would i still be right to still check the reverse of 'unpaid' status then && session.payment_status !== 'unpaid') { to sucessfully verify if it was paid?
ie. "if not unpaid, run this code"
or should i switch to && session.payment_status == 'paid') {
Not entirely on the first one...
As this has 3 enums.. the last option being no_payment_required. The second one works but you might want to handle no_payment_required if it's applicable to your payments.
ah so && session.payment_status == 'paid') { is probably the way to go, then handle the other enums a different way
also is there a way to refund a checkout session and not a payment intent?
const refund = await stripe.refunds.create({
id: session.payment_intent,
reason: 'Slug' + slug + ' not available, for some reason.'
})
this is the code i have now
hhmmm, I do not understand this question. Can you rephrase this please?
You cannot refund a checkout session.
sure, so still using checkout
That is not how it works
hm, how can i refund a checkout session then if the user already paid? would i need to lookup the paymentIntent?
A Checkout Session represents your customer's session...
i see, so lets say my webapp creates the checkout session for the user
the user pays
Yes, you can refund he Payment Intent; https://stripe.com/docs/api/refunds/create#create_refund-payment_intent
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
when handling his payment, there was an error, so my webapp should refund it automatically
would i need to create a payment intent for this, even though the transaction already exist alongside the Checkout session?
my success URL is /checkout/success?session_id={CHECKOUT_SESSION_ID}'
retrieving a checkout session gives me info like this...
"mode": "payment",
"payment_intent": "pi_1DtBRR2eZvKYlo2CmCVxxvd7",
"payment_link": null,```
so i would use js const refund = await stripe.refunds.create({ payment_intent: session.payment_intent, amount: 40, // keep 10c for fee, user agrees to this at checkout reason: 'Slug' + slug + ' not available, for some reason.' }) right?