我正在尝试在客户端创建多个令牌以发送到服务器以在 Stripe Connect 上进行多个目的地费用。
我不能使用 Customer 对象,因为对于 Destination Charges,Customer 必须是平台上的关联帐户,因此客人结账将不起作用。
所以我需要调用 Stripe.createToken 'x' 次,并使用 stripeResponseHandler 函数将令牌保存在 'x' 个隐藏输入中,然后将其提交到服务器端以处理费用。
这就是我非常非常手动地设法为 2 个令牌做到这一点的方法:
Stripe.createToken( {
number: card,
cvc: cvc,
exp_month: month,
exp_year: year,
name: name,
address_line1: address_line1,
address_line2: address_line2,
address_state: address_state,
address_city: address_city,
address_zip: address_zip,
address_country: address_country
}, stripeResponseHandler1 );
Stripe.createToken( {
number: card,
cvc: cvc,
exp_month: month,
exp_year: year,
name: name,
address_line1: address_line1,
address_line2: address_line2,
address_state: address_state,
address_city: address_city,
address_zip: address_zip,
address_country: address_country
}, stripeResponseHandler2 );
function stripeResponseHandler1( status, response ) {
var $form = jQuery("form.checkout, form#order_review");
if ( response.error ) {
jQuery('.woocommerce_error, .woocommerce-error, .woocommerce-message, .woocommerce_message, .stripe_token').remove();
jQuery('#dokan-stripe-connect-card-number').closest('p').before( '<ul class="woocommerce_error woocommerce-error"><li>' + response.error.message + '</li></ul>' );
$form.unblock();
} else {
var token = response['id'];
wc_stripe_connect_params.token_done = true;
jQuery( '.stripe_token').remove();
$form.append("<input type='hidden' class='stripe_token' name='stripe_token1' value='" + token + "'/>");
}
}
function stripeResponseHandler2( status, response ) {
var $form = jQuery("form.checkout, form#order_review");
if ( response.error ) {
jQuery('.woocommerce_error, .woocommerce-error, .woocommerce-message, .woocommerce_message, .stripe_token').remove();
jQuery('#dokan-stripe-connect-card-number').closest('p').before( '<ul class="woocommerce_error woocommerce-error"><li>' + response.error.message + '</li></ul>' );
$form.unblock();
} else {
var token = response['id'];
wc_stripe_connect_params.token_done = true;
$form.append("<input type='hidden' class='stripe_token2' name='stripe_token2' value='" + token + "'/>");
$form.submit();
}
}
显然,这不是任何东西的编码方式,所以我想我需要它做一些类似的事情:
var vendor_count = jQuery(".vendor_count").first().data("count");
for(i = 1; i <= vendor_count; i++ ) {
Stripe.createToken( {
number: card,
cvc: cvc,
exp_month: month,
exp_year: year,
name: name,
address_line1: address_line1,
address_line2: address_line2,
address_state: address_state,
address_city: address_city,
address_zip: address_zip,
address_country: address_country
}, stripeResponseHandler );
}
但我不知道如何将 vendor_count 索引传递给 stripeResponseHandler 以创建额外的隐藏输入字段以进行发送。
我是不是完全走错了路?我觉得基于本文开头的原因,我有理由要求以这种方式创建多个令牌。