SDKs overview
Razorpay provides Software Development Kits (SDKs) and libraries to facilitate the integration of its payment gateway and related services into various applications. These SDKs abstract the underlying RESTful API, allowing developers to interact with Razorpay's platform using familiar programming constructs. The primary objective of these SDKs is to streamline the process of initiating payments, verifying transactions, and managing other payment-related operations, thereby reducing development time and effort.
The official SDKs are maintained by Razorpay and cover popular web development languages and mobile platforms. They are designed to handle aspects such as secure communication, request signing, and response parsing, which are critical for robust payment system integrations. For a comprehensive understanding of the core API, developers can consult the Razorpay API reference documentation.
Official SDKs by language
Razorpay offers official SDKs for a range of programming languages and mobile development frameworks. These SDKs are actively maintained and recommended for stable and secure integrations. Each SDK provides specific methods and classes that map to Razorpay's API endpoints, enabling developers to perform operations such as creating orders, fetching payment details, and managing refunds.
Web & Backend SDKs
| Language | Package Name | Maturity | Install Command Example |
|---|---|---|---|
| PHP | razorpay/razorpay |
Stable | composer require razorpay/razorpay |
| Node.js | razorpay |
Stable | npm install razorpay |
| Python | razorpay |
Stable | pip install razorpay |
| Ruby | razorpay |
Stable | gem install razorpay |
| Java | com.razorpay:razorpay-java |
Stable | (Maven) <dependency><groupId>com.razorpay</groupId><artifactId>razorpay-java</artifactId><version>[LATEST_VERSION]</version></dependency> |
| .NET | Razorpay.Api |
Stable | dotnet add package Razorpay.Api |
Mobile SDKs
For mobile applications, Razorpay provides dedicated SDKs to enable native payment experiences and integrate with platform-specific payment methods.
- Android: The Razorpay Android SDK allows for direct integration into Android applications, supporting various payment methods and providing a customizable UI.
- iOS: The Razorpay iOS SDK offers similar functionality for Apple's ecosystem, enabling secure payments within native iOS apps.
- React Native: A dedicated React Native SDK simplifies integration for cross-platform applications built with React Native.
- Flutter: The Razorpay Flutter SDK enables payment gateway integration for Flutter applications, catering to multi-platform development.
Installation
The installation process for Razorpay SDKs typically involves using a package manager specific to the programming language or framework. The following examples illustrate common installation commands for some of the popular backend SDKs. For mobile SDKs, platform-specific steps involving build system configurations (e.g., Gradle for Android, CocoaPods/Swift Package Manager for iOS) are required, as detailed in the Razorpay SDK documentation.
PHP
composer require razorpay/razorpay
Node.js
npm install razorpay
Python
pip install razorpay
Ruby
gem install razorpay
Java (Maven)
<dependency>
<groupId>com.razorpay</groupId>
<artifactId>razorpay-java</artifactId>
<version>[LATEST_VERSION]</version>
</dependency>
Replace [LATEST_VERSION] with the current stable version, which can be found in the Razorpay Java SDK documentation.
.NET (NuGet)
dotnet add package Razorpay.Api
Quickstart example
A common integration pattern with Razorpay involves creating an order on the server-side, then using the order ID to initiate the payment process on the client-side. The following examples demonstrate how to create an order using different backend SDKs. This order ID is then passed to the client-side (web or mobile) where the Razorpay checkout interface is invoked.
Python Quickstart: Create an Order
This Python example demonstrates how to use the Razorpay Python SDK to create a payment order with a specific amount and currency. The order ID is crucial for subsequent client-side payment initiation.
import razorpay
# Initialize Razorpay client with your API keys
# Get your API keys from https://dashboard.razorpay.com/#/app/keys
client = razorpay.Client(auth=("YOUR_KEY_ID", "YOUR_KEY_SECRET"))
# Create an order
# For example, an order for INR 500.00
data = {
"amount": 50000, # amount in paise (e.g., 50000 paise = INR 500.00)
"currency": "INR",
"receipt": "receipt#1",
"notes": {
"key1": "value3",
"key2": "value2"
}
}
order = client.order.create(data=data)
print(order)
# Expected output includes 'id' field, e.g., 'order_xxxxxxxxxxxxxx'
Node.js Quickstart: Create an Order
The Node.js SDK provides a similar straightforward approach to creating orders. This snippet shows the server-side logic for generating an order ID.
const Razorpay = require('razorpay');
// Initialize Razorpay client with your API keys
const instance = new Razorpay({
key_id: 'YOUR_KEY_ID',
key_secret: 'YOUR_KEY_SECRET',
});
// Create an order
async function createRazorpayOrder() {
const options = {
amount: 50000, // amount in paise (e.g., 50000 paise = INR 500.00)
currency: 'INR',
receipt: 'receipt#1',
notes: {
key1: 'value3',
key2: 'value2',
},
};
try {
const order = await instance.orders.create(options);
console.log(order);
// Expected output includes 'id' field, e.g., 'order_xxxxxxxxxxxxxx'
} catch (error) {
console.error(error);
}
}
createRazorpayOrder();
PHP Quickstart: Create an Order
This PHP example demonstrates the use of the Razorpay PHP SDK to create a server-side order. The generated order ID is then used for client-side payment processing.
<?php
require 'vendor/autoload.php';
use Razorpay\Api\Api;
// Initialize Razorpay client with your API keys
// Get your API keys from https://dashboard.razorpay.com/#/app/keys
$api = new Api("YOUR_KEY_ID", "YOUR_KEY_SECRET");
// Create an order
$orderData = [
'receipt' => 'receipt_1',
'amount' => 50000, // amount in paise (e.g., 50000 paise = INR 500.00)
'currency' => 'INR',
'payment_capture' => 1 // auto capture
];
$order = $api->order->create($orderData);
print_r($order->toArray());
// Expected output includes 'id' field, e.g., 'order_xxxxxxxxxxxxxx'
?>
After creating the order on the server, the order_id is typically passed to the client-side, where the Razorpay Checkout widget is invoked. The client-side integration involves using JavaScript (for web) or the respective mobile SDK (for Android/iOS) to display the payment form and handle the user's payment interaction. For detailed client-side implementation, refer to the Razorpay Checkout integration guide.
Community libraries
While Razorpay maintains a comprehensive set of official SDKs, the developer community also contributes various libraries and plugins. These community-driven projects can offer integrations with specific frameworks or provide additional utilities not covered by the official SDKs. For example, developers might find community contributions for CMS platforms, e-commerce solutions, or niche programming languages. Always evaluate the maturity, maintenance status, and security practices of any third-party library before integrating it into a production environment. Resources like GitHub and relevant developer forums are common places to discover such contributions. For example, searching for Razorpay-related projects on GitHub can reveal community-maintained tools and integrations.
While community libraries can be valuable, it's generally recommended to prioritize official SDKs for core payment processing due to their direct support, regular updates, and adherence to Razorpay's security standards, including PCI DSS Level 1 compliance.