向现有客户添加信用卡源时出现问题



我尝试向现有客户添加新的信用卡,但收到此错误:

收到的未知参数:卡

我想出了如何使用StripeTokenService来检索卡指纹来验证卡是否已存在,但是我无法尝试将该卡添加到客户。

我的代码如下所示:

var sourceService = new Stripe.StripeSourceService();
// Get customer with current payment source.
var stripeCustomer = customerService.Get(stripeCustomerWithAccount.Id, new Stripe.StripeRequestOptions { ApiKey = ConfigurationManager.AppSettings["StripeSecretKey"] });
// Set Stripe Customer Id and Stripe Token options.
var tokenService = new Stripe.StripeTokenService();
var stripeToken = tokenService.Get(tokenId, new Stripe.StripeRequestOptions { ApiKey = ConfigurationManager.AppSettings["StripeSecretKey"] });
// Check if credit card already exists.
if (!CreditCardExists(stripeCustomer, stripeToken))
{
// Create new credit card.
var sourceOptions = new StripeNet.StripeSourceCreateOptions()
{
Customer = stripeCustomer.Id,
Card = new StripeNet.StripeCreditCardOptions
{
TokenId = stripeToken.StripeCard.Id 
}                            
};
var source = sourceService.Create(sourceOptions, new Stripe.StripeRequestOptions { ApiKey = ConfigurationManager.AppSettings["StripeSecretKey"] });
}

好的,我想出了方法,我将分享我的答案:

if (!CreditCardExists(stripeCustomer, stripeToken))
{ 
var creditCardService = new StripeNet.StripeCardService();
var creditCardOptions = new StripeNet.StripeCardCreateOptions { SourceToken = tokenId };
var creditCard = creditCardService.Create(stripeCustomer.Id, creditCardOptions, new StripeNet.StripeRequestOptions { ApiKey = ConfigurationManager.AppSettings["StripeSecretKey"] });
// The only way I found to get customer with all sources...
stripeCustomer = customerService.Get(stripeCustomerWithAccount.Id, new StripeNet.StripeRequestOptions { ApiKey = ConfigurationManager.AppSettings["StripeSecretKey"] });
}

最新更新