3

I want to integrate PayuMoney payment gateway to my rails application. And I want to redirect to payment gateway URL with post request, so I use HTTparty to redirect and POST request to payumoney URL.

My controller:

class ClientFeePaymentsController < ApplicationController
 include HTTParty

 def fee_payment
   uri = URI('https://test.payu.in/_payment.php')
   res = Net::HTTP.post_form(uri, 'key' => 'fddfh', 'salt' => '4364')
   puts res.body    
 end 
end

routes:

resources :client_fee_payments do
    collection do
      get :fee_payment
      post :fee_payment
    end
  end

when i run this i got,

Missing template client_fee_payments/fee_payment, application/fee_payment with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :axlsx, :jbuilder]}.
Raj
  • 950
  • 1
  • 9
  • 33

1 Answers1

1

You can't redirect with a post request. You need to send your post request, and then redirect to a page.

You should use redirect_to :some_page in the end of your controller method.

Right now rails is trying to render the "default", that's why you're getting that error.

Try this

require "net/http"
require "uri"

uri = URI.parse("http://example.com/search")

# Shortcut
response = Net::HTTP.post_form(uri, {"q" => "My query", "per_page" => "50"})

# Full control
http = Net::HTTP.new(uri.host, uri.port)

request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data({"q" => "My query", "per_page" => "50"})

# Tweak headers, removing this will default to application/x-www-form-urlencoded 
request["Content-Type"] = "application/json"

response = http.request(request)
Jagat Dave
  • 1,643
  • 3
  • 23
  • 30
hattenn
  • 4,371
  • 9
  • 41
  • 80
  • How to redirect to https://test.payu.in/_payment.php with post request. ? @hattenn – Raj Nov 04 '15 at 06:52
  • You can't redirect with a post request. redirect_to is using the "Location: url" header from html. In redirect_to you can only use GET params – dthal Nov 04 '15 at 07:00
  • @dthal is correct. I've added some more information to my question that might help you. – hattenn Nov 04 '15 at 07:01