Razor pay Integration In Ruby On Rails

Total Blog Views: 71

Blog Status: publish

Created By: swazahmad Created at: 08-14-2021

Tags: ruby on rails payment gateway integration UPI integration card payment in ruby on rails indian Upi Integration In ruby on rails

Today We Learn How To handle All UPI/Netbanking/Card transactions using Razorpay

How To handle Custom Payment Take using any UPI using Razorpay.

Register Here and Gain Keys required for configuration, please fill the form carefully so your application gets verified By Razorpay,

For Website Whitelisting Your website should have a minimum below criteria 

  • contact_us page
  • SSL
  • about us page
  • Privacy and return policy

After Filling in all the details And once everything is okay your account will get verified and you will receive an Email from the Razorpay team you can get Live mode Keys Now

Follow the Below Steps Goto settings

 

Click On API keys If already present Or You can generate the New One

 

Please Note Down The Keys

Please Add Below Line In Your Product List Page

 

<form action="/purchase" method="POST">
  <script
    src="https://checkout.razorpay.com/v1/checkout.js"
    data-key="<%= "rzp_live_123456" %>"
    data-amount="<%= product.final_price %>"
    data-name="ShadBox"
    data-description="product 1"
    data-prefill.name="<%= "#{current_user.display_name}" %>"
    data-prefill.email="<%= "#{current_user.email}" %>"
    data-theme.color="#041634"
    >
  </script>
  <input type="hidden" value="<%= "#{product.id}" %>" name="product_id">
  <input type="hidden" value="<%= "#{current_user.id}" %>" name="user_id">
</form>

You can Update the Above Values Based On your requirement

Update routes.rb file to handle the  request from razorpay

 

 post '/purchase' => 'orders#update_payment'

 

Add update_payment Methods In Orders Controller

 

class OrdersController < ApplicationController
  before_action :authenticate_user!
  def update_payment
    product = Product.find_by_id(params[:product_id])
    payment = current_user.payment_histories.new(product_id: product.id, payment_id: params[:razorpay_payment_id])
    if payment.save
      flash[:alert] = "payment successfully made."
      redirect_to product_path(product)
    else
      flash[:alert] = "Something went wrong please try again later."
      redirect_to root_path
    end
  end
end

In the above Code, If payment is successfully captured we created an entry In DB to store Payment Info and we can proceed with the order based on the requirement

List of payment Method Supported by Razorpay Please see below Live App screenshot

Click On link after Login we do have configured Using razorpay Click On pay Button

razropay integrate ruby on rails

 

Razorpay provide a very beautiful Dashboard 

 

Thanks for reading , If queries and Suggestion Please ask in the comment

 


swazahmad

Swaz is Practice Lead of ROR Developer. he's a Blogger, Mentor, and Rubyst. He has expertise in Javascript also . he's highly skilled in designing, developing and testing web applications. He enjoys being challenged and interesting with projects that need him to



Comments



  • swazahmad | almost 4 years ago
    Awesome Information Thanks For Sharing
Buy traffic for your website

About Shadbox

we have the “Get things executed” lifestyle at our place of work. There are not any excuses, no if’s or however’s in our dictionary. committed to navigating the ship of creativity to create cell answers, we resolve the real-lifestyles troubles of our clients and their clients. Our passion for work has won us many awards, year after 12 months.

Services

Downloads