redirect_to using POST in rails
The idea is to make a 'redirect' while under the hood you generate a form with method :post.
I have faced the same problem and extracted the solution into the gem repost
, so it is doing all that work for you, so no need to create a separate view with the form, just use the provided by gem function redirect_post()
on your controller.
class MyController < ActionController::Base
...
def some_action
redirect_post('url', params: {}, options: {})
end
...
end
I "solved" the issue by displaying a summary page with all the products and delivery charges etc, with the typical "to confirm and pay for your purchases, click the continue button below" type message. The continue button causes the site to POST the product data and everything across to the payment processor.
The short answer - there is another step for the user. However, the key is to make it seem as natural and as much part of the checkout experience as you can. This way, it doesn't come across too much as "just another step".
However, if you do come across a better way, I'll be very interested to hear what it was :)
With a simple line of javascript, you can have your POST form to post itself (form.submit()). You can then hide the form and display a simple "please wait while..." message to the user while the form is submitted to the payment processor.
Redirection isn't possible with POST requests - it's part of the HTTP/1.1 protocol.
You could either introduce another step that contains the form data to be POSTed to the payment processor, or you could send the post from your application (something I have done when working with PROTX).