【问题标题】:Problem adding credit card source to an existing customer向现有客户添加信用卡来源时出现问题
【发布时间】:2023-04-10 13:03:01
【问题描述】:

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

收到未知参数:卡

我知道如何使用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"] });
}

【问题讨论】:

    标签: c# stripe-payments


    【解决方案1】:

    好的,我想通了,我将分享我的答案:

    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"] });
    }
    

    【讨论】:

      猜你喜欢
      • 2015-05-08
      • 1970-01-01
      • 2011-11-13
      • 1970-01-01
      • 1970-01-01
      • 2017-04-20
      • 2012-04-07
      • 1970-01-01
      • 2019-03-03
      相关资源
      最近更新 更多