I am trying to make a direct payment with Stripe Connect via React Native. I included my Node.js backend function that creates the paymentIntent. These are the guides on the Stripe Docs I where following:
Creating PaymentIntent:
1: https://stripe.com/docs/payments/accept-a-payment?platform=react-native
Stripe Connect Create Direct Charge:
2: https://stripe.com/docs/connect/direct-charges
After following these two guides I got the error customer doesn't exist (customerID). Ok, so as far as I know this makes sense since I created a customer on the platform lvl and tried to use that customer to create the paymentIntent for the connected account that doesn't have that customer. So I researched further and found this:
Cloning Customers across accounts:
3: https://stripe.com/docs/connect/cloning-customers-across-accounts
This is exactly what I wan't since I am building a platform app where I don't wont the customer to reenter payment information every time.
If your platform uses the Payment Methods API, you must create a PaymentMethod from that customer
I am not sure but I think I need to do that? Ok, so I go to this link...
https://stripe.com/docs/payments/payment-methods/connect#cloning-payment-methods
Now, the say here: Create a PaymentMethod using the API or code a fixed test ID before making this request.
After clicking on the "fixed test ID" you get to this page:
https://stripe.com/docs/testing#cards
There is the test paymentMethod: "pm_card_visa". I use it, it doesn't work. Thats my problem. Please have a look at my commented code below to completely understand my problem.
app.post('/payment-sheet', async (req, res) => {
// Use an existing Customer ID if this is a returning customer.
const customer = await stripe.customers.create();
console.log("CUSTOMER_ID", customer.id);
const paymentMethod = await stripe.paymentMethods.create({
type: 'card',
card: {
number: '4242424242424242',
exp_month: 4,
exp_year: 2023,
cvc: '314',
},
});
console.log("PAYMENT_METHOD_ID", customer.id);
const clonedPaymentMethod = await stripe.paymentMethods.create({
customer: customer.id,
payment_method: paymentMethod.id,
}, {
stripeAccount: 'acct_1Ks7wyQ7pYORq1ll',
});
console.log("CLONED_PAYMENT_METHOD_ID", paymentMethod.id);
const clonedCustomer = await stripe.customers.create({
paymentMethod: clonedPaymentMethod.id,
}, {
stripeAccount: 'acct_1Ks7wyQ7pYORq1ll',
});
console.log("CLONED_CUSTOMER_ID", customer.id);
const paymentIntent = await stripe.paymentIntents.create({
amount: 1099,
customer: clonedCustomer.id,
paymentMethod: clonedPaymentMethod.id,
currency: 'eur',
automatic_payment_methods: {
enabled: true,
},
}, {
stripeAccount: 'acct_1Ks7wyQ7pYORq1ll',
});
res.json({
paymentIntent: paymentIntent.client_secret,
ephemeralKey: ephemeralKey.secret,
customer: customer.id,
publishableKey: 'pk_test_51If3LbLceO********************9xxLypLlBm24BXiP5FsLsb9TgNOwmHGCYYPKZsDoU000J8jVZmF'
});
});
CodePudding user response:
Test Cards are only available in the US. https://stripe.com/docs/testing#cards If you're not in the US you can't use the test cards and have to use. Use the international card that fits your country: https://stripe.com/docs/testing?numbers-or-method-or-token=payment-methods#international-cards
CodePudding user response:
This is the code I got it working with in the end. I needed to create a payment method for the platform customer first before cloning it.
app.post('/payment-sheet', async (req, res) => {
// Use an existing Customer ID if this is a returning customer.
const customer = await stripe.customers.create();
console.log("CUSTOMER_ID", customer.id);
const paymentMethod = await stripe.paymentMethods.create({
type: 'card',
card: {
number: '4242424242424242',
exp_month: 4,
exp_year: 2023,
cvc: '314',
},
});
console.log("PAYMENT_METHOD_ID", customer.id);
const clonedPaymentMethod = await stripe.paymentMethods.create({
customer: customer.id,
payment_method: paymentMethod.id,
}, {
stripeAccount: 'acct_1Ks7wyQ7pYORq1ll',
});
console.log("CLONED_PAYMENT_METHOD_ID", paymentMethod.id);
const clonedCustomer = await stripe.customers.create({
payment_method: clonedPaymentMethod.id,
}, {
stripeAccount: 'acct_1Ks7wyQ7pYORq1ll',
});
console.log("CLONED_CUSTOMER_ID", customer.id);
const ephemeralKey = await stripe.ephemeralKeys.create({
customer: clonedCustomer.id
}, {
apiVersion: '2020-08-27',
stripeAccount: 'acct_1Ks7wyQ7pYORq1ll',
},
);
console.log("EPHEMERAL_KEY", ephemeralKey.secret);
const paymentIntent = await stripe.paymentIntents.create({
amount: 1099,
customer: clonedCustomer.id,
payment_method: clonedPaymentMethod.id,
currency: 'eur',
automatic_payment_methods: {
enabled: true,
},
}, {
stripeAccount: 'acct_1Ks7wyQ7pYORq1ll',
});
res.json({
paymentIntent: paymentIntent.client_secret,
ephemeralKey: ephemeralKey.secret,
customer: clonedCustomer.id,
publishableKey: 'pk_test_51If3LbLceOiP5FsLsb9Tg********************NOwmHGCYYPKZsDoU000J8jVZmF'
});
});