Integrating Easebuzz Payment Gateway into Ruby on Rails

BharteeTechRubyOnRails
2 min readApr 10, 2024

--

Sign Up and Get API Credentials:

  1. Sign up for an Easebuzz account.
  2. Obtain your API Key and Secret, which you will need for API integration.

Install Required Gems:

In your Rails application, make sure you have the required gems installed. You can add them to your Gemfile:

gem ‘rest-client’ # For making HTTP requests to Easebuzz API
gem ‘json’ # For working with JSON data

Configure API Credentials:

Store your Easebuzz API credentials securely. You can use environment variables or a configuration file to store these credentials. For example, you can use the dotenv-rails gem to manage environmental variables.

Create a Payment Controller:

In your Rails application, create a controller to handle payments. You can generate a controller like this:

rails generate controller Payments

Initiate a Payment:

In your PaymentsController, create an action to initiate a payment. This action will make a POST request to the Easebuzz API to generate a payment link.

def create_payment
# Use RestClient or HTTParty to make the API request to Easebuzz
response = RestClient.post(
'https://api.easebuzz.in/payment',
{
key: ENV['EASEBUZZ_API_KEY'],
txnid: SecureRandom.hex(10), # Generate a unique transaction ID
amount: 100, # Set the payment amount
productinfo: 'Your product name',
firstname: 'Customer First Name',
email: 'customer@example.com',
phone: '1234567890',
surl: 'https://example.com/success',
furl: 'https://example.com/failure'
}
)

payment_data = JSON.parse(response)
redirect_to payment_data['url']
end

Handle Callbacks:

In your PaymentsController, create an action to handle callbacks from Easebuzz, which include success and failure callbacks. You will need to verify the callback data’s authenticity and update your application’s records accordingly.

Integrating Easebuzz payment gateway into your Ruby on Rails application opens up opportunities for seamless online payment processing, enhancing the user experience and facilitating business growth. By following the steps outlined in this blog post and leveraging Easebuzz’s robust features, you can streamline the payment process and provide customers with a secure and convenient payment experience.

Happy Integrating Easebuzz Payment Gateway into Ruby on Rails Application 🚀 Please follow for more updates

BharteeSahareTechRoR

--

--