首页 > 解决方案 > 我如何确保客户不会跳过带有条纹的付费专区?

问题描述

我正在建立一个模型类似于 Fiverr 的市场。您为服务付费,付款后,您可以填写您希望卖家提供的偏好。我面临的问题是付款后的成功链接可以直接复制并粘贴到不付款的首选项页面。我如何确保条纹不会发生这种情况。这是我的服务器代码:

//checkout stripe session code:
 app.post('/create-checkout-session', async (req, res) => {
 const {request} = req;
 const account_id = req.body.account_id;
 const user_id = req.body.user_id;
 var successLink = 'http://localhost:3000/dashboard/userreq/'+user_id;
 console.log('request: ' + req.body.account_id);
 const session = await stripe.checkout.sessions.create({
  payment_method_types: ['card'],
  line_items: [
    {
    price_data: {
      currency: 'usd',
      product_data: {
        name: 'Story',
      },
      unit_amount: 1300,
    },
    quantity: 1,
  },
],
payment_intent_data: {
application_fee_amount: 123,
transfer_data: {
  destination: account_id,
 },
},
mode: 'payment',
success_url: successLink,
cancel_url: 'http://localhost:3000/cancel.html',
});
 res.send({
sessionId: session.id,
 });});
//webhook to see if payment was successful
app.post('/webhook', bodyParser.raw({type: 'application/json'}), (request, response) => {
  const sig = request.headers['stripe-signature'];

  let event;

  // Verify webhook signature and extract the event.
  // See https://stripe.com/docs/webhooks/signatures for more information.
  try {
    event = stripe.webhooks.constructEvent(request.body, sig, endpointSecret);
  } catch (err) {
    return response.status(400).send(`Webhook Error: ${err.message}`);
  }

  if (event.type === 'checkout.session.completed') {
    const session = event.data.object;
    handleCompletedCheckoutSession(session);
  }

  response.json({received: true});
});

const handleCompletedCheckoutSession = (session) => {
  // Fulfill the purchase.
  console.log(JSON.stringify(session));
}

app.listen(process.env.PORT || 8080, () => {
  console.log("Server started...");
});

标签: stripe-payments

解决方案


您希望在成功 URL 中编码结帐会话 ID:https ://stripe.com/docs/payments/checkout/custom-success-page#modify-success-url

然后,当您的成功页面被点击时,您将通过从后端检索 Checkout Session 并检查其来检查会话 ID 是否有效payment_statushttps ://stripe.com/docs/api/checkout/sessions/object# checkout_session_object-payment_status

如果没有会话 ID 或payment_statusis not paid,那么您将不会授予对您正在销售的任何内容的访问权限。


推荐阅读