Stripe.net 方法未找到:'Void Stripe.StripeCustomerCreateOptions.set_Card(Stripe.StripeCreditCardOptions)'

4
我正在使用最新的Stripe.net版本。
await SubscriptionsFacade.SubscribeUserAsync(user, planId, taxPercent: taxPercent);

raises

[MissingMethodException: 方法未找到: 'Void Stripe.StripeCustomerCreateOptions.set_Card(Stripe.StripeCreditCardOptions)'。]

出了什么问题?我更新到最新版本,现在我的Stripe.net应用程序已经损坏了。Stripe引入了一种新的创建卡片的方式吗?

以下是完整的代码:

public async Task<ActionResult> Register(RegisterViewModel model)
{
    if (ModelState.IsValid)
    {
        var userIP = GeoLocation.GetUserIP(Request).Split(':').First();
        var user = new ApplicationUser
        {
            UserName = model.Email, 
            Email = model.Email,
            RegistrationDate = DateTime.UtcNow,
            LastLoginTime = DateTime.UtcNow,
            IPAddress = userIP,
            IPAddressCountry = GeoLocationHelper.GetCountryFromIP(userIP),
            BillingAddress = new BillingAddress()
        };
        var result = await UserManager.CreateAsync(user, model.Password);
        if (result.Succeeded)
        {
            // Create Stripe user
            var taxPercent = user.IPAddressCountry != null && EuropeanVat.Countries.ContainsKey(user.IPAddressCountry) ? 
                EuropeanVat.Countries[user.IPAddressCountry] : 0;

            // if no plan set, default to professional
            var planId = string.IsNullOrEmpty(model.SubscriptionPlan)
                ? "starter"
                : model.SubscriptionPlan;

            var customer = new StripeCustomerService();
            var customerInfo = customer.Get(user.CustomerIdentifier);

            await SubscriptionsFacade.SubscribeUserAsync(user, planId, taxPercent: taxPercent);
            await UserManager.UpdateAsync(user);

            await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
            await UserManager.EmailService.SendWelcomeEmail(user.UserName, user.Email);

            TempData["flash"] = new FlashSuccessViewModel("Congratulations! Your account has been created.");

            return RedirectToAction("Index", "Notes");
        }
        AddErrors(result);
    }

    // If we got this far, something failed, redisplay form
    return View(model);
}

并订阅用户异步:

https://github.com/pedropaf/saas-ecom/blob/1370ac169807e97ffb7414610d5be4de4a3cc9ae/SaasEcom.Core/Infrastructure/Facades/SubscriptionsFacade.cs


我不确定他们是否进行了更新,但我们能否在您的控制器中看到更多的订阅代码呢? - Alex Rohr
@Alex Rohr,我更新了我的答案以显示控制器代码。 - user299709
1
曾经遇到过类似的问题,更新了所有必需项目的stripe.net后,这个问题已经得到解决。 - Nayeem Bin Ahsan
1个回答

1
据我所知,SubscribeUserAsync在调用时需要一个卡片。
private async Task<Subscription> SubscribeUserAsync
(SaasEcomUser user, string planId, CreditCard creditCard, int trialInDays = 0, decimal taxPercent = 0)

或者

public async Task<Subscription> SubscribeUserAsync
(SaasEcomUser user, string planId, decimal taxPercent = 0, CreditCard creditCard = null)

由于您正在订阅用户,因此可能需要与之配套的信用卡。我建议通过创建令牌或调用现有令牌来添加信用卡。

 var customer = new StripeCustomerService();
 var customerInfo = customer.Get(user.CustomerIdentifier);
 //then store card with  customerInfo.DefaultSourceId  somewhere and use it

我在 user.CustomerIdentifier 周围遇到了编译错误,我更新了完整控制器代码的答案。 - user299709
我也不确定你会如何存储卡片(你第三行的评论),因为Stripe用户是在注册帐户时创建的,用户没有提供信用卡。 - user299709
我的 user.CustomerIdentifier 将客户的 ID 附加到我的数据库并调用它。你需要将它添加到你的数据库中。 - Alex Rohr

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接