2015-11-04 55 views
2

我想將PayuMoney支付網關集成到我的Rails應用程序中。而且我想用付款請求重定向到支付網關URL,因此我使用HTTparty重定向並POST請求以支付貨幣URL。重定向到後付款的付款網址

我的控制器:

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 

路線:

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

當我運行此我得到了,

Missing template client_fee_payments/fee_payment, application/fee_payment with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :axlsx, :jbuilder]}. 
+0

你找到了一個解決方案? – Abhilash

回答

1

你不能用POST請求重定向。您需要發送您的發佈請求,然後重定向到一個頁面。

您應該在控制器方法的末尾使用redirect_to :some_page

現在rails正試圖呈現「默認」,這就是爲什麼你會得到這個錯誤。

嘗試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) 
+0

如何使用發佈請求重定向到https://test.payu.in/_payment.php。 ? @hattenn –

+0

您無法使用發佈請求重定向。 redirect_to使用html中的「Location:url」標題。 在redirect_to中,您只能使用GET參數 – dthal

+0

@dthal是正確的。我已經在我的問題中添加了一些可能對您有幫助的信息。 – hattenn