我能够成功创建一个令牌,然后创建一个新客户,将他们注册到特定的订阅计划中。
我无法弄清楚如何捕获Stripe为他们创建的customer_id。我需要这个以便稍后进行更改(更改计划,更新CC等)。我创建客户的代码如下(我使用读者获取fname,lname等,并在此处将其排除在外为简洁起见):
private StripeCustomer CreateCustomer()
{
NameValueCollection nvc = Request.Form;
string tokenID = nvc["stripeToken"];
if (tokenID != null)
{
var tokenService = new StripeTokenService();
StripeToken stripeToken = tokenService.Get(tokenID);
}
var myCustomer = new StripeCustomerCreateOptions();
myCustomer.Email = email;
myCustomer.Description = fname + " " + lname + " (" + email + ")";
myCustomer.TokenId = tokenID;
string plan = "basic";
myCustomer.PlanId = plan;
var customerService = new StripeCustomerService();
StripeCustomer CurrentCustomer = customerService.Create(myCustomer);
}
也许我正在考虑这个错误(必须),但我一直在寻找令牌来提供CustomerID。这是提供的内容:
id: tok_102znI2MdvjLMWitzgclEEcg
livemode: false
created: 1385241151
used: false
object: "token"
type: "card"
card:
id: card_102znI2MdvjLMWitq44B0MY7
object: "card"
last4: "4242"
type: "Visa"
exp_month: 12
exp_year: 2021
fingerprint: "V2WUOPIgMkP5DGGe"
customer: null
country: "US"
name: null
address_line1: null
address_line2: null
address_city: null
address_state: null
address_zip: null
address_country: null
在创建客户之前,令牌会传回给我,因此显然无效。
答案 0 :(得分:0)
Chris F有正确的想法。
在
StripeCustomer CurrentCustomer = customerService.Create(myCustomer);
我只需添加类似
的内容string custid = CurrentCustomer.id;
然后将custid添加到我的数据库中。
答案 1 :(得分:0)
您也可以通过以下方式执行此操作:
StripeCustomer currentCustomer = customerService.Create(myCustomer);
currentCustomer.StripeCardList.StripeCards.FirstOrDefault().CustomerId;