我正在使用 Checkout
在我的 ASP.NET Core 应用程序中实现 Stripe .
我知道如何使用 Checkout
获取用于向信用卡收费的 token 但是我从哪里获得 token 来创建客户?
在文档中,我看到我需要获取 token 才能创建客户,但不确定该 token 的来源。
https://stripe.com/docs/api/dotnet#create_customer
据我所知,一个 token 只能使用一次,所以它不能与我在信用卡收费之前获得的 token 相同。
最佳答案
正如我在此引用的条纹 document
When you collect a customer's payment information, a Stripe token is created. This token can only be used once, but that doesn't mean you have to request your customer's card details for every payment.
Stripe provides a Customer object that makes it easy to save this—and other—information for later use. You can use Customer objects for creating subscriptions or future one-off charges.
你需要做的就是创建一个你已经拥有的客户
来自客户的卡详细信息并向该客户收费。
使用以下代码片段执行此操作,这样您将创建一个客户并使用单个 token 进行收费
StripeConfiguration.SetApiKey(secret_key_of_your_account);
var token = model.Token; // Using ASP.NET MVC
var customers = new StripeCustomerService();
var charges = new StripeChargeService();
var customer = customers.Create(new StripeCustomerCreateOptions {
Email = "paying.user@example.com",
SourceToken = token
});
// YOUR CODE: Save the customer ID and other info in a database for later.
// YOUR CODE (LATER): When it's time to charge the customer again, retrieve the customer ID.
var charge = charges.Create(new StripeChargeCreateOptions {
Amount = 1500, // $15.00 this time
Currency = "usd",
CustomerId = customer.Id
});
阅读引用文档了解更多详情
关于stripe-payments - 使用 Stripe 获取 token 以创建客户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47842595/