ruby 轨道7| GET请求在生产环境中不起作用

q9yhzks0  于 12个月前  发布在  Ruby
关注(0)|答案(2)|浏览(113)

我有一个rails 7应用程序,当用户点击按钮时,它会重定向到一个支付网关,通过GET请求在线支付,在我的开发模式下,在本地机器上(在localhost上:3000),它工作得很好。
orders_controller.rb

def paye
        @payment_response = Easebuzz::Payment.initiate({
          "txnid" => "#{@order.id}",
          "amount" => amount.to_f,
          "firstname" => current_user.name,
          "email" => current_user.email,
          "phone" => current_user.phone_number,
          "productinfo" => "Payment for Order#{@order.id}",
          "surl" => "http://localhost:3000/orders/#{@order.id}/successE",
          "furl" => "http://localhost:3000/orders/#{@order.id}/failedTransaction",
        })

        if @payment_response['status'] == 1
          data = @payment_response['data']
          redirect_to("https://testpay.easebuzz.in/pay/#{data}", allow_other_host: true, status: 303)
        end

       puts @payment_response
end

routes.rb:

resources :orders do
  member do
      get '/paye', to: 'orders#paye'
  end
 end

index.html.erb

<%= link_to paye_order_path(order) %>

正如我所说的,在开发模式下,它工作得非常好,但是当我在生产环境中使用它时,我使用aws ec2,apache和passenger部署了它,只是改变了它。

def paye
     .....
          "surl" => "http://(Main Domain.in)/orders/#{@order.id}/successE",
          "furl" => "http://(Main Domain.in)/orders/#{@order.id}/failedTransaction",
     ......

     .......
          redirect_to("https://pay.easebuzz.in/pay/#{data}", allow_other_host: true, status: 303) 
          #using pay.easebuzz in production
       .....
  puts @payment_response
end

只有第一次它在生产中工作,然后从第二次,它不工作。
GET请求显示(OrdersController#payE is missing a template for request formats: text/html)
但是在开发中,它工作得非常好,为什么在生产中它不执行GET请求呢??
puts @payment_response也没有在日志中显示任何内容。
所以我的主要问题是GET请求(order_controller.rb中的payE方法)在开发中工作,但在生产中使用时,它不工作,它不能阅读Easebuzz::Payment.initiate
我也改变了payE从GET到POST请求,看看它是否会puts @payment_response,但它显示No template found for OrdersController#payE在日志中。
我在这里做什么蠢事?

z9zf31ra

z9zf31ra1#

因此,它在模板问题上出错的事实意味着@payment_response['status'] == 1不是真的。puts @payment_response可能不工作,因为STDOUT没有绑定到生产中的日志,您可以尝试Rails.logger.debug @payment_response.inspect
所以这应该可以帮助你看到响应,我最好的猜测是你的Easebuzz配置没有正确设置使用正确的商家密钥或生产的东西,但你会知道更多,一旦你看到日志。
最后,你的代码应该更优雅地处理错误,即。你应该有一个else来进行检查,或者是一个带有flash错误的本地重定向,或者是一个显示给用户的错误模板。

wh6knrhe

wh6knrhe2#

好吧,所以我是完全愚蠢的没有阅读的文档Easebuzz,在现场付款,我需要使用唯一的交易ID:“)
注意,我使用了"txnid",它指的是transaction id,所以每次交易发生时(即当用户点击按钮并弹出付款页面时),付款页面只是一个交易,或者我们可以说它是用唯一的transaction id构建的,它应该有一个唯一的id,我使用的id是SQL自带的内置唯一id(每当我们在Rails中创建模型或其他东西时)。
(here我使用@order.id),每次我做rails db:setup重新启动,数据库将重置(注意,我已经使用了唯一的id,我第一次使用实时支付生产,所以它只工作了1次,后来它就不工作了)。
因此,下次当我使用rails db:setup重新开始时,我使用相同的id创建订单(在开始时显然是1,我已经第一次使用过一次)。
所以我用
orders_controller.rb

def payE
        unique_txnid = "#{Time.now.to_i}_#{rand(100000..999999)}"
        @payment_response = Easebuzz::Payment.initiate({
          "txnid" => unique_txnid,
          "amount" => amount.to_f,
          "firstname" => current_user.name,
          "email" => current_user.email,
          "phone" => current_user.phone_number,
          "productinfo" => "Payment for Order#{@order.id}",
          "surl" => "http://localhost:3000/orders/#{@order.id}/successE",
          "furl" => "http://localhost:3000/orders/#{@order.id}/failedTransaction",
        })

        if @payment_response['status'] == 1
          data = @payment_response['data']
          redirect_to("https://pay.easebuzz.in/pay/#{data}", allow_other_host: true, status: 303)
        end

end

相关问题