我正在使用Checkout
在我的ASP.NET核心应用中实现Stripe。
我知道如何使用{{1}}获取信用卡收费令牌,但我在哪里可以获得令牌来创建客户?
在文档中,我看到我需要获取令牌来创建客户,但不确定该令牌的来源。 https://stripe.com/docs/api/dotnet#create_customer
据我所知,一个令牌只能使用一次,所以它不能与我在收取信用卡之前获得相同的令牌。
答案 0 :(得分:4)
正如我在条带document
中引用的那样当您收集客户的付款信息时,会创建一个条带标记。此令牌只能使用一次,但这并不意味着您必须为每笔付款请求客户的卡详细信息。
Stripe提供了一个Customer对象,可以轻松保存此对象 其他信息供以后使用。您可以使用Customer对象 创建订阅或未来的一次性费用。
您必须做的就是创建一个您在服用时获得的客户 来自客户的卡详细信息并向该客户收取费用。
使用以下代码段进行操作,这样您就可以使用单个令牌创建客户并收费
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
});
阅读参考文档了解更多详情
答案 1 :(得分:0)
\Stripe\Stripe::setApiKey("----");
\Stripe\Stripe::setApiKey(".................");
$token= \Stripe\Token::create(array(
"card" => array(
"number" => "4242424242424242",
"exp_month" => 1,
"exp_year" => 2019,
"cvc" => "314"
)
));
$request['stripe_token'] =$token['id'];
// When Contact person have not Stripe Customer id then we have to do the following process.
try {
$customer = \Stripe\Customer::create([
"description" => "Customer for ".$contactDetails['email'],
"source" => $request['stripe_token'] // obtained with Stripe.js
]);
// update its customerid in the contact table
// Create Customer then save its id in table and use the customer id when you are verifiying the customer token
$result= \Stripe\Charge::create(array(
"amount" => $request['amount'],
"currency" => $request['currency'],
"customer" => $customer
));
$status = $result['succeeded'];
if($result['status'] == "succeeded"){
$success = 'Your payment was successful.';
$all['payment_done'] = "1";
$FinalArray = array('status'=>'true','message'=>'Your payment done successful.','result'=>$all);
}else{
$FinalArray = array('status'=>'fail','message'=>'Your Token is not generated successfully','result'=>[]);
}
}
catch (Exception $e) {
$error = $e->getMessage();
$all['payment_done'] = "0";
$FinalArray = array('status'=>'false','message'=>'The Stripe token id is not correctly','result'=>$all);
}