1
爲了保持這種簡單,我只包含了一個我正在驗證的表格。一切都驗證正確,但我不明白爲什麼一個令牌不會生成。表單從不提交。我沒有確認問題是什麼,我沒有確認表格是否正常工作。驗證其他字段後創建分條支付令牌
var oeValidate = {
'name' : function() {
var ele = $('#name');
if(ele.val().length < 6) {
oeValidate.errors = true;
ele.removeClass('correct').addClass('error');
} else {
ele.removeClass('error').addClass('correct');
}
},
'sendIt' : function() {
if(!oeValidate.errors) {
$('#payment-form').submit(function(event){
// disable the submit button to prevent repeated clicks
$('#stripe-submit').attr("disabled", "disabled");
// send the card details to Stripe
Stripe.createToken({
name: $('#name').val(),
number: $('#card-number').val(),
exp_month: $('select[name="card-month"]').val(),
exp_year: $('select[name="card-year"]').val(),
cvc: $('#card-cvc').val()
}, stripeResponseHandler);
// prevent the form from submitting the default action
return false;
});
}
}
};
Stripe.setPublishableKey(stripe_vars.publishable_key);
function stripeResponseHandler(status, response) {
if (response.error) {
// show errors returned by Stripe
jQuery(".payment-errors").html(response.error.message);
// re-enable the submit button
jQuery('#stripe-submit').attr("disabled", false);
} else {
var form$ = jQuery("#payment-form");
// token contains id, last4, and card type
var token = response['id'];
// insert the token into the form so it gets submitted to the server
form$.append("<input type='hidden' name='stripeToken' value='" + token + "'/>");
// and submit
form$.get(0).submit();
}
}
jQuery(document).ready(function($) {
$('#stripe-submit').click(function(){
oeValidate.errors = false;
oeValidate.name();
oeValidate.sendIt();
return false;
});
});
那麼你是說我不能將這些信息存儲在一個對象中? – souporserious
@ftntravis as docs say,you must use'$('form')。submit(function(){$ form = $(this); ... Stripe.createToken($ form,stripeResponseHandler); ...}) ;' – vladkras
我很抱歉,但沒有幫助。 – souporserious