Upgraded docs version is here ✨

Your documentation experience is getting an upgrade. Check it out now!

Go To Beta

Docs upgrade is here. Check it out!

Go To Beta
API ReferenceIntegrationsKnowledge Base

Sample Code

Generate API KeyπŸ”—

  1. Log into your Dashboard with appropriate credentials.
  2. Select the mode (Test or Live) for which you want to generate the API key.
    • Test Mode: The test mode is a simulation mode that you can use to test your integration flow. Your customers will not be able to make payments in this mode.
    • Live Mode: When your integration is complete, switch to live mode and generate live mode API keys. Replace test mode keys with live mode keys in the integration to accept payments from customers.
  3. Navigate to Settings β†’ API Keys β†’ Generate Key to generate key for the selected mode.

The Key Id and Key Secret appear on a pop-up page as shown below:

Test Mode API Keys

Live Mode API Keys

Watch Out!

  • After generating the keys from the Dashboard, download and save them securely. If you do not remember your API Keys, you need to re-generate them from the Dashboard and replace it wherever required.
  • Do not share your API Key secret with anyone or on any public platforms. This can pose security threats for your Razorpay account.
  • Once you generate the API Keys, only the Key Id is visible on the Dashboard and not the Key secret as it can pose security threats for your Razorpay account.

OrdersπŸ”—

Note:
Click here for request parameters and an example request and response.

Create an OrderπŸ”—

Copy$api->order->create(array('receipt' => '123', 'amount' => 100, 'currency' => 'INR', 'notes'=> array('key1'=> 'value3','key2'=> 'value2')));

Fetch Order by IDπŸ”—

Copy$api->order->fetch($orderId);

Fetch all Order ObjectsπŸ”—

Copy$api->order->all($options);

Fetch all Payment Objects for an OrderπŸ”—

Copy$api->order->fetch($orderId)->payments();

Update OrderπŸ”—

Copy$api->order->fetch($orderId)->edit(array('notes'=> array('notes_key_1'=>'Beam me up Scotty. 1', 'notes_key_2'=>'Engage')));

PaymentsπŸ”—

Note:
Click here for request parameters and an example request and response.

Capture a PaymentπŸ”—

Copy$api->payment->fetch($paymentId)->capture(array('amount'=>$amount,'currency' => 'INR'));

Fetch Payment by IDπŸ”—

Copy$api->payment->fetch($paymentId);

Fetch all PaymentsπŸ”—

Copy$api->payment->all($options)

Fetch Payments for an OrderπŸ”—

Copy$api->order->fetch($orderId)->payments();

Fetch Payment DetailsπŸ”—

Copyecho $payment->amount; echo $payment->currency; // And so on for other attributes

Fetch Expanded Card or EMI Details for PaymentsπŸ”—

Copy$api->payment->all(array('expand[]'=>'card')
Copy$api->payment->all(array('expand[]'=>'emi')

Fetch Card Details with Payment IDπŸ”—

Copy$api->payment->fetch($paymentId)->fetchCardDetails();

Update a PaymentπŸ”—

Copy$api->payment->fetch($paymentId)->edit(array('notes'=> array('key_1'=> 'value1','key_2'=> 'value2')));

Fetch Payment Downtime DetailsπŸ”—

Copy$api->payment->fetchPaymentDowntime();

Fetch Payment DowntimeπŸ”—

Copy$api->payment->fetchPaymentDowntimeById($downtimeId);

SettlementsπŸ”—

Note:
Click here for request parameters and an example request and response.

Fetch Settlement by IDπŸ”—

Copy$api->settlement->fetch($settlementId);

Fetch all SettlementsπŸ”—

Copy$api->settlement->all($options);

Fetch all Report Objects for SettlementsπŸ”—

Copy$api->settlement->reports(array("year"=>2020,"month"=>09));

Settlement ReconπŸ”—

Copy$api->settlement->settlementRecon(array('year' => 2018, 'month' =>02, 'day'=>11));

Create On-demand SettlementπŸ”—

Copy$api->settlement->createOndemandSettlement(array("amount"=> 1221, "settle_full_balance"=> false, "description"=>"Testing","notes" => array("notes_key_1"=> "Tea, Earl Grey, Hot","notes_key_2"=> "Tea, Earl Grey… decaf.")));

Fetch all On-demand SettlementsπŸ”—

Copy$api->settlement->fetchAllOndemandSettlement($options);

Fetch On-demand Settlement by IDπŸ”—

Copy$api->settlement->fetch($settlementId)->fetchOndemandSettlementById();

RefundsπŸ”—

Note:
Click here for request parameters and an example request and response.

Create a Normal RefundπŸ”—

Copy$api->payment->fetch($paymentId)->refund(array("amount"=> "100", "speed"=>"normal", "notes"=>array("notes_key_1"=>"Beam me up Scotty.", "notes_key_2"=>"Engage"), "receipt"=>"Receipt No. 31"));

Create a Partial RefundπŸ”—

Copy$refund = $api->refund->create(array('payment_id' => $id, 'amount'=>$refundAmount));

Create an Instant RefundπŸ”—

Copy$$api->payment->fetch($paymentId)->refund(array("amount"=> "100","speed"=>"optimum","receipt"=>"Receipt No. 31"));

Fetch Refund by IDπŸ”—

Copy$api->refund->fetch($refundId);

Fetch all RefundsπŸ”—

Copy$api->refund->all($options);

Fetch a Specific Refund for a PaymentπŸ”—

Copy$api->payment->fetch($paymentId)->fetchRefund($refundId);

Fetch Multiple Refunds for a PaymentπŸ”—

Copy$api->payment->fetch($paymentId)->fetchMultipleRefund($option);

Update a RefundπŸ”—

Copy$api->refund->fetch($refundId)->edit(array('notes'=> array('notes_key_1'=>'Beam me up Scotty.', 'notes_key_2'=>'Engage')));

CustomersπŸ”—

Note:
Click here for request parameters and an example request and response.

Create a CustomerπŸ”—

Copy$api->customer->create(array('name' => 'Gaurav Kumar', 'email' => 'gaurav.kumar@example.com','contact'=>'9123456780','notes'=> array('notes_key_1'=> 'Tea, Earl Grey, Hot','notes_key_2'=> 'Tea, Earl Grey… decaf'));

Fetch Customer by IDπŸ”—

Copy$api->customer->fetch($customerId)

Fetch all CustomersπŸ”—

Copy$api->customer->all($options)

Edit CustomerπŸ”—

Copy$api->customer->fetch($customerId)->edit(array('name' => 'Gaurav Kumar', 'email' => 'gaurav.kumar@example.com','notes'=> array('notes_key_1'=> 'Tea, Earl Grey, Hot','notes_key_2'=> 'Tea, Earl Grey… decaf')));

SubscriptionsπŸ”—

Note:
Click here for request parameters and an example request and response.

Create a PlanπŸ”—

Copy$api->plan->create(array('period' => 'weekly', 'interval' => 1, 'item' => array('name' => 'Test Weekly 1 plan', 'description' => 'Description for the weekly 1 plan', 'amount' => 600, 'currency' => 'INR'),'notes'=> array('key1'=> 'value3','key2'=> 'value2')));

Fetch Plan by IDπŸ”—

Copy$api->plan->fetch($planId);

Fetch all PlansπŸ”—

Copy$api->plan->all($options);

Create a SubscriptionπŸ”—

Copy$api->subscription->create(array('plan_id' => 'plan_7wAosPWtrkhqZw', 'customer_notify' => 1,'quantity'=>5, 'total_count' => 6, 'start_at' => 1495995837, 'addons' => array(array('item' => array('name' => 'Delivery charges', 'amount' => 30000, 'currency' => 'INR'))),'notes'=> array('key1'=> 'value3','key2'=> 'value2')));
Copy$api->subscription->create(array('plan_id' => 'plan_HoYg68p5kmuvzD','total_count' => 12,'quantity' => 1,'expire_by' => 1633237807,'customer_notify' => 1, 'addons' => array(array('item'=>array('name' => 'Delivery charges','amount' => 30000,'currency' => 'INR'))),'notes'=>array('notes_key_1'=>'Tea, Earl Grey, Hot','notes_key_2'=>'Tea, Earl Grey… decaf.'),'notify_info'=>array('notify_phone' => '9123456789','notify_email'=> 'gaurav.kumar@example.com')));

Fetch Subscription by IDπŸ”—

Copy$api->subscription->fetch($subscriptionId);

Fetch all SubscriptionsπŸ”—

Copy$api->subscription->all($options);

Cancel a SubscriptionπŸ”—

Copy$api->subscription->fetch($subscriptionId)->cancel($options);

Note:
$options = ['cancel_at_cycle_end' => 1];

Update a SubscriptionπŸ”—

Copy$api->subscription->fetch($subscriptionId)->update($options);

Fetch Details of a Pending UpdateπŸ”—

Copy$api->subscription->fetch($subscriptionId)->pendingUpdate()

Cancel an UpdateπŸ”—

Copy$api->subscription->fetch($subscriptionId)->cancelScheduledChanges();

Pause a SubscriptionπŸ”—

Copy$api->subscription->fetch($subscriptionId)->pause(array('pause_at'=>'now'))

Resume a SubscriptionπŸ”—

Copy$api->subscription->fetch($subscriptionId)->resume(array('resume_at'=>'now'))

Fetch All Invoices for a SubscriptionπŸ”—

Copy$api->invoice->all(['subscription_id'=>$subscriptionId]);

Payment VerificationπŸ”—

Copy$api->utility->verifyPaymentSignature($options)

Create an Add-onπŸ”—

Copy$api->subscription->fetch($subscriptionId)->createAddon(array('item' => array('name' => 'Extra Chair', 'amount' => 30000, 'currency' => 'INR'), 'quantity' => 2))

Fetch Add-on by IDπŸ”—

Copy$api->addon->fetch($addonId);

Fetch all Add-onsπŸ”—

Copy$api->addon->all($options);

Delete an Add-onπŸ”—

Copy$api->addon->fetch($addonId)->delete();

Payment LinksπŸ”—

Note:
Click here for request parameters and an example request and response.

Copy$api->paymentLink->create(array('amount'=>500, 'currency'=>'INR', 'accept_partial'=>true, 'first_min_partial_amount'=>100, 'description' => 'For XYZ purpose', 'customer' => array('name'=>'Gaurav Kumar', 'email' => 'gaurav.kumar@example.com', 'contact'=>'+919999999999'), 'notify'=>array('sms'=>true, 'email'=>true) , 'reminder_enable'=>true ,'notes'=>array('policy_name'=> 'Jeevan Bima'),'callback_url' => 'https://example-callback-url.com/', 'callback_method'=>'get'));
Copy$api->paymentLink->create(array('upi_link'=>true,'amount'=>500, 'currency'=>'INR', 'accept_partial'=>true, 'first_min_partial_amount'=>100, 'description' => 'For XYZ purpose', 'customer' => array('name'=>'Gaurav Kumar', 'email' => 'gaurav.kumar@example.com', 'contact'=>'+919999999999'), 'notify'=>array('sms'=>true, 'email'=>true) , 'reminder_enable'=>true ,'notes'=>array('policy_name'=> 'Jeevan Bima')));
Copy$api->paymentLink->fetch($paymentLinkId);
Copy$api->paymentLink->all();
Copy$api->paymentLink->fetch($paymentLinkId)->cancel();

Send or Resend NotificationsπŸ”—

Copy$api->paymentLink->fetch($paymentLinkId)->notifyBy($medium));
Copy$api->paymentLink->fetch($paymentLinkId)->edit(array("reference_id"=>"TS42", "expire_by"=>"1640270451" , "reminder_enable"=>0, "notes"=>["policy_name"=>"Jeevan Saral 2"]));

InvoicesπŸ”—

Note:
Click here for request parameters and an example request and response.

Create an InvoiceπŸ”—

Copy$api->invoice->create(array ('type' => 'invoice','date' => 1589994898, 'customer_id'=> 'cust_E7q0trFqXgExmT', 'line_items'=>array(array('item_id'=>'item_DRt61i2NnL8oy6'))));

Update an InvoiceπŸ”—

Copy$api->invoice->fetch($invoiceId)->edit(array('line_items' => array(array('id' => 'li_DAweOizsysoJU6','name' => 'Book / English August - Updated name and quantity','quantity' => 1),array('name' => 'Book / A Wild Sheep Chase','amount' => 200,'currency' => 'INR','quantity' => 1)),'notes' => array('updated-key' => 'An updated note.')));

Issue an InvoiceπŸ”—

Copy$api->invoice->fetch($invoiceId)->issue();

Send/Resend NotificationsπŸ”—

Copy$api->invoice->fetch($invoiceId)->notify($medium);

Fetch Invoice by IDπŸ”—

Copy$api->invoice->fetch($invoiceId);

Fetch all InvoicesπŸ”—

Copy$api->invoice->all();

Cancel an InvoiceπŸ”—

Copy$api->invoice->fetch($invoiceId)->cancel();

Delete an InvoiceπŸ”—

Copy$api->invoice->fetch($invoiceId)->delete();

Smart CollectπŸ”—

Note:
Click here for request parameters and an example request and response.

Create a Virtual AccountπŸ”—

Copy$api->virtualAccount->create(array('receivers' => array('types'=> arra('bank_account')),'allowed_payers' => array(array('type'=>'bank_account','bank_account'=>array('ifsc'=>'RATN0VAAPIS','account_number'=>'2223330027558515'))),'description' => 'Virtual Account created for Raftar Soft','customer_id' => 'cust_HssUOFiOd2b1TJ', 'notes' => array('project_name' => 'Banking Software')));

Create Static/Dynamic QRπŸ”—

Copy$api->virtualAccount->create(array('receivers' => array('types' => array('qr_code')), 'description' => 'First QR code', 'amount_expected' => 100, 'notes' => array('receiver_key' => 'receiver_value')));

Fetch Virtual Account by IDπŸ”—

Copy$api->virtualAccount->fetch($virtualId);

Fetch all Virtual AccountsπŸ”—

Copy$api->virtualAccount->all($options);

Fetch Payment made to a Virtual Account by IDπŸ”—

Copy$bankTransfer = $api->payment->fetch($payment_id)->bankTransfer();

Fetch all Payments made to a Virtual AccountπŸ”—

Copy$payments = $virtualAccount->payments();

Fetch Payments for a Virtual AccountπŸ”—

Copy$api->virtualAccount->fetch($virtualId)->payments($options);

Fetch Payment Details using ID and Transfer MethodπŸ”—

Copy$api->payment->fetch($virtualId)->bankTransfer();

Refund Payments made to a Virtual AccountπŸ”—

Copy$api->payment->fetch($paymentId)->refunds();

Add Receiver to an Existing Virtual AccountπŸ”—

Copy$api->virtualAccount->fetch($virtualId)->addReceiver(array('types' => array('vpa'),'vpa' => array('descriptor'=>'gauravkumar')));

Close a Virtual AccountπŸ”—

Copy$api->virtualAccount->fetch($virtualId)->close();

RouteπŸ”—

Note:
Click here for request parameters and an example request and response.

Create Transfers from PaymentsπŸ”—

Copy$api->payment->fetch($paymentId)->transfer(array('transfers' => array('account'=> $accountId, 'amount'=> '1000', 'currency'=>'INR', 'notes'=> array('name'=>'Gaurav Kumar', 'roll_no'=>'IEC2011025'), 'linked_account_notes'=>array('branch'), 'on_hold'=>'1', 'on_hold_until'=>'1671222870')));

Create Transfers from OrdersπŸ”—

Copy$api->order->create(array('amount' => 2000,'currency' => 'INR','transfers' => array(array('account' => 'acc_CPRsN1LkFccllA','amount' => 1000,'currency' => 'INR','notes' => array('branch' => 'Acme Corp Bangalore North','name' => 'Gaurav Kumar'),'linked_account_notes' => array('branch'),'on_hold' => 1,'on_hold_until' => 1671222870),array('account' => 'acc_CNo3jSI8OkFJJJ','amount' => 1000,'currency' => 'INR','notes' => array('branch' => 'Acme Corp Bangalore South','name' => 'Saurav Kumar'),'linked_account_notes' => array('branch'),'on_hold' => 0))));

Direct TransfersπŸ”—

Copy$api->transfer->create(array('account' => $accountId, 'amount' => 500, 'currency' => 'INR'));

Edit a TransferπŸ”—

Copy$transfer = $api->transfer->fetch($transfer_id)->edit($options);

Fetch Transfer for a PaymentπŸ”—

Copy$api->payment->fetch($paymentId)->transfer();

Fetch Transfer for an OrderπŸ”—

Copy$api->order->fetch($orderId)->transfers(array('expand[]'=>'transfers'));

Fetch a TransferπŸ”—

Copy$api->transfer->fetch($transferId);

Fetch all TransfersπŸ”—

Copy$transfers = $api->transfer->all();

Fetch Transfers for a SettlementπŸ”—

Copy$api->transfer->all(array('recipient_settlement_id'=> $recipientSettlementId));

Fetch Settlement DetailsπŸ”—

Copy$api->transfer->all(array('expand[]'=> 'recipient_settlement'));

Fetch Payments of a Linked AccountπŸ”—

Copy$api->payment->all(array('X-Razorpay-Account'=> $linkedAccountId));

Refund Payments and Reverse Transfer from a Linked AccountπŸ”—

Copy$api->payment->fetch($paymentId)->refund(array('amount'=> '100','reverse_all'=>'1'));

Reverse a TransferπŸ”—

Copy$api->transfer->fetch($transferId)->reverse(array('amount'=>'100'));

Hold Settlements For TransfersπŸ”—

Copy$api->payment->fetch($paymentId)->transfer(array('account' => $accountId, 'amount' => 500, 'currency' => 'INR','on_hold'=>'1'));

Modify Settlement Hold for TransfersπŸ”—

Copy$api->transfer->fetch($paymentId)->edit(array('on_hold' => '1', 'on_hold_until' => '1679691505'));

QR CodeπŸ”—

Note:
Click here for request parameters and an example request and response.

Create QR CodesπŸ”—

Copy$api->qrCode->create(array("type" => "upi_qr","name" => "Store_1", "usage" => "single_use","fixed_amount" => 1,"payment_amount" => 300,"customer_id" => "cust_HKsR5se84c5LTO","description" => "For Store 1","close_by" => 1681615838,"notes" => array("purpose" => "Test UPI QR code notes")));

Create QR Code with GSTπŸ”—

Copy$api->qrCode->create(array("type" => "upi_qr","name" => "Store_1", "usage" => "single_use","fixed_amount" => 1,"payment_amount" => 300,"customer_id" => "cust_HKsR5se84c5LTO","description" => "For Store 1","close_by" => 1681615838,"notes" => array("purpose" => "Test UPI QR code notes"),"tax_invoice" => array("number" => "INV001", "date" => 1589994898,"customer_name" => "Gaurav Kumar", "business_gstin"=> "06AABCU9605R1ZR","gst_amount" => 4000, "cess_amount" => 0, "supply_type" => "interstate")));

Fetch All QR CodesπŸ”—

Copy$api->qrCode->all($options)

Fetch a QR CodeπŸ”—

Copy$api->qrCode->fetch($qrCodeId)

Fetch a QR Code for Customer IDπŸ”—

Copy $api->qrCode->all(["customer_id" => $customerId])

Fetch a QR Code for Payment IDπŸ”—

Copy $api->qrCode->all(["payment_id" => $paymentId])

Fetch Payments for a QR CodeπŸ”—

Copy$api->qrCode->fetch($qrCodeId)->fetchAllPayments($options)

Close a QR CodeπŸ”—

Copy$api->qrCode->fetch($qrCodeId)->close()
×