Paypal返回URL GET而不是POST - Rails

时间:2014-11-06 21:10:07

标签: ruby-on-rails post paypal get

我正在使用paypal付款。除了返回URL之外,一切正常。 Paypal正在使用POST返回我的Rails应用程序,如何强迫他使用GET?

def paypal_url(return_path, token_id, pack_id, amount)
    values = {
        business: "#{Rails.application.secrets.paypal_account}",
        cmd: "_xclick",
        upload: 1,
        return: "#{Rails.application.secrets.app_host}#{return_path}",
        invoice: id,
        amount: amount,
        item_name: Purchase.packs[pack_id].description,
        quantity: 1, # 1 pack
        notify_url: "#{Rails.application.secrets.app_host}/hook"
    }
    "#{Rails.application.secrets.paypal_host}/cgi-bin/webscr?" + values.to_query
  end

这是错误

Started POST "/users/1" for 90.62.1.250 at 2014-11-06 20:58:46 +0000
ActionController::RoutingError (No route matches [POST] "/users/1")

1 个答案:

答案 0 :(得分:0)

虽然这不是您可能想要的答案, 如果您想要使用发送的给定发布请求,请添加到routes.rb文件(在配置中)

#routes.rb
post "/hook" => "modelname#hook"

然后在模型控制器中,定义一个新方法(名为hook)来处理发布请求

#modelname_controller.rb
protect_from_forgery except: [:hook]
def hook
  params.permit! # Permits the pay
  status = params[:payment_status]
  if status == "Completed"
    # Process the data
  end
  render nothing: true
end