问题描述
我正在尝试使用以下逻辑为未经身份验证的客户实施结帐程序:
-
收集客户电子邮件
-
使用以下逻辑生成 Stripe 客户:
const customer = await stripe.customers .create({ email,name,}) .then((customer) => customer) .catch((error) => { console.log(error); return null; });
-
创建令牌以将帐户传递给我的 Stripe Connect 业务合作伙伴帐户。
const tempCustomerToken = await stripe.tokens.create( { customer: customerAccId,},{ stripeAccount: vendorStripeAcc,} );
-
根据业务合作伙伴的帐户创建客户。
const tempCustomer = await stripe.customers.create( { source: tempCustomerToken.id,} );
-
使用来自业务合作伙伴的客户 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 },} );
这在第 2 步中失败并出现此错误 - The customer must have an active payment source attached.
但是,我希望客户在 Stripe Checkout
会话期间提供他们的付款方式,因此当我创建客户时,我不想要求他们提供任何付款信息。
有没有办法实现以下目标:
- 使用电子邮件创建 Stripe 客户,而我的 Stripe 账户上没有付款方式。
- 与
Stripe Connect
业务合作伙伴共享此客户。 - 允许客户使用
Stripe Checkout
会话在direct
业务供应商帐户上进行Stripe Connect
购买。
解决方法
当您希望在平台账户上拥有客户和一张卡,然后在连接的账户上克隆该卡以接受一次性付款时,将使用您所描述的流程。这个想法是,作为一个平台,您可以一次性收集卡的详细信息,并且可以代表第三方供应商接受未来的付款。
当您执行此操作时,平台中的客户与关联帐户上的客户没有任何关联或关联。它们只是 2 个独立的对象,您可以克隆卡片一次以避免再次收集卡片详细信息。
在您的示例中,尽管您没有卡片,也不想收集卡片。这意味着没有理由在平台帐户上创建客户或尝试在连接的帐户上克隆它。您似乎只想接受关联帐户的付款。
您应该完全跳过所有步骤,而只是在连接的帐户上创建结帐会话。当您完成 Checkout 时,它会收集卡详细信息、接受付款并在连接的帐户上为您创建客户以保存卡详细信息以备将来付款。
您将无法在平台上使用该客户或其卡,但按照 Stripe Connect 的构建方式,这部分是预期的。