无法获得条纹付款意图成功元数据

时间:2020-06-18 17:22:30

标签: javascript angular firebase google-cloud-functions stripe-payments

我是新来的使用条带支付的人,所以我决定简化操作并从条带文档中实现redirectToCheckout和条带Webhooks,按照步骤操作,首先从条带的仪表板创建产品,然后添加一些元数据密钥并值,最后我在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'
})

Firebase云功能

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)
});

1 个答案:

答案 0 :(得分:2)

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

我将监听checkout.session.completed Webhook通知事件类型,然后获取Checkout会话,并expandingline_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);