我的代码有问题。我真不知道怎么了。
这个路由应该显示来自输入的令牌数据,但是提交按钮只是加载,什么都没有发生。因此,通过inspect元素标记生成。这是路由:
Route::get('buy', function(){
return View('pages.add_creditcard');
});
Route::post('buy', function(){
dd(Input::all());
});
Here is View (blade):
{!! Form::open(['id' => 'billing-form', 'url' => '/buy', 'method' => 'post']) !!}
信用卡号码:CVC:过期日期:{! !Form::selectMonth(null, null, ['data-stripe' => 'exp-month']) !!}{! !形式::selectRange (null,日期(Y),日期(Y) + 10, null, [' data-stripe ' => ' exp-year ']) ! !}{! !Form::submit('buy now', ['id' => 'submit']) !!}
{!! 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创建令牌,但您仍然必须为您的post buy创建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
});
}