如何使用共享客户创建直接收费



我正试图从我的平台直接向连接的帐户收费。Stripe支持部门建议我使用共享客户来实现这一点,但这只会产生更多问题。

代码本身非常简单,如果它有效的话。它使用iOS应用程序提供的src_...令牌更新平台客户。这是有效的。然后,它尝试使用StripeTokenService()创建一个共享客户。尽管严格遵循了文件,但这并不奏效。我收到的错误是:

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

我看不到在Stripe.Net SDK中为共享客户提供源代码的方法。我所能提供的只是一个CardBankAccount,这两个我都不想做,因为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);

当使用Sources时,您必须使用不同的方法,此处对此进行了说明:https://stripe.com/docs/sources/connect#shared-卡片来源

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

最新更新