Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid token ID error #44

Open
g-hamilton opened this issue Sep 3, 2021 · 0 comments
Open

Invalid token ID error #44

g-hamilton opened this issue Sep 3, 2021 · 0 comments

Comments

@g-hamilton
Copy link

Hi, I'm not sure if this is a "stipe-expo" issue but I suspect it might be because it relates to a token I'm trying to generate using this library. So forgive me if not ;)

I'm getting the error: Invalid token ID when creating a paymentIntent through the official "stripe" node.js library on my back end.

I can process a simple payment where my platform charges a customer card token. This works fine:

stripe.paymentIntents
    .create({
      amount: 100,
      confirm: true,
      currency: "gbp",
      description: "payment",
      payment_method_types: ["card"],
      payment_method_data: {
        type: "card",
        card: {
          token: customerCard.id, // token generated on the client side (see below for code)
        },
      },
    })

But now I want to move away from a 'simple' charge to a 'direct' charge flow using Stripe Connect, as per this guide: https://stripe.com/docs/connect/direct-charges

If I amend my code as per the guide so that I'm trying to generate the card token on the connect account (rather than my platform stripe account), and then create the paymentIntent to create the charge on the connect account:

stripe.paymentIntents
    .create({
      amount: 1000,
      application_fee_amount: 100, // trying to take a fee now
      confirm: true,
      currency: "gbp",
      description: "payment",
      payment_method_types: ["card"],
      payment_method_data: {
        type: "card",
        card: {
          token: customerCard.id, // token generated using the connect account id (see below for code)
        },
      },
    }, { stripeAccount: "{{ ACTUAL_CONNECT_ACCOUNT_ID_IS_HERE }}"}) // so that we're creating the charge on the connect account

The call fails (in my try catch) with "Error: Invalid token Id: tok_abc..."

Here's how I'm generating the token:

import createStripe from "stripe-client"; // https://github.com/expo/stripe-expo

...

// init a new instance of stripe client passing the ID of the connected account to create the token on that account
  const stripeClient = createStripe(
    "pk_test_5...gKi",
    { stripeAccount: "{ ACTUAL_CONNECT_ACCOUNT_ID_IS_HERE }" }
  );
  return stripeClient.createToken({ card });

I am getting what looks to be a valid token before passing it to the back end so I'm really stuck as to the reason the token is invalid.

Can someone please help?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant