You have two routes with the same url value payment/charges
Feb 19, 2015
4
Level 1
Stripe Get & Post Routing
Hi everyone,
So i have watched Jeffrey way Stripe video tutorial on implementing credit card payment service.
Now i am stuck i really need help, here is my route design. I am bascially trying to pass data from view 'Payment' to view 'charges' through a form. Here is the set-up.
//The url for this form - Payment is localhost/public/payment
{{ Form::open(array('url' => '/payment/charges','method'=>'POST','id'=>'billing-infor-form', 'class' => 'form-horizontal')) }}
//the url for the form - charges is localhost/public/payment/charges
{{Form::open(['id'=>'billing-form', 'class' => 'form-horizontal'])}}
//problem here is that the form is submitted with this
this.form = $('#billing-form');
this.form[0].submit();
//there is no url implemented for this form, leading it to assuming it's current URL routing.
//here is my route set-up
Route::get('/payment', 'BillController@payment');
Route::post('/payment/charges', array('as' => 'charges', 'uses'=>'BillController@paymentCharges'));
//the route::post method for payment and charges - conflict here
Route::get('/payment/charges', 'BillController@charges');
Route::post('/payment/charges', function(){
$billing = App::make('Acme\Billing\BillingInterface');
$customerId= $billing->charge([
'email' => Input::get('email'),
'token' => Input::get('stripe-token')
]);
if(array_key_exists('error', $customerId))
return Redirect::refresh()->withMessage($customerId['message'])->withInput(Input::all());
else
return Redirect::refresh()->withMessage('Charge was successful!');
});
i have tried giving the payment view form a different route but it will go into a endless redirect loop. So if anyone have better knowledge on how i could go above solving this, it would really helpful.
Thanks in advance!
This is the full script on the Payment View, showing how the form is processed.
(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: 'stripe-token',
value: response.id
}).appendTo(this.form);
this.form[0].submit();
}
};
StripeBilling.init();
})();
Please or to participate in this conversation.