在 javascript 中条纹身份验证和捕获
Stripe auth and capture in javascript
Stripe 支持两步支付流程,用于授权和获取卡上的钱。为此,我们必须发送一个 capture = false 参数。
我的问题是如何在 javascript api 中发送此参数??
var args = {
number: jQuery('#AccountNumber').val(),
exp_month: jQuery('#ExpirationMonth').val(),
exp_year: jQuery('#ExpirationYear').val(),
address_line1: jQuery('#baddress1').val(),
address_line2: jQuery('#baddress2').val(),
address_city: jQuery('#bcity').val(),
address_state: jQuery('#bstate').val(),
address_zip: jQuery('#bzipcode').val(),
address_country: jQuery('#bcountry').val()
};
//create token
Stripe.createToken(args, stripeResponseHandler);
将Stripe.createToken(args, stripeResponseHandler);
替换为
Stripe.card.createToken(args, stripeResponseHandler);
现在您的 stripeResponseHandler
是一个 Javascript 函数,一旦在捕获信用卡详细信息后从 Stripe 的服务器收到响应,就会执行该函数。所以你需要一些代码来处理响应:
function stripeResponseHandler(status, response) {
// Grab the form:
var $form = $('#payment-form');
if (response.error) { // Problem!
// Show the errors on the form
$form.find('.payment-errors').text(response.error.message);
$form.find('button').prop('disabled', false); // Re-enable submission
} else { // Token was created!
// Get the token ID:
var token = response.id;
// Insert the token into the form so it gets submitted to the server:
$form.append($('<input type="hidden" name="stripeToken" />').val(token));
// Submit the form:
$form.get(0).submit();
}
}
更多信息:https://stripe.com/docs/stripe.js#collecting-card-details
一个典型的 Stripe 支付流程可以分为两个步骤:
客户端,在您的前端 (HTML + Javascript) 代码中,您使用 Stripe 的预建 Checkout form, or your own custom form with the Stripe.js 库收集客户的付款信息。这将 return 一个令牌,然后您将其发送到您的服务器。
服务器端,在您的后端代码中(在 PHP、Python、Ruby 或您喜欢的任何服务器端编程语言中),您使用 charge creation request 中的令牌实际为卡充值。
如果您想在费用创建请求中使用 "auth & capture" flow, you need to pass the capture=false
参数,即在您的服务器端代码中,而不是在令牌创建步骤中。
Stripe 支持两步支付流程,用于授权和获取卡上的钱。为此,我们必须发送一个 capture = false 参数。
我的问题是如何在 javascript api 中发送此参数??
var args = {
number: jQuery('#AccountNumber').val(),
exp_month: jQuery('#ExpirationMonth').val(),
exp_year: jQuery('#ExpirationYear').val(),
address_line1: jQuery('#baddress1').val(),
address_line2: jQuery('#baddress2').val(),
address_city: jQuery('#bcity').val(),
address_state: jQuery('#bstate').val(),
address_zip: jQuery('#bzipcode').val(),
address_country: jQuery('#bcountry').val()
};
//create token
Stripe.createToken(args, stripeResponseHandler);
将Stripe.createToken(args, stripeResponseHandler);
替换为
Stripe.card.createToken(args, stripeResponseHandler);
现在您的 stripeResponseHandler
是一个 Javascript 函数,一旦在捕获信用卡详细信息后从 Stripe 的服务器收到响应,就会执行该函数。所以你需要一些代码来处理响应:
function stripeResponseHandler(status, response) {
// Grab the form:
var $form = $('#payment-form');
if (response.error) { // Problem!
// Show the errors on the form
$form.find('.payment-errors').text(response.error.message);
$form.find('button').prop('disabled', false); // Re-enable submission
} else { // Token was created!
// Get the token ID:
var token = response.id;
// Insert the token into the form so it gets submitted to the server:
$form.append($('<input type="hidden" name="stripeToken" />').val(token));
// Submit the form:
$form.get(0).submit();
}
}
更多信息:https://stripe.com/docs/stripe.js#collecting-card-details
一个典型的 Stripe 支付流程可以分为两个步骤:
客户端,在您的前端 (HTML + Javascript) 代码中,您使用 Stripe 的预建 Checkout form, or your own custom form with the Stripe.js 库收集客户的付款信息。这将 return 一个令牌,然后您将其发送到您的服务器。
服务器端,在您的后端代码中(在 PHP、Python、Ruby 或您喜欢的任何服务器端编程语言中),您使用 charge creation request 中的令牌实际为卡充值。
如果您想在费用创建请求中使用 "auth & capture" flow, you need to pass the capture=false
参数,即在您的服务器端代码中,而不是在令牌创建步骤中。