我如何确保客户不会跳过带有条纹的付费专区?
How do I make sure customers don't skip paywall with stripe?
我正在构建一个模型类似于 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...");
});
您希望在成功中对结帐会话 ID 进行编码 URL:https://stripe.com/docs/payments/checkout/custom-success-page#modify-success-url
然后当您的成功页面被点击时,您将通过从后端检索结帐会话并检查其 payment_status
来检查会话 ID 是否有效:https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-payment_status
如果没有会话 ID 或者 payment_status
不是 paid
,那么您将不会授予对您销售的任何内容的访问权限。
我正在构建一个模型类似于 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...");
});
您希望在成功中对结帐会话 ID 进行编码 URL:https://stripe.com/docs/payments/checkout/custom-success-page#modify-success-url
然后当您的成功页面被点击时,您将通过从后端检索结帐会话并检查其 payment_status
来检查会话 ID 是否有效:https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-payment_status
如果没有会话 ID 或者 payment_status
不是 paid
,那么您将不会授予对您销售的任何内容的访问权限。