为 stripe 关联帐户创建客户 node.js

create customer for stripe connected account node.js

我有这个:

 const paymentMethod = await stripe.paymentMethods.create({
    type: 'card',
    card: {
      number: '4242424242424242',
      exp_month: 1,
      exp_year: 2024,
      cvc: '123',
    },
  });

  console.log(paymentMethod.id)
  const customer = await stripe.customers.create({
    payment_method: paymentMethod.id,
  });

它的作用是创建一种付款方式,然后 link 将其发送给我当场创建的客户。但是,我需要为 stripeAccount 创建客户,而不是我自己的客户。我还以编程方式为我的商家创建条带帐户,所以现在我想 link 我为特定商家创建的客户。

这是我发现您可以为 paymentIntents 执行的操作,我认为您可以为 stripe 帐户执行此操作,但事实并非如此:

const paymentIntent = await stripe.paymentIntents.create({
    amount: 2000,
    currency: 'usd',
    customer: customerid
  }, {
    stripeAccount: 'myaccount_id',
});

那么我如何在创建客户时使用 stripeAccount

您可以对任何 API 请求使用 stripeAccount,它对所有请求的工作方式相同。 Stripe 的文档中直接有一个示例: https://stripe.com/docs/connect/authentication#stripe-account-header

const customer = await stripe.customers.create(
  {email: 'person@example.edu'},
  {stripeAccount: '{{CONNECTED_STRIPE_ACCOUNT_ID}}'}
);

顺便说一句,还请注意您的集成似乎有点不对劲——您永远不应该使用这样的原始卡详细信息调用 stripe.paymentMethods.create,除非您想要大量的 PCI 合规性头痛(https://stripe.com/docs/security/guide#validating-pci-compliance 在“API直接”)。您应该使用 Stripe 的前端,例如 Elements/Checkout.