Raj
Raj

Reputation: 980

redirect to payment URL with post params

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]}.

Upvotes: 3

Views: 1316

Answers (1)

hattenn
hattenn

Reputation: 4399

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)

Upvotes: 1

Related Questions