【问题标题】:ASP.NET stripe.net Cannot charge a customer that has no active cardASP.NET stripe.net 无法向没有活动卡的客户收费
【发布时间】:2016-12-15 12:43:03
【问题描述】:
 protected void ChargePayment(object sender, EventArgs e)
    {
        StripeCustomer CurrentCustomer = GetCustomer();

        if (CurrentCustomer == null)
        {
            return;
        }


        var myCharge = new StripeChargeCreateOptions();


        myCharge.Currency = "dkk";
        myCharge.CustomerId = CurrentCustomer.Id;
        myCharge.Description = "KPHF Prorated Charge";

        string key = "sk_test_P6GjMq1OVwmxZv5YNozAX6dY";
        var chargeService = new StripeChargeService(key);

        try
        {
            chargeService.Create(myCharge);

        }
        catch (StripeException ex)
        {
            exError.Text = ex.Message;
        }


    }

    private StripeCustomer GetCustomer()
    {
        MembershipUser CurrentUser = Membership.GetUser();
        var myCustomer = new StripeCustomerCreateOptions();
        var myCustomer2 = new StripeCreditCardOptions();

        myCustomer.Email = cMail.Text;
        myCustomer2.TokenId = CreditCard.Text;
        myCustomer2.ExpirationMonth = CardMonth.SelectedItem.Text;
        myCustomer2.ExpirationYear = CardYear.SelectedItem.Text;
        myCustomer2.Cvc = cvc.Text;

        myCustomer.PlanId = "1";


        var customerService = new StripeCustomerService("sk_test_P6GjMq1OVwmxZv5YNozAX6dY");

        try
        {
            StripeCustomer result = customerService.Create(myCustomer);

            return result;
        }
        catch (StripeException ex)
        {
            exError.Text = ex.Message;
            return null;
        }

输入信用卡信息后,我确实在条带系统中创建了客户,但没有向他收费,并且我收到以下异常:“无法向没有活动卡的客户收费”。有什么帮助或提示吗?

【问题讨论】:

    标签: c# asp.net stripe.net


    【解决方案1】:

    您没有将卡片附在客户身上。您已创建卡片对象但未与客户关联。按照此语法添加卡片

    var myCustomer = new StripeCustomerCreateOptions();
        myCustomer.Email = "pork@email.com";
        myCustomer.Description = "Johnny Tenderloin (pork@email.com)";
    
        // setting up the card
        myCustomer.SourceCard = new SourceCard()
        {
            Number = "4242424242424242",
            ExpirationYear = "2022",
            ExpirationMonth = "10",
            Cvc = "1223"                          // optional
        };
    
        myCustomer.PlanId = *planId*;                          // only if you have a plan
        myCustomer.TaxPercent = 20;                            // only if you are passing a plan, this tax percent will be added to the price.
        myCustomer.Coupon = *couponId*;                        // only if you have a coupon
        myCustomer.TrialEnd = DateTime.UtcNow.AddMonths(1);    // when the customers trial ends (overrides the plan if applicable)
        myCustomer.Quantity = 1;                               // optional, defaults to 1
    
        var customerService = new StripeCustomerService();
        StripeCustomer stripeCustomer = customerService.Create(myCustomer)
    

    您可以在此处阅读更多信息 stripe .net

    【讨论】:

    • @ŽeniaBogdasic,如果答案满足您的要求,您应该接受帮助其他观众作为各自情况下的完美解决方案。
    • 它正在工作。谢谢
    猜你喜欢
    • 2022-01-27
    • 1970-01-01
    • 1970-01-01
    • 2021-01-05
    • 2017-03-17
    • 1970-01-01
    • 2017-11-05
    • 1970-01-01
    • 2015-05-25
    相关资源
    最近更新 更多