I am using stripe for checkout and i want to create an order in my data base when the chechout succeed. Do you know how can I run a callback function when the checkout succeed? All I know is that there is a successUrl for the checkout...
I am using stripe for checkout and i want to create an order in my data base when the chechout succeed. Do you know how can I run a callback function when the checkout succeed? All I know is that there is a successUrl for the checkout...
Share Improve this question asked Nov 12, 2022 at 12:35 ofek leviofek levi 591 silver badge4 bronze badges 3- Which endpoint are you using exactly? – kind user Commented Nov 12, 2022 at 12:39
- I am creating a stripe checkout seassion with stripe.checkout.sessions.create() , and then I am redirecting the client to checkoutSession.url – ofek levi Commented Nov 12, 2022 at 12:48
- Maybe just wrap the request with try...catch and look for the success response? – kind user Commented Nov 12, 2022 at 13:12
2 Answers
Reset to default 4If you use Checkout Session to collect payment, customer will be redirected to the success_url
declared after pleting the payment. In addition, Stripe will also send checkout.session.pleted
event via Webhook. I'd remend listening to checkout.session.pleted
to create and fulfil customer's order: https://stripe./docs/payments/checkout/fulfill-orders
If you are using the EmbeddedCheckout
ponent, a callback named onComplete
can be specified.
https://stripe./docs/payments/checkout/custom-redirect-behavior#disable-redirects
const App = ({clientSecret}) => {
const [isComplete, setIsComplete] = useState(false);
const handleComplete = () => setIsComplete(true);
return isComplete ? (
<PurchaseSummary />
) : (
<EmbeddedCheckoutProvider
stripe={stripePromise}
options={{
clientSecret,
onComplete: handleComplete
}}
>
<EmbeddedCheckout />
</EmbeddedCheckoutProvider>
)
}