0

I have a rails 7 app where when the user clicks the button, it redirects to a payment gateway for doing payments online via GET Request, in my development mode, in local machine (on localhost:3000), it works perfectly fine.

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) %>

so as i said, in develpment mode, it is working absolutely fine, but when i use it in production which i deployed using aws ec2, apache and passenger, and just changed

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

Only 1st time it worked in production, then from 2nd time, it wasn't working.

the GET request is showing (OrdersController#payE is missing a template for request formats: text/html)

but in development, it is working absolutely fine, why is it not doing GET request in production??

also puts @payment_response is not showing anything in the logs.

So my main problem is that The GET request (payE method in order_controller.rb) is working in development, but when using in production, it is not working, it is not reading the Easebuzz::Payment.initiate

also i changed from payE from GET to POST request to see if it will puts @payment_response, but it is showing No template found for OrdersController#payE in logs.

What dumb thing am i doing here?

2
  • The issue is likely that there is an error with Easebuzz::Payment.initiate. Add a payE.html.erb template to your views, which you likely need if there is a failure anyway. You can use that to help debug. Commented Sep 29, 2023 at 14:35
  • Note, "#{x}" and x are effectively the same if x is a String. If you want to convert it to one, x.to_s is the typical method. The quoted style is a bash thing. Commented Sep 29, 2023 at 14:39

2 Answers 2

1

So the fact that it's erroring on a template issue means that @payment_response['status'] == 1 is not true. puts @payment_response is probably not working because STDOUT is not tied to your logs in production, you could try Rails.logger.debug @payment_response.inspect.

So that should help you see the response, and my best guess would be that your Easebuzz config is not setup properly to use the right merchant key or something for production, but you'll know more once you see the logs.

Finally, your code should handle an error more gracefully, ie. you should have an else for that check, with either a local redirect with a flash error, or maybe a template with an error displayed to the user.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks! i found what dumb thing i was doing, I needed to have new transaction id each time (even if we refresh the page, it should have a unqiue txnid), but there i was using @order.id which is also unique ONCE but when i used the same id again, it wasnt working, i was being totally dumb without reading docs :' ).
0

Ok, so i was being totally Dumb without reading the docs on Easebuzz, during Live Payments, i needed to use Unique Transaction ID :')

notice i used "txnid", it refers to the transaction id, So each time when a transaction occurs (i.e when the user clicks the button and payment page pops up), that payment page is nothing but a transaction, or we can say it is built with the unique transaction id, it should be having a unique id, i was using the id which is a built-in unique id which comes with SQL (whenever we create a model or something in rails).

(here i used @order.id) and everytime i was doing rails db:setup to start fresh and the database would reset (notice that i have already used that unique id the first time i used the Live Payment on production,so it worked only 1 time, then later it wasn't working).

So next time when i was starting fresh using rails db:setup i was creating the order with the same id (which would be 1 at the start obviously which i have already used once for the first time).

So i fixed it bu using

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.