【问题标题】:Stripe.net Method not found: 'Void Stripe.StripeCustomerCreateOptions.set_Card(Stripe.StripeCreditCardOptions)'未找到 Stripe.net 方法:'无效 Stripe.StripeCustomerCreateOptions.set_Card(Stripe.StripeCreditCardOptions)'
【发布时间】:2016-12-11 08:41:58
【问题描述】:

我正在使用最新的 Stripe.net 版本

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

加注

[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);
}

和 SubscribeUserAsync:

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

【问题讨论】:

  • 我不确定他们是否对其进行了更多更新,但我们能否在您的控制器中看到更多的订阅代码?
  • @Alex Rohr 我更新了答案以显示控制器代码

标签: c# stripe.net


【解决方案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 附近遇到编译错误,我更新了完整控制器代码的答案
  • 另外我不确定你将如何存储卡(你的第三行评论),因为条纹用户是在帐户注册时创建的,用户没有提供信用卡。
  • 我的 user.CustomerIdentifier 将客户的 ID 附加到我的数据库并调用它。你必须把它添加到你的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多