gpt4 book ai didi

c# - ASP.NET stripe.net 无法向没有事件卡的客户收费

转载 作者:太空宇宙 更新时间:2023-11-03 21:09:11 24 4
gpt4 key购买 nike

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

输入信用卡信息后,我确实在条纹系统中创建了客户,但他没有被收费,我得到以下异常:“无法向没有事件卡的客户收费”。有任何帮助或提示吗?

最佳答案

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

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

关于c# - ASP.NET stripe.net 无法向没有事件卡的客户收费,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38851250/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com