简体   繁体   English

Stripe API:展开嵌套的卡片元素

[英]Stripe API: expand nested card element

I use a Stripe Checkout session to set up a payment intent and want to expand the card property, nested three levels deep.我使用 Stripe Checkout 会话来设置付款意图,并希望扩展嵌套三层的卡片属性。

According to the documentation , I can expand a property and a sub-property with dot-notation:根据文档,我可以用点符号扩展一个属性和一个子属性:

  const session = await stripe.checkout.sessions.retrieve(session_id, {
    expand: ["setup_intent.payment_method"]
  });

Then I receive this response:然后我收到这个回复:

{
  id: 'cs_test...",
  ...
  setup_intent: {
    id: 'seti_1MDYkcAphQbVdSksInihHamA',
    ...
    payment_method: {
      id: 'pm_1MDYknAphQbVdSks1a1eohA7',
      object: 'payment_method',
      billing_details: [Object],
      card: [Object],
      ...
      type: 'card'
    },
  ...
}

I would like to also expand the card to get the fingerprint and check if it is a duplicate.我还想扩展卡以获取指纹并检查它是否重复。 So I use this:所以我用这个:

  const session = await stripe.checkout.sessions.retrieve(session_id, {
    expand: ["setup_intent.payment_method.card"]
  });

But the result is the same as above: card: [Object] and it does not show the card's fingerprint.但是结果和上面一样: card: [Object]并且没有显示卡的指纹。

The request does not throw an error on Stripe's end, so I presume that the syntax is correct.该请求不会在 Stripe 端引发错误,因此我认为语法是正确的。

Is this lack of expansion due to being in test mode?是否由于处于测试模式而缺乏扩展? If not, how can I tell Stripe to include the card's fringerprint?如果没有,我如何告诉 Stripe 包含卡的指纹?

The problem is due to the fact that you are printing out a nested object.问题是由于您正在打印嵌套对象这一事实。 Even if the printed result is shown that way, the object properties are there and you can still use them.即使以这种方式显示打印结果,对象属性仍然存在,您仍然可以使用它们。

You can confirm by running:您可以通过运行来确认:

console.log(setup_intent.payment_method.card.fingerprint);

You'll find the card object fingerprint and documentation here: https://stripe.com/docs/api/payment_methods/object#payment_method_object-card您可以在此处找到卡对象指纹和文档: https ://stripe.com/docs/api/payment_methods/object#payment_method_object-card

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM