我的代码有问题。不知道到底出了什么问题。
此路由应显示输入中的 token 数据,但提交按钮只是加载,没有任何反应。因此,通过检查元素 - 生成 token 。 这是路线:
Route::get('buy', function(){
return View('pages.add_creditcard');
});
Route::post('buy', function(){
dd(Input::all());
});
这是 View ( Blade ):
{!! Form::open(['id' => 'billing-form', 'url' => '/buy', 'method' => 'post']) !!}
卡号:
客户验证码:
截止日期:
{!!形式::selectMonth(null, null, ['data-stripe' => 'exp-month']) !!}
{!! Form::selectRange(null,date('Y'),date('Y')+10, null, ['data-stripe' => 'exp-year']) !!}
{!! Form::submit('立即购买', ['id' => '提交']) !!}
{!! Form::close() !!}
这是 js 文件:
(function() {
var StripeBilling = {
init: function() {
this.form = $('#billing-form');
this.submitButton = this.form.find('input[type=submit]');
this.submitButtonValue = this.submitButton.val();
var stripeKey = $('meta[name="publishable-key"]').attr('content');
Stripe.setPublishableKey(stripeKey);
this.bindEvents();
},
bindEvents: function() {
this.form.on('submit', $.proxy(this.sendToken, this));
},
sendToken: function(event) {
this.submitButton.val('One Moment...').prop('disabled', true);
Stripe.createToken(this.form, $.proxy(this.stripeResponseHandler, this));
event.preventDefault();
},
stripeResponseHandler: function(status, response) {
if(response.error) {
this.form.find('.payment-errors').show().text(response.error.message);
return this.submitButton.prop('disabled', false).val(this.submitButtonValue);
}
$('<input>', {
type: 'hidden',
name: 'stripeToken',
value: response.id
}).appendTo(this.form);
//this.form[0].submit();
}
};
StripeBilling.init();
})();
此表单完全有效,但 POST 方法不执行任何操作。也许js有问题?
最佳答案
Stripe.js 创建了 token ,但您仍然需要为您的购买后创建 ajax 调用。试试这个
if(response.error) {
}else
{
var token = response.id;
var last4 = response.card['last4'];
var stripeId = response.card['id'];
$.post('/stripe/account/proccess_payment', {
stripeToken : token,
last_four : last4,
stripe_id : stripeId
}).done(function(data){
// your code here
});
}
关于javascript - Laravel 路由不适用于 js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32148818/