Initialization🔗
Set up your [KEY_ID] and [KEY_SECRET] using the following command:
Copyrequire "razorpay"
Razorpay.setup('key_id', 'key_secret')
Learn about the Ruby bindings to interact with Razorpay APIs.
Notes:
Utils.ToUnixTimestamp
method.Set up your [KEY_ID] and [KEY_SECRET] using the following command:
Copyrequire "razorpay"
Razorpay.setup('key_id', 'key_secret')
Follow these steps to generate API keys:
The Key Id
and Key Secret
appear on a pop-up page.
Watch this video to see how to generate API keys in the test mode.
Watch this video to see how to generate API keys in the live mode.
Watch Out!
You can set custom headers for your requests using the following command:
CopyRazorpay.headers = {"CUSTOM_APP_HEADER" => "CUSTOM_VALUE"}
Note:
If you are using Rails, the right place to do this might be config/initializers/razorpay.rb
.
Note:
Click here for request parameters and an example request and response.
Copyorder = Razorpay::Order.create amount: 5000, currency: 'INR', receipt: 'TEST'
Copyorder = Razorpay::Order.fetch('order_id')
Copyorders = Razorpay::Order.all
Copypayments = order.payments
Note:
Click here for request parameters and an example request and response.
CopyRazorpay::Payment.fetch("payment_id").capture({amount:5000, currency:'INR'})
Notes:
The amount must come from your session. This is required to verify that the purchase was correctly made without any tampering.
If a payment is captured or refunded via capture!
, then the calling object is also updated:
Copypayment = Razorpay::Payment.fetch('payment_id')
payment.status
# 'authorized'
payment.capture!
payment.status
# 'captured'
Note:
Click here for request parameters and an example request and response.
CopyRazorpay::Payment.fetch("payment_id").refund({amount:500})
refunds = Razorpay::Payment.fetch("payment_id").refunds
Copyrefund = Razorpay::Refund.create(payment_id:"payment_id")
Razorpay::Refund.fetch(refund.id)
Note:
If a payment is captured or refunded via refund!
, then the calling object is also updated:
Copypayment = Razorpay::Payment.fetch('payment_id')
payment.status
# 'captured'
payment.refund!
payment.status
# 'refunded'
Note:
Click here for parameters related to the Cards APIs.
Copycard = Razorpay::Card.fetch('card_00000000000001')
puts card.network
Note:
Click here for request parameters and an example request and response.
Copycustomer = Razorpay::Customer.create email: 'gaurav.kumar@example.com', contact: '9876543210'
puts customer.id
Note:
Click here for request parameters and an example request and response.
Copyplan = Razorpay::Plan.create interval: 1, period: 'monthly', item: {
name: 'Test Plan',
description: 'Description for Test Plan',
currency: 'INR',
amount: 500
},
notes: {
identifier: 'Test Plan'
}
Copysubscription = Razorpay::Subscription.create plan_id: plan.id,
customer_id: customer.id,
start_at: (
Time.now + (60 * 60 * 24)).to_i,
total_count: 3
Note:
The above request creates a subscription that starts after 24 hours, (Time.now + (60 * 60 * 24)).
Copysubscription_addon = Razorpay::Addon.create subscription.id, item: {
name: 'test_plan',
description: 'test_plan_desc',
currency: 'INR',
amount: 500
},
quantity: 1
Copyaddon = Razorpay::Addon.fetch subscription_addon.id
Note:
Click here for request parameters and an example request and response.
Copyinvoice = Razorpay::Invoice.create customer_id: customer.id,
amount: 100,
currency: 'INR',
description: 'Test Invoice',
type: 'link'
Note:
Click here for detailed webhooks documentation.
You can verify the signature received in a webhook using the following:
CopyRazorpay::Utility.verify_webhook_signature(webhook_body, webhook_signature, webhook_secret)
If the signature is invalid, this throws a SecurityError exception.
The parameters are:
webhook_body
request.raw_post
in Railsreq.body.read
in Rackrequest.body.read
in Sinatrawebhook_signature
X-Razorpay-Signature
. You can read the header using:request.headers["X-Razorpay-Signature"]
in Railsenv["HTTP_X_RAZORPAY_SIGNATURE"]
in Rackrequest.env["HTTP_X-Razorpay-Signature"]
in Sinatrawebhook_secret
You can parse the webhook after it has been validated by using JSON.parse webhook_body
.
You can use the utility class to verify the signature received in response to a payment made using Orders API.
Copyputs payment_response
# {
# :razorpay_order_id => "test_order_id",
# :razorpay_payment_id => "test_payment_id",
# :razorpay_signature => "signature"
# }
Razorpay::Utility.verify_payment_signature(payment_response)
ON THIS PAGE