简体   繁体   English

成功条带结帐后调用端点

[英]Call endpoint after successful stripe checkout

I'm trying to find a way after I get a successful payment on stripe to call a server endpoint to send a custom a email with data from my database.在我成功通过条带付款后,我试图找到一种方法来调用服务器端点以发送自定义 email 与我的数据库中的数据。

Frontend Code

 function checkout(session) {
        stripe
          .redirectToCheckout({
            sessionId: session,
          })
          .then(function (result) {})
          .catch((err) => {
            console.log(err);
          });
      }

backend code

   const session = await stripe.checkout.sessions.create({
      payment_method_types: ["card"],
      line_items: [
        {
          price: "MY_PLAN_ID",
          quantity: 1,
        },
      ],
      mode: "subscription",
      success_url:
        "http://localhost:3000/success?session_id={CHECKOUT_SESSION_ID}",
      cancel_url: "http://localhost:3000/purchase",
    });
    res.status(200).json({ success: true, checkout: session.id });

You don't really need an endpoint.你真的不需要端点。 you can call a function inside your node server the handle the email.您可以在节点服务器中调用 function 处理 email。 If you intend to send the email from another server, then you'll need to setup an endpoint there, you can trigger it by sending a request with Request or any other package.如果您打算从另一台服务器发送 email,那么您需要在那里设置一个端点,您可以通过使用Request或任何其他 package 发送请求来触发它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM