Alk
Alk

Reputation: 5547

Create Stripe Charge for Connected Account - No Such Customer

I’ve successfully setup the Customers payment methods and am able to retrieve them using the following code:

return stripe.paymentMethods
       .list({ customer: customerId, type: 'card' })
       .then((cards) => {
            if (cards) {
               return { cards: cards.data, error: null };
            }
            return {
               error: 'Error creating client intent',
               cards: null,
             };
        })
        .catch((e) => {
           console.log(e);
           return { cards: null, error: 'Error fetching user cards' };
        });

I’m now trying to create a direct PaymentIntent that will route the payment to a Stripe Connect connected account.

To do this I’m running this code:

if (cards && cards.cards && cards.cards.length > 0) {
   const card = cards.cards[0];

   const paymentIntent = await stripe.paymentIntents.create(
    {
        amount: amount,
        customer: card.customer,
        receipt_email: userEmail,
        currency,
        metadata: {
            amount,
            paymentMode: chargeType,
            orderId,
        },
        description:
            'My First Test Charge (created for API docs)',
        application_fee_amount: 0,
    },
    {
        stripeAccount: vendorStripeAccount,
    }
);
const confirmedPaymentIntent = await stripe.paymentIntents.confirm(
    paymentIntent.id,
    { payment_method: card.id }
);

This gives me the error ‘No such customer’, even though the customer ID is defined and I can find the customer in my Stripe dashboard. I also see the customer’s payment methods there.

What am I doing wrong?

Upvotes: 1

Views: 1648

Answers (1)

Justin Michael
Justin Michael

Reputation: 6460

The problem is that the Customer exists on your platform account, not the connected account you're trying to create the Payment Intent on.

In your first code snippet you don't specify a stripeAccount, so that API request is being made on your platform account. The Customer exists there, which is why that works as expected.

In your second code snippet you do specify a stripeAccount, which means that API request is being made on the connected account specified, not your platform account. You can read more about making API calls on connected accounts in Stripe's documentation.

To resolve the situation you either need to create the Payment Intent on your platform account as a destination charge, or create the Customer object on the connected account so it can be used there.

Upvotes: 1

Related Questions