Express 在签出期间在条带中检索客户ID

Express 在签出期间在条带中检索客户ID,express,stripe-payments,Express,Stripe Payments,我有一个条带结账,如果成功,我想检索客户ID。我遵循了Stripe教程,但它不适合我(签出工作正常,但我无法检索客户ID以将其添加到我的用户数据库) 我的代码: router.post("/create-checkout-session", ensureAuthenticated, async (req, res) => { const { priceId } = req.body; // See https://stripe.com/docs/api

我有一个条带结账,如果成功,我想检索客户ID。我遵循了Stripe教程,但它不适合我(签出工作正常,但我无法检索客户ID以将其添加到我的用户数据库)

我的代码:

router.post("/create-checkout-session", ensureAuthenticated, async (req, res) => {
    const { priceId } = req.body;

    // See https://stripe.com/docs/api/checkout/sessions/create
    // for additional parameters to pass.
    try {
      const session = await stripe.checkout.sessions.create({
        mode: "subscription",
        payment_method_types: ["card"],
        line_items: [
          {
            price: priceId,
            // For metered billing, do not pass quantity
            quantity: 1,
          },
        ],
        // {CHECKOUT_SESSION_ID} is a string literal; do not change it!
        // the actual Session ID is returned in the query parameter when your customer
        // is redirected to the success page.
        success_url: 'http://localhost:3000/fr/premiereconnexion?session_id={CHECKOUT_SESSION_ID}',
        cancel_url: 'https://localhost:3000/fr/erreursouscription',
      });
    
      res.send({
        sessionId: session.id,
        customerID: session.customer
      });
    }
    catch (e) {
    res.status(400);
    return res.send({
      error: {
        message: e.message,
      }
    });
  }
  }
});

您如何检索客户ID

您应该通过提取查询参数并通过对Stripe的API调用检索会话id来处理
successful\u url
,以获取
客户
:。因此,对于
success\u url
路由,您应该有一个
get(…)
路由


或者,收听
checkout.session.completed
webhook事件。

您如何检索客户ID

您应该通过提取查询参数并通过对Stripe的API调用检索会话id来处理
successful\u url
,以获取
客户
:。因此,对于
success\u url
路由,您应该有一个
get(…)
路由


或者,听听
checkout.session.completed
webhook事件。

这是否回答了您的问题?这回答了你的问题吗?