0

I've got a long and fairly complex form for a booking system that a user fills in, then pays using Stripe Checkout. I'm trying to figure out the best solution to both handle payment failure easily (so submitting form over AJAX so I don't have to try and regenerate the whole booking form with all the data the user's entered), whilst also handling payment success gracefully (so with a new page showing a booking summary and a different URL so if user clicks reload button in their browser it doesn't just take them back to the search results and booking form again)

I'm using a mixture of Laravel 5.4 and JS/JQuery to generate the booking form on the front end, and after Stripe Checkout (I'm using their standard simple integration pop up) it submits all the form + Stripe token etc back to a POST route in my Laravel backend. In my controller, I then try and charge the credit card using standard Stripe API and process the booking details into my database, and then return a Laravel view from a Blade template thus giving the user a different page and URL. As mentioned I want to switch the form submission to AJAX so payment failure can be handled easily (i.e. their big filled in form doesn't disappear, and just an alert pops up to user so they can try and enter a new card into the Stripe Checkout). That bit's fine, I'll just use this: https://stackoverflow.com/a/34099169/4059141 but then in payment succeeds I basically want the same behaviour as if I'd done a regular form POST, so the new page being displayed with a new URL.

I can generate and pass back the rendered HTML from the blade template over AJAX no problem, but that leaves the original URL in the browser's address bar, so if they hit reload on the booking summary they'll just see the search results page and blank booking form again - not what I want.

Any thoughts on a solution are welcome! Thanks

Alex Kerr
  • 956
  • 15
  • 44
  • 1
    One approach would be to have, in the case of a successful charge, your controller return a JSON (or whichever serialization form you are using) response indicating a successful completion back to your client side, including in the response an ID of the order/booking. Then on your client side (JS), on successful AJAX response, you would initiate a redirect to a confirmation page url, e.g `/confirmation?id=` passing the booking ID that was included in the response. – psmvac Sep 05 '18 at 09:23
  • 1
    Then the controller that would handle request of the `/confirmation?id=` url, would look up the booking details using the ID passed as param, check that it correspond to the user session, and then return as response the rendered HTML from the a blade template including the booking confirmation details that you need. – psmvac Sep 05 '18 at 09:26
  • Please refer https://stackoverflow.com/a/52223116/4336065 – Jigar7521 Sep 07 '18 at 13:08

0 Answers0