#burt - Checkout Refunds
1 messages · Page 1 of 1 (latest)
Hello! Let me pull your messages into this thread, then we'll talk here...
My stripe server - as detailed in the Stripe quickstart documentation - uses the following code to send the user to a checkout then back to my site
const session = await stripe.checkout.sessions.create({
line_items: myArray,
mode: 'payment',
success_url: http://localhost:3000/ordersuccess?success=true,
cancel_url: http://localhost:3000/cart?canceled=true,
automatic_tax: { enabled: false },
});res.redirect(303, session.url);
How do I retrieve the generated user order ID for refunds?
Sorry about that - I thought a thread was auto-generated on replies
Can I deleted them from chat?
No, unfortunately it's a manual process on our end. Sorry for the delay!
Yeah, you can delete the other messages if you want to.
Not required though.
Anyway, can you tell me a bit more about the specific scenario? Are you trying to issue a refund manually, through the Dashboard, or are you trying to build a refund system in code of some kind?
I am trying to build a refund system into my code. If a user were to "order" and that order were to be wrong, for simplicity lets say they can click a button that says "refund" and get their money back
I'm having trouble implementing this because I am unsure how to access the order ID needed to give refunds when using this stripe hosted checkout
Gotcha. There are several ways to do so. One would be to list the Checkout Sessions belonging to a specific Customer in order to produce the list of things they can choose to get refunded: https://stripe.com/docs/api/checkout/sessions/list#list_checkout_sessions-customer
Would that work for your use case?
This customer is using a "guest" checkout feature and has only given a few details necessary to stripe to complete the transaation. Upon transaction completion there is no way to identify this user via code - they are simply browsing the site.
What I would like to happen is this: Upon user redirect to my site, a backend "order" is created via my personal API that my application is using. This is how I internally track my customer orders outside of stripe. Each order has a unique ID. I would like for this order object to also store it's "Stripe Order ID" when it gets created so that I can reference it to issue a refund
Does this make sense?
In short: I have my own orders getting created for internal tracking. These orders need to include the Stripe order ID as well, and I do not know how to get it...
Yep, that makes sense. One question: are you creating your own internal order ID before or after the Checkout Session?
after the checkout session
The order is submitted to my internal system upon completion of payment
Are you listening for checkout.session.completed events to know when the payment is complete?
Hmmm, no
I have a checkout button that has this simple code
<form action="/create-checkout-session" method="POST">
<input type="hidden" name="body" value={JSON.stringify(cart)}/>
<button type="submit">
Checkout
</button>
</form>
That redirects to stripe, then the other code I pasted redirects back to my success URL which is a separate page
It's important to know that someone can pay you successfully and then never land on your success URL. Imagine a scenario where someone on a train is checking out, pays you successfully, but then before they can be directed to your success URL the train goes into a tunnel and they lose their Internet connection. You need to use webhooks to confirm payments like that have happened and not rely only on your success URL.
interesting, I was unaware
So with my implementation, what would you recommend doing?:
From my checkout page, to the stripe checkout, then to the success url page. Where in those 3 steps?
You should add a Webhook Endpoint which listens for checkout.session.completed Events. There are more details here: https://stripe.com/docs/payments/checkout/fulfill-orders
This is an addition to what you're already doing, not something you change.
The only thing you'll need to change is your order logic. Right now it's only waiting for the success URL, but you need to change it so whichever happens first (the person landing on the success URL or you receiving the checkout.session.completed event) is the fulfillment trigger, and the second one that happens is a no-op.
Does that make sense? Happy to clarify further if not!
No problem!
Would you say that documentation covers pretty much everything I would need to add?
Just want to cover my bases before I go lol
ooo also - one more question. If I have multiple people checking out at once, will this still work?
Yep, it will still work with many people checking out at once as long as the code on your end accounts for that. 🙂