Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bellaratmelia's avatar

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();

})();

0 likes
4 replies
bellaratmelia's avatar

@blackbird that's what i needed help with. I am trying to figure out a way to allow my form to post to a different view, but at the second view post through its current URL.

bobbybouwmann's avatar

Oke oke, start over. What function/controllers needs to link to what route? If you think that out first then you get a better idea to handle that ;)

bellaratmelia's avatar

@blackbird Here it the structure Payment view will go to payment/charges view. In the process it will pass all the relevant form data over. So in the form URL i initiate the url to be payment/charges. This allows me to call the controller function @payment. Which creates a view for payment/charges.

(I followed the video, so i am stuck) Here is the tricky part, the payment/charges view form has no URL. Giving it one like how i do so with payment/charges will lead to a endless redirecting loop. Therefore the route for this method is the same as the previous one.

Do you have any idea how i can fix this?

Please or to participate in this conversation.