我使用带节点js的条来支付费用,我正在创建一个会话并使用条签出接口。我使用一个web钩子来听事件,当付款被创建或成功的时候,stripe发送payment_intent.succeeded,所以我用它做了一些事情。但问题是,当我单击cancel url取消付款时,stripe不取消付款,也不发送payment_intent.canceled,这是一个问题,因为我不知道是否取消了付款,我无法做我计划做的事情。这是我的代码:
// 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语句永远不会执行,因为如果付款被取消,条带不会发回任何东西。
发布于 2021-12-07 09:38:10
cancel_url
字段不会自动取消与CheckoutSession关联的PaymentIntent。
因此,预计不会发生这样的情况:
但问题是当我单击cancel url取消付款时,stripe不取消付款或发送payment_intent.canceled。
如果客户按下结账页面右上角的“后退”按钮,则cancel_url
用于取消付款页面。因此,它将是您的网站的网址,您指定的土地您的客户。
即使在导航到cancel_url
之后,CheckoutSession仍然是可用的(直到它手动过期或在创建后24小时默认过期为止),或者您的代码取消了基础PaymentIntent。
https://stackoverflow.com/questions/70264115
复制