【问题标题】:redirect to payment URL with post params使用 post 参数重定向到付款 URL
【发布时间】:2016-02-04 13:33:05
【问题描述】:

我想将 PayuMoney 支付网关集成到我的 rails 应用程序中。我想通过 post 请求重定向到支付网关 URL,所以我使用 HTTparty 重定向和 POST 请求到 payumoney 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]}.

【问题讨论】:

  • 你找到解决办法了吗??

标签: ruby-on-rails ruby payment payu payumoney


【解决方案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)

【讨论】:

  • 如何通过 post 请求重定向到 test.payu.in/_payment.php。 ? @hattenn
  • 您无法通过发布请求进行重定向。 redirect_to 正在使用 html 中的“Location: url”标头。在 redirect_to 你只能使用 GET 参数
  • @dthal 是正确的。我在我的问题中添加了一些可能对您有帮助的更多信息。
猜你喜欢
  • 2013-05-26
  • 2019-09-11
  • 1970-01-01
  • 2019-05-02
  • 2017-09-20
  • 2013-07-02
  • 2014-07-15
  • 1970-01-01
  • 2014-08-10
相关资源
最近更新 更多