This codebase is interacting with the Razorpay API. This projects explains how to use Razorpay Payment Gatewat in our Rails Application.
- Ruby is installed (v 3.1.0)
- Rails is installed (v 7.0.2)
- MySQL is installed
- Git is installed
- GitHub account is created
- Razorpay account created for business
- Cloned/created a new rails project
- Database configuration setup (using MySQL)
- Initialize a local repository using git
- .gitignore file created to add configuration.yml
- configuration.yml file created to initialize environment variables
- Created a new remote repository using GitHub
- Implemented required APIs for order and process a payment
- Changed README.md and documentation added
- Code Commited and Pushed to GitHub repository
- Go to the config directory
- Create a new file with name configuration.yml
RAZORPAY_KEY_ID: enter_key_id_here_xxxxxxxxxxxxxxxxxxxxxx
RAZORPAY_KEY_SECRET: enter_key_secret_here_xxxxxxxxxxxxxxxxxxxxxx
Payment Gateway
gem 'razorpay'
here is the link
For authentication:
- Bcrypt here is the gem documentation link
- doorkeeper here is the gem documentation link
- doorkeeper-jwt here is the gem documentation link
User can signup by providing basic details
- Name
- Password
POST http://localhost:3000/oauth/token
Request Parameter | Type | Description |
---|---|---|
email |
string |
Required. |
password |
password_digest |
Required. |
client_id |
string |
Required. |
client_secret |
string |
Required. |
grant_type |
string |
Required. |
Response Parameter | Type | Response |
---|---|---|
access_token |
string |
eyJraWQiOiJxVTJERVIyREV*************** |
token_type |
string |
Bearer |
expires_in |
integer |
7200 |
refresh_token |
string |
yRUB93xdWSp8WP4hJd4AX*************** |
created_at |
integer |
166445*** |
POST http://localhost:3000/api/v1/order/create
Request Parameter | Type | Description |
---|---|---|
amount |
integer |
Required. |
user_id |
reference |
Required. |
Response Parameter | Type | Response |
---|---|---|
id |
integer |
1 |
amount |
integer |
120 |
user_id |
reference |
2 |
gateway_order_id |
string |
yRUB93**** |
POST http://localhost:3000/api/v1/order/verify
Request Parameter | Type | Description |
---|---|---|
gateway_order_id |
string |
Required. |
razorpay_payment_id |
string |
Required. |
razorpay_signature |
string |
Required. |
Response Parameter | Type | Description |
---|---|---|
status |
boolean |
on success true |
status |
boolean |
on fails false |
base_url = GET https://api.razorpay.com/v1
Parameter | Type | Description |
---|---|---|
YOUR_KEY_ID |
string |
Required. YOUR_KEY_ID |
YOUR_SECRET |
string |
Required. Your YOUR_SECRET key |
You can use Razorpay APIs in two modes, Test and Live. The API keys are different for each mode. Know about generating API Keys.
- ruby v3.1.0
- rails v7.0.2
We need to register our account on Razorpay as a business. We would need blow keys from our account:
- key_id
- key_secret
You can find your API keys at https://dashboard.razorpay.com/#/app/keys.
We will setup these keys in our Rozarpay configurations.
Razorpay.setup('key_id', 'key_secret')
Razorpay provides various features to manage the complete payment process for an order link.
Here is the list from their documentation:
- Customer
- Token
- Order
- Payments
- Settlements
- Fund
- Refunds
- Invoice
- Plan
- Item
- Subscriptions
- Add-on
- Payment Links
- Smart Collect
- Transfer
- QR Code
- Emandate
- Cards
- Paper NACH
- UPI
- Register Emandate and Charge First Payment Together
- Register NACH and Charge First Payment Together
- Payment Verification