Stripe取消url不会取消付款,因此Stripe不会发送取消付款意向



我正在使用节点js的stripe进行支付,我正在创建一个会话并使用stripe结账界面。当支付创建或成功时,我使用网络挂钩来监听事件,因此stripe发送payment_intent.successed,所以我用它做了一些事情。但问题是,当我点击取消url取消支付时,stripe不会取消付款或发送payment_intent.canced,这是一个问题,因为我不知道付款是否被取消,我不能做我计划做的事情。这是我的代码:

// This will share the stripe publickey with the frontend
const webhook = async (req, res) => {
// Signature verification
const playload = req.body;
const sig = req.headers["stripe-signature"];
const endpointSecret = process.env.STRIPE_WEBHOOK_SECRET;
let event;
try {
// Checking if the response is actually from stripe
event = stripe.webhooks.constructEvent(playload, sig, endpointSecret);
} catch (error) {
console.log(error.message);
res.status(400).json({ success: false });
return;
}
// Getting the ad id
const adID = event.data.object.metadata.id;
const userEmail = event.data.object.metadata.email;
// Checking if the payment did faile
if (
event.type === "payment_intent.canceled" ||
event.type === "charge.failed" ||
event.type === "charge.expired"
) {
const paymentIntent = event.data.object;
console.log(`PaymentIntent ${paymentIntent.status}`);
// Sending the deleting request
await axios.delete(`${process.env.SERVER_URL}/api/v1/single-ad`, {
data: { id: adID, email: userEmail },
});
return res.status(200).json({ message: "Ad is successfully deleted" });
}

if语句永远不会执行,因为如果付款被取消,stripe不会发回任何东西。

CheckoutSession上的cancel_url字段不会自动取消与CheckoutSession关联的PaymentIntent。

因此,预计不会发生这种情况:

但问题是,当我点击取消url取消付款时,stripe不会取消付款或发送payment_intent.canced

cancel_url用于如果客户按下";背面";按钮,以取消付款页面。因此,它将是你指定的网站的URL,让你的客户登陆。

即使在导航到cancel_url之后,CheckoutSession仍然可用(直到它手动过期或默认在创建后24小时过期(,或者您的代码取消了基本的PaymentIntent。

最新更新