I have a problem with my code. Don't know really what is wrong.
This route should display Token data from input, but submit button is just loading and nothing happens. Therefore with inspect element - token is generated. Here is route :
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']) !!}
Card Number:
CVC:
Expiration Date:
{!! Form::selectMonth(null, null, ['data-stripe' => 'exp-month']) !!}
{!! Form::selectRange(null,date('Y'),date('Y')+10, null, ['data-stripe' => 'exp-year']) !!}
{!! Form::submit('buy now', ['id' => 'submit']) !!}
{!! Form::close() !!}
and here is js file :
(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();
})();
This form is fully working, but POST method does nothing. maybe js is the problem?