c# - 如何使用共享客户创建直接收费?
问题描述
我正在尝试从我的平台直接向连接的帐户收费。Stripe 支持人员建议我使用共享客户来执行此操作,但这只会产生更多问题。
代码本身非常简单,如果它有效的话。src_...
它使用 iOS 应用程序提供的令牌更新平台客户。这行得通。然后它尝试使用StripeTokenService()
. 尽管遵循了信函的文档,但这不起作用。我收到的错误是:
您提供了一位客户但未指定来源。客户的默认来源是一个来源,不能与现有客户共享。
我看不到在 Stripe .Net SDK 中向共享客户提供源的方法。我所能提供的只是一个Card
or 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);
解决方案
使用Sources时,您必须使用此处记录的不同方法:https ://stripe.com/docs/sources/connect#shared-card-sources
这个想法是您要将源从平台“克隆”到连接的帐户。这是original_source
在创建新源时使用的。然后,您将获得一个具有不同 ID 的新 Source 对象,src_XXXX
然后您可以直接在连接的帐户上收费。
推荐阅读
- javascript - console.log 多行格式化的行
- git - 使用 git rebase 不小心将其他人的提交添加到我的 PR
- javascript - Javascript 代码在 Mozilla Firefox 中运行,但在 Google Chrome 中不运行
- c# - C# 和 Angular - 跨源错误
- laravel-5.4 - 未定义的属性:Illuminate\Database\Eloquent\Relations\HasMany::$id
- javascript - 尝试运行测试时找不到AngularJS指令?
- c++ - 如何将 C++ 控制台应用程序放入系统托盘通知?
- c++11 - 有没有一种高性能的方法来制作一个 56 位整数?
- go - Go 的 net.Listener Addr() 是做什么用的?
- node.js - 在对话框流节点 js 应用程序中获取请求权限意图响应的问题