简体   繁体   中英

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.

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.

The request does not throw an error on Stripe's end, so I presume that the syntax is correct.

Is this lack of expansion due to being in test mode? If not, how can I tell Stripe to include the card's fringerprint?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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