首页 > 解决方案 > 如何使用共享客户创建直接收费?

问题描述

我正在尝试从我的平台直接向连接的帐户收费。Stripe 支持人员建议我使用共享客户来执行此操作,但这只会产生更多问题。

代码本身非常简单,如果它有效的话。src_...它使用 iOS 应用程序提供的令牌更新平台客户。这行得通。然后它尝试使用StripeTokenService(). 尽管遵循了信函的文档,但这不起作用。我收到的错误是:

您提供了一位客户但未指定来源。客户的默认来源是一个来源,不能与现有客户共享。

我看不到在 Stripe .Net SDK 中向共享客户提供源的方法。我所能提供的只是一个Cardor BankAccount,这两个我都不想做,因为 API 应该不知道敏感的用户信息。

我在这里到底做错了什么?

StripeConfiguration.SetApiKey(Settings.Stripe.SecretKey);
var businessRequestOptions = new StripeRequestOptions { StripeConnectAccountId = businessOwner.StripeAccountId };

var customerService = new StripeCustomerService();
customerService.Update(userDetail.StripeCustomerId, new StripeCustomerUpdateOptions
{    
  SourceToken = stripeToken // = 'src_...'
});

var tokenService = new StripeTokenService();
// this is the call that generates the error I mentioned above \/ \/ 
var token = tokenService.Create(new StripeTokenCreateOptions
{
  CustomerId = userDetail.StripeCustomerId // = 'cus_...'
}, businessRequestOptions);

// create a direct charge to the business account (taking out application fee)
var chargeService = new StripeChargeService();
var stripeCharge = chargeService.Create(new StripeChargeCreateOptions
{
  Amount = Convert.ToInt32(fee),
  Currency = currency,
  Description = $"Payment to {businessOwner.BusinessName} through Service X",
  ApplicationFee = applicationFee,
  SourceTokenOrExistingSourceId = token.Id, // use shared customerId here
}, businessRequestOptions);

标签: c#stripe-paymentsstripe.net

解决方案


使用Sources时,您必须使用此处记录的不同方法:https ://stripe.com/docs/sources/connect#shared-card-sources

这个想法是您要将源从平台“克隆”到连接的帐户。这是original_source在创建新源时使用的。然后,您将获得一个具有不同 ID 的新 Source 对象,src_XXXX然后您可以直接在连接的帐户上收费。


推荐阅读