简体   繁体   English

为关联帐户创建条带费用 - 没有此类客户

[英]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.我现在正在尝试创建一个直接的PaymentIntent ,它将付款路由到Stripe Connect连接的帐户。

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.这给了我错误“没有这样的客户”,即使定义了客户 ID 并且我可以在我的 Stripe 仪表板中找到该客户。 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.在您的第一个代码片段中,您没有指定stripeAccount ,因此在您的平台帐户上发出 API 请求。 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.在您的第二个代码片段中,您确实指定了一个stripeAccount ,这意味着 API 请求是在指定的连接帐户上发出的,而不是您的平台帐户。 You can read more about making API calls on connected accounts in Stripe's documentation .您可以在 Stripe 的文档中阅读有关对已连接帐户进行 API 调用的更多信息

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.要解决这种情况,您需要在您的平台帐户上创建支付意图作为目的地费用,或者在连接的帐户上创建客户 object 以便可以在那里使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM