#brilliam.de

1 messages · Page 1 of 1 (latest)

oblique raftBOT
finite atlas
#

hi there!

forest yarrow
finite atlas
#

ok, and what status would i be specifically looking for to know if the charge was a success?

forest yarrow
#

It would be 'succeeded'.

finite atlas
#

gotcha. so i’m looking for something similar right now, mind if i share some code?

forest yarrow
finite atlas
#

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') { ... ```
forest yarrow
finite atlas
#

so would i check payment_status or just status?

forest yarrow
#

You'd want 'paid' in this case.

finite atlas
#

ah ok

forest yarrow
#

payment_status

#

The other status has is the status of the Checkout Session itself.

finite atlas
#

so is 'paid' a "universal" status that will always show if the funds were successfully transfered or not?

forest yarrow
#

That is correct, it would show when it's paid.

finite atlas
#

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') {

forest yarrow
#

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.

finite atlas
#

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

forest yarrow
#

hhmmm, I do not understand this question. Can you rephrase this please?

#

You cannot refund a checkout session.

finite atlas
#

sure, so still using checkout

forest yarrow
#

That is not how it works

finite atlas
#

hm, how can i refund a checkout session then if the user already paid? would i need to lookup the paymentIntent?

forest yarrow
#

A Checkout Session represents your customer's session...

finite atlas
#

i see, so lets say my webapp creates the checkout session for the user

#

the user pays

forest yarrow
finite atlas
#

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?