stripe-payments - 我如何确保客户不会跳过带有条纹的付费专区?
问题描述
我正在建立一个模型类似于 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...");
});
解决方案
您希望在成功 URL 中编码结帐会话 ID:https ://stripe.com/docs/payments/checkout/custom-success-page#modify-success-url
然后,当您的成功页面被点击时,您将通过从后端检索 Checkout Session 并检查其来检查会话 ID 是否有效payment_status
:https ://stripe.com/docs/api/checkout/sessions/object# checkout_session_object-payment_status
如果没有会话 ID 或payment_status
is not paid
,那么您将不会授予对您正在销售的任何内容的访问权限。
推荐阅读
- c++ - 如何使用 Arduino 步进电机前后移动?
- python - 如何在 BS4 中添加嵌套的 DIV
- php - 恐惧到 EOF?限制
- python - 来自 json 的不同数量的字段以将其加载到 Python Pandas 数据框中
- android - 访问 Recycler´s Adapter 中的 ViewModel
- c# - Microsoft.Azure.KeyVault.Models.KeyVaultErrorException:“拒绝访问第一方服务。”
- java - 如何将 JDBC Swing Worker 与连接池一起使用(最好是在分离 SQL 和应用程序逻辑时)?
- php - Google Search Console API 组结果
- python - 数字图像的预测方式不同
- amazon-web-services - 无法通过 Lake Formation 授予对 Glue 表的跨账户访问权限