无法获取条带付款意图成功元数据



我是使用条纹支付的新手,所以我决定让它变得简单并从条纹文档中实现重定向到Checkout和条纹网络钩子,我按照步骤操作,首先我从stripe的仪表板创建了一个产品,然后我添加了一些元数据键和值,最后我在Angular上编写了代码,一切都运行良好,直到我意识到我没有获得预期的元数据, 实际上它是空的。

我正在使用Firebase云函数作为后端,使用Angular框架作为前端,这是我的代码:

stripe.redirectToCheckout({
lineItems: [{ price: itemSku, quantity: 1}],
mode: 'payment',
customerEmail: this.userEmail,
successUrl: 'http://localhost:4200/purchase/success',
cancelUrl: 'http://localhost:4200/purchase/failed'
})

火碱云功能

app.post('/webhook', bodyParser.raw({type: 'application/json'}), (request, response) => {
const sig = request.headers['stripe-signature'];
let event;
try {
event = stripe.webhooks.constructEvent(request.rawBody, sig, endpointSecret);
} catch (err) {
response.status(404).end()
}
const intent = event.data.object
switch (event.type) {
case constants.INTENT_SUCCESS:
// it prints the object with empty metadata
console.log('Success object:', intent);  <- metadata:{}
break;
case constants.INTENT_FAILED:
console.log('Failed:', intent.id);
break;
}
response.json({received: true});
response.sendStatus(200)
});

Stripe 中的每个对象都会有不同的元数据。听起来元数据已添加到Product对象中,该对象不会复制到PaymentIntent

我会侦听 webhook 通知事件类型的checkout.session.completed,然后获取结帐会话并扩展它相关的line_itemspriceproduct

const session = await stripe.checkout.sessions.retrieve(
"cs_test_xxx", {
expand: ["line_items.data.price.product"]
}
)
console.log(res.line_items.data[0].price.product);

最新更新