简体   繁体   中英

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?

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.

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