Stripe - 使用 Stripe Connect 创建结帐会话

Stripe - Create Checkout Session with Stripe Connect

我正在尝试使用以下逻辑为未经身份验证的客户实施结帐程序:

  1. 收集客户电子邮件

  2. 使用以下逻辑生成 Stripe 客户:

    const customer = await stripe.customers
     .create({
         email,
         name,
     })
     .then((customer) => customer)
     .catch((error) => {
         console.log(error);
         return null;
     });
    
  3. 创建令牌以将帐户传递到我的 Stripe Connect 业务合作伙伴帐户。

    const tempCustomerToken = await stripe.tokens.create(
             {
                 customer: customerAccId,
             },
             {
                 stripeAccount: vendorStripeAcc,
             }
         );
    
  4. 根据业务伙伴的账户创建客户

    const tempCustomer = await stripe.customers.create(
             {
                 source: tempCustomerToken.id,
             },
             {
                 stripeAccount: vendorStripeAcc,
             }
         );
    
  5. 使用业务合作伙伴帐户中的客户 ID 创建结账会话

    const session = await stripe.checkout.sessions.create(
             {
                 payment_method_types: ['card', 'alipay'],
                 customer: tempCustomer.id,
                 line_items: items,
                 success_url: 'https://example.com/success',
                 cancel_url: 'https://example.com/cancel',
                 payment_intent_data: {
                     application_fee_amount: 50
                 },
             },
             {
                 stripeAccount: vendorStripeAcc,
             }
         );
    

步骤 2 失败并出现此错误 - The customer must have an active payment source attached.

但是,我希望客户在 Stripe Checkout 会话期间提供他们的付款方式,因此当我创建客户时,我不想向他们询问任何付款信息。

有没有办法实现以下目标:

  1. 使用电子邮件创建 Stripe 客户,但在我的 Stripe 账户上没有付款方式。
  2. Stripe Connect 业务伙伴分享此客户。
  3. 允许客户使用 Stripe Checkout 会话在 Stripe Connect 企业供应商帐户上进行 direct 购买。

当您想在平台帐户上拥有一个客户和一张卡,然后在连接的帐户上克隆该卡以接受一次性付款时,将使用您描述的流程。这个想法是,作为一个平台,您只需收集一次银行卡详细信息,就可以代表第三方供应商接受未来的付款。

当您执行此操作时,平台中的客户和连接帐户中的客户没有任何关联或关联。它们只是 2 个独立的对象,您可以克隆一次卡片以避免再次收集卡片详细信息。

在你的例子中你没有卡片也不想收集卡片。这意味着没有理由在平台帐户上创建客户或尝试在连接的帐户上克隆它。您似乎只想接受关联帐户的付款。

您应该完全跳过所有步骤,而只是在连接的帐户上创建一个结帐会话。在您结帐时,它将收集银行卡详细信息、接受付款并在连接的帐户上为您创建一个客户以保存银行卡详细信息以供将来付款。

您将无法在平台上使用该客户及其卡,但 Stripe Connect 的构建方式预计该部分。