Reputation: 82
I'm getting the error: Invalid token ID when creating a paymentIntent
through the Stripe API (NodeJS).
The following works:
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
},
},
})
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 to this:
stripe.paymentIntents
.create({
amount: 1000,
application_fee_amount: 100, // added this
confirm: true,
currency: "gbp",
description: "payment",
payment_method_types: ["card"],
payment_method_data: {
type: "card",
card: {
token: customerCard.id,
},
},
}, { stripeAccount: "{{ ACTUAL_CONNECT_ACCOUNT_ID_IS_HERE }}"}) // added this
The call fails (in my try catch) with "Error: Invalid token Id: tok_abc..."
I don't understand why the paymentIntent
is being created without error in the first case, but as soon as I try to create another paymentIntent
using direct charge on the connect account, and taking an application fee (as per the docs), and using the exact same method to generate a new card/token (with the same stripe test card), the paymentIntent
fails and the token which was fine before is now invalid. The error seems misleading or at least obscured.
I'm generating a new card token client side on each payment attempt exactly as per the guide, using this package: https://github.com/expo/stripe-expo. 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_ID_IS_HERE}" }
);
return stripeClient.createToken({ card });
Getting what looks to be a valid token every time.
Can someone please help?
Thanks
Upvotes: 1
Views: 1287
Reputation: 3321
You're using Stripe's ReactNative SDK (via Expo), it looks like.
Serer-side, you are creating a PaymentIntent on the Connect account with the
}, { stripeAccount: "{{ ACTUAL_CONNECT_ACCOUNT_ID_IS_HERE }}"}) // added this
part.
Similarly, you need to create the Token on the Connect account as well.
You can do this by passing stripeAccountId: acct_123
when you construct StripeProvider
in your ReactNative code: https://stripe.dev/stripe-react-native/api-reference/interfaces/StripeProviderProps.html#stripeAccountId
where acct_123 is the same account ID you're passing when you create your PaymentIntent server-side.
That would mean your Token creation would happen not on the Platform, but on the Connect account.
Upvotes: 0