最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there a callback function for stripe checkout success case? - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 4

If 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>
  )
}
发布评论

评论列表(0)

  1. 暂无评论