### Install Requests with Composer Source: https://github.com/razorpay/razorpay-php/blob/master/libs/Requests-2.0.4/README.md Instructions for adding the Requests library to your PHP project using Composer. ```sh composer require rmccue/requests ``` ```json { "require": { "rmccue/requests": "^2.0" } } ``` -------------------------------- ### Making a GET Request with Headers and Options Source: https://github.com/razorpay/razorpay-php/blob/master/libs/Requests-2.0.4/README.md Demonstrates how to make a GET request to an API endpoint, including custom headers and authentication options. Accesses the response status code, content type, and body. ```php $headers = array('Accept' => 'application/json'); $options = array('auth' => array('user', 'pass')); $request = WpOrg\Requests\Requests::get('https://api.github.com/gists', $headers, $options); var_dump($request->status_code); // int(200) var_dump($request->headers['content-type']); // string(31) "application/json; charset=utf-8" var_dump($request->body); // string(26891) "[...]" ``` -------------------------------- ### Install Source from Zip/Tarball Source: https://github.com/razorpay/razorpay-php/blob/master/libs/Requests-2.0.4/README.md Provides commands to download and extract the Requests library source code using curl or wget. ```bash $ curl -L https://github.com/WordPress/Requests/tarball/stable | tar xzv (or) $ wget https://github.com/WordPress/Requests/tarball/stable -O - | tar xzv ``` -------------------------------- ### Subscription Creation Response Source: https://github.com/razorpay/razorpay-php/blob/master/documents/subscription.md This is an example of the JSON response received after successfully creating a subscription. It includes details like the subscription ID, plan ID, status, and counts. ```json { "id": "sub_00000000000001", "entity": "subscription", "plan_id": "plan_00000000000001", "status": "created", "current_start": null, "current_end": null, "ended_at": null, "quantity": 1, "notes":{ "notes_key_1":"Tea, Earl Grey, Hot", "notes_key_2":"Tea, Earl Grey… decaf." }, "charge_at": 1580453311, "start_at": 1580626111, "end_at": 1583433000, "auth_attempts": 0, "total_count": 6, "paid_count": 0, "customer_notify": true, "created_at": 1580280581, "expire_by": 1580626111, "short_url": "https://rzp.io/i/z3b1R61A9", "has_scheduled_changes": false, "change_scheduled_at": null, "source": "api", "offer_id":"offer_JHD834hjbxzhd38d", "remaining_count": 5 } ``` -------------------------------- ### Virtual Accounts Source: https://context7.com/razorpay/razorpay-php/llms.txt Examples for creating, fetching, and managing virtual accounts using the Razorpay PHP SDK. ```APIDOC ## Virtual Accounts ### Create virtual accounts to accept bank transfers This section demonstrates how to create virtual accounts with different receiver types (bank account, UPI VPA) and configurations like allowed payers. #### Create virtual account with bank account receiver ```php // Create a virtual account with a bank account receiver $va = $api->virtualAccount->create([ 'receivers' => ['types' => ['bank_account']], 'description' => 'Collect payment for Order #101', 'customer_id' => 'cust_CaVDm8eDRSXYME', 'close_by' => 1681615838, 'notes' => ['project_name' => 'Banking Software'], ]); // {"id":"va_DlGmm7jInLudH9","status":"active","receivers":[{"account_number":"2223330099089860",...}]} ``` #### Create virtual account with UPI VPA receiver ```php // Create a virtual account with UPI VPA receiver $va = $api->virtualAccount->create([ 'receivers' => ['types' => ['vpa']], 'description' => 'VPA collection account', 'customer_id' => 'cust_IOyIY3JvbVny9o', 'amount_expected' => 50000, ]); ``` #### Create virtual account with Third-Party Validation (TPV) ```php // Create with Third-Party Validation (TPV) — restrict allowed payer accounts $va = $api->virtualAccount->create([ 'receivers' => ['types' => ['bank_account']], 'allowed_payers' => [ ['type' => 'bank_account', 'bank_account' => ['ifsc' => 'RATN0VAAPIS', 'account_number' => '2223330027558515']], ], 'customer_id' => 'cust_HssUOFiOd2b1TJ', ]); ``` ### Fetch a virtual account ```php // Fetch a virtual account $va = $api->virtualAccount->fetch('va_JccTXwXA6UG4Gi'); ``` ### Fetch all virtual accounts ```php // Fetch all virtual accounts $vas = $api->virtualAccount->all(['count' => 10]); ``` ### Fetch payments received by a virtual account ```php // Fetch payments received by a virtual account $payments = $api->virtualAccount->fetch('va_JccTXwXA6UG4Gi')->payments(); ``` ### Fetch bank transfer details for a payment ```php // Fetch bank transfer details for a payment $bankTransfer = $api->payment->fetch('pay_Di5iqCqA1WEHq6')->bankTransfer(); ``` ### Add a new receiver type to an existing virtual account ```php // Add a new receiver type to an existing virtual account $api->virtualAccount->fetch('va_JccTXwXA6UG4Gi') ->addReceiver(['types' => ['vpa'], 'vpa' => ['descriptor' => 'gauravkumar']]); ``` ### Add an allowed payer account (TPV) ```php // Add an allowed payer account (TPV) $api->virtualAccount->fetch('va_JccTXwXA6UG4Gi')->addAllowedPayer([ 'type' => 'bank_account', 'bank_account' => ['ifsc' => 'UTIB0000013', 'account_number' => '914010012345679'], ]); ``` ### Delete an allowed payer account ```php // Delete an allowed payer account $api->virtualAccount->fetch('va_JccTXwXA6UG4Gi')->deleteAllowedPayer('ba_DlGmm9mSj8fjRM'); ``` ### Close a virtual account ```php // Close a virtual account $api->virtualAccount->fetch('va_JccTXwXA6UG4Gi')->close(); ``` ``` -------------------------------- ### Payment Link Creation Response (JSON) Source: https://github.com/razorpay/razorpay-php/blob/master/documents/paymentLink.md This is an example of the JSON response received after successfully creating a payment link. It includes details such as the payment link ID, status, amount, customer information, and URLs. ```json { "accept_partial": true, "amount": 1000, "amount_paid": 0, "callback_method": "", "callback_url": "", "cancelled_at": 0, "created_at": 1596193199, "currency": "INR", "customer": { "contact": "+919999999999", "email": "gaurav.kumar@example.com", "name": "Gaurav Kumar" }, "deleted_at": 0, "description": "Payment for policy no #23456", "expire_by": 0, "expired_at": 0, "first_min_partial_amount": 100, "id": "plink_FL4vbXVKfW7PAz", "notes": null, "notify": { "email": true, "sms": true }, "payments": null, "reference_id": "#42321", "reminder_enable": true, "reminders": [], "short_url": "https://rzp.io/i/F4GC9z1", "source": "", "source_id": "", "status": "created", "updated_at": 1596193199, "user_id": "" } ``` -------------------------------- ### Payment Link Creation Response (JSON) Source: https://github.com/razorpay/razorpay-php/blob/master/documents/paymentLink.md This is an example of the JSON response received after successfully creating a payment link. It includes details such as the payment link ID, status, amount, customer information, and notification settings. ```json { "accept_partial": true, "amount": 1000, "amount_paid": 0, "callback_method": "", "callback_url": "", "cancelled_at": 0, "created_at": 1596188371, "currency": "INR", "customer": { "contact": "+919999999999", "email": "gaurav.kumar@example.com", "name": "Gaurav Kumar" }, "deleted_at": 0, "description": "Payment for policy no #23456", "expire_by": 0, "expired_at": 0, "first_min_partial_amount": 100, "id": "plink_FL3YbdvN2Cj6gh", "notes": null, "notify": { "email": true, "sms": true }, "payments": null, "reference_id": "#543422", "reminder_enable": true, "reminders": [], "short_url": "https://rzp.io/i/wKiXKud", "source": "", "source_id": "", "status": "created", "updated_at": 1596188371, "user_id": "" } ``` -------------------------------- ### Run Specific Test Suite Source: https://github.com/razorpay/razorpay-php/blob/master/libs/Requests-2.0.4/README.md Execute a specific set of tests by providing the test suite name. For example, to run tests for the Transport/cURL component. ```bash $ phpunit Transport/cURL ``` -------------------------------- ### Fetch and Manage Settlements with Razorpay PHP SDK Source: https://context7.com/razorpay/razorpay-php/llms.txt Use these methods to retrieve all settlements, fetch specific settlement details, get settlement reports, reconcile daily settlements, and create on-demand settlements. Ensure you have the API client initialized. ```php // Fetch all settlements $settlements = $api->settlement->all(['count' => 10, 'from' => 1509000000]); ``` ```php // Fetch a specific settlement $settlement = $api->settlement->fetch('setl_DGlQ1Rj8os78Ec'); // {"id":"setl_DGlQ1Rj8os78Ec","amount":9973635,"status":"processed","utr":"1568176960vxp0rj"} ``` ```php // Fetch settlement report for a month (line-item breakdown) $report = $api->settlement->reports(['year' => 2020, 'month' => 9]); // Returns each payment/refund/transfer/adjustment with settlement details ``` ```php // Settlement reconciliation for a specific day $recon = $api->settlement->settlementRecon(['year' => 2020, 'month' => 9, 'day' => 15]); ``` ```php // Create an on-demand (instant) settlement $ondemand = $api->settlement->createOndemandSettlement([ 'amount' => 200000, 'settle_full_balance' => false, 'description' => 'Vendor payment', 'notes' => ['notes_key_1' => 'Urgent payout'], ]); // {"id":"setlod_FNj7g2YS5J67Rz","status":"initiated","amount_requested":200000} ``` ```php // Fetch all on-demand settlements $api->settlement->fetchAllOndemandSettlement(['expand[]' => 'ondemand_payouts']); ``` ```php // Fetch on-demand settlement by ID with payout details $api->settlement->fetchOndemandSettlementById('setlod_MI0c34SIRVT25W', ['expand[]' => 'ondemand_payouts']); ``` -------------------------------- ### Run Test Suite Source: https://github.com/razorpay/razorpay-php/blob/master/libs/Requests-2.0.4/README.md Execute the library's test suite using PHPUnit. Ensure the PHP JSON extension is enabled. ```bash $ phpunit ``` -------------------------------- ### Fetch Payments Received by a Virtual Account Source: https://context7.com/razorpay/razorpay-php/llms.txt Get a list of all payments that have been received by a specific virtual account. ```php // Fetch payments received by a virtual account $payments = $api->virtualAccount->fetch('va_JccTXwXA6UG4Gi')->payments(); ``` -------------------------------- ### Create Payment Link with Offers Source: https://github.com/razorpay/razorpay-php/blob/master/documents/paymentLink.md This snippet shows how to create a payment link and apply a specific offer to it. ```APIDOC ## POST /paymentLink ### Description Creates a payment link that allows customers to make payments. This example demonstrates how to associate an offer with the payment link. ### Method POST ### Endpoint /paymentLink ### Parameters #### Request Body - **amount** (integer) - Required - Amount to be paid using the Payment Link. - **currency** (string) - Required - A three-letter ISO code for the currency in which you want to accept the payment. For example, INR. - **description** (string) - Optional - A brief description of the Payment Link. - **reference_id** (string) - Optional - A reference number tagged to a Payment Link. - **customer** (array) - Optional - Customer details (name, email, contact). - **expire_by** (integer) - Optional - Timestamp, in Unix, at which the Payment Link will expire. By default, a Payment Link will be valid for six months from the date of creation. - **notify** (object) - Optional - Notification preferences. - **sms** (boolean) - Optional - Enable SMS notifications. - **email** (boolean) - Optional - Enable email notifications. - **options** (array) - Required - Options to associate the offer_id with the Payment Link. Parent parameter under which the order child parameter must be passed. - **order** (array) - **offers** (array) - Required - An array containing the offer ID(s) to be applied. - **offer_id** (string) - The ID of the offer to apply. ### Request Example ```php $api->paymentLink->create(array( 'amount'=>20000, 'currency'=>'INR', 'accept_partial'=>false, 'description' => 'For XYZ purpose', 'customer' => array('name'=>'Gaurav Kumar', 'email' => 'gaurav.kumar@example.com', 'contact'=>'+919999999999'), 'notify'=>array('sms'=>true, 'email'=>true), 'reminder_enable'=>false, 'options'=>array('order'=>array('offers'=>array('offer_I0PqexIiTmMRnA'))) )); ``` ### Response #### Success Response (200) - **id** (string) - Unique identifier for the payment link. - **entity** (string) - Type of entity created (e.g., 'payment_link'). - **amount** (integer) - The total amount of the payment link. - **amount_paid** (integer) - The amount that has been paid so far. - **currency** (string) - The currency of the payment link. - **description** (string) - Description of the payment link. - **status** (string) - Current status of the payment link (e.g., 'created'). - **created_at** (integer) - Timestamp when the payment link was created. - **updated_at** (integer) - Timestamp when the payment link was last updated. - **short_url** (string) - A shortened URL for the payment link. - **customer** (object) - Details of the customer associated with the payment link. - **notify** (object) - Notification settings. - **reminder_enable** (boolean) - Indicates if reminders are enabled. #### Response Example ```json { "accept_partial": false, "amount": 3400, "amount_paid": 0, "cancelled_at": 0, "created_at": 1600183040, "currency": "INR", "customer": { "contact": "+919999999999", "email": "gaurav.kumar@example.com", "name": "Gaurav Kumar" }, "description": "Payment for policy no #23456", "expire_by": 0, "expired_at": 0, "first_min_partial_amount": 0, "id": "plink_FdLt0WBldRyE5t", "notes": null, "notify": { "email": true, "sms": true }, "payments": null, "reference_id": "#425", "reminder_enable": false, "reminders": [], "short_url": "https://rzp.io/i/CM5ohDC", "status": "created", "user_id": "" } ``` ``` -------------------------------- ### Payment Links Source: https://context7.com/razorpay/razorpay-php/llms.txt Examples for creating, fetching, updating, canceling, and managing notifications for payment links using the Razorpay PHP SDK. ```APIDOC ## Payment Links ### Create shareable payment links This section covers creating standard and UPI-only payment links with various options like partial payments, expiry, customer details, and notifications. #### Create a standard payment link with partial payment support ```php // Create a standard payment link with partial payment support $link = $api->paymentLink->create([ 'amount' => 500, 'currency' => 'INR', 'accept_partial' => true, 'first_min_partial_amount' => 100, 'expire_by' => 1691097057, 'reference_id' => 'TS1989', 'description' => 'For XYZ purpose', 'customer' => [ 'name' => 'Gaurav Kumar', 'email' => 'gaurav.kumar@example.com', 'contact' => '+919999999999', ], 'notify' => ['sms' => true, 'email' => true], 'reminder_enable' => true, 'notes' => ['policy_name' => 'Jeevan Bima'], 'callback_url' => 'https://example-callback-url.com/', 'callback_method' => 'get', ]); // {"id":"plink_...","short_url":"https://rzp.io/i/...","status":"created"} ``` #### Create a UPI-only payment link ```php // Create a UPI-only payment link $api->paymentLink->create([ 'upi_link' => true, 'amount' => 500, 'currency' => 'INR', 'description' => 'UPI-only payment', 'customer' => ['name' => 'Gaurav Kumar', 'contact' => '+919999999999'], ]); ``` ### Fetch all payment links ```php // Fetch all payment links $links = $api->paymentLink->all(['reference_id' => 'TS1989']); ``` ### Fetch a specific payment link ```php // Fetch a specific payment link $link = $api->paymentLink->fetch('plink_FMbhpT6nqDjDei'); ``` ### Update a payment link ```php // Update a payment link $api->paymentLink->fetch('plink_FMbhpT6nqDjDei')->edit([ 'reference_id' => 'TS42', 'expire_by' => 1640270451, 'reminder_enable' => 0, 'notes' => ['policy_name' => 'Jeevan Saral 2'], ]); ``` ### Cancel a payment link ```php // Cancel a payment link $api->paymentLink->fetch('plink_FMbhpT6nqDjDei')->cancel(); ``` ### Resend notification via SMS or email ```php // Resend notification via SMS or email $api->paymentLink->fetch('plink_FMbhpT6nqDjDei')->notifyBy('sms'); // {"success":true} ``` ``` -------------------------------- ### Include Autoloader from GitHub Source Source: https://github.com/razorpay/razorpay-php/blob/master/libs/Requests-2.0.4/README.md Shows how to include the Requests autoloader after cloning the source code from GitHub. ```php require_once '/path/to/Requests/src/Autoload.php'; WpOrg\Requests\Autoload::register(); ``` -------------------------------- ### Create an order Source: https://context7.com/razorpay/razorpay-php/llms.txt Create a new order server-side before displaying the checkout to the customer. The amount is specified in paise. ```APIDOC ## Create an order An order must be created server-side before showing the checkout to the customer. The `amount` is in paise (100 paise = ₹1). ```php use Razorpay\Api\Api; $api = new Api('rzp_test_XXXXXXXXXXXX', 'your_key_secret'); try { $order = $api->order->create([ 'amount' => 50000, // ₹500.00 in paise 'currency' => 'INR', 'receipt' => 'receipt#1', 'notes' => [ 'customer_name' => 'Gaurav Kumar', 'product_id' => 'SKU-1234', ], 'partial_payment' => false, ]); echo $order['id']; // "order_EKwxwAgItmmXdp" echo $order['status']; // "created" echo $order['amount']; // 50000 } catch (\Razorpay\Api\Errors\Error $e) { echo $e->getMessage(); } // Fetch a specific order $order = $api->order->fetch('order_EKwxwAgItmmXdp'); // Fetch all orders with pagination $orders = $api->order->all(['count' => 10, 'skip' => 0]); // Update order notes $api->order->fetch('order_EKwxwAgItmmXdp')->edit([ 'notes' => ['notes_key_1' => 'Beam me up Scotty.'], ]); // Fetch payments for an order $payments = $api->order->fetch('order_EKwxwAgItmmXdp')->payments(); ``` ``` -------------------------------- ### Server-to-Server (S2S) Payment Creation Source: https://context7.com/razorpay/razorpay-php/llms.txt Guides on creating payments using server-to-server integration, including card payments and UPI payments with different flows. ```APIDOC ## Server-to-Server (S2S) Payment Creation ### Description This section details how to create payments using server-to-server integration. It covers creating card payments with detailed card and browser information, and UPI payments using the 'collect' flow. ### Create a card payment via S2S integration ```php // Create a card payment via S2S integration $response = $api->payment->createPaymentJson([ 'amount' => 100, 'currency' => 'INR', 'order_id' => 'order_DPzFe1Q1dEOKed', 'email' => 'gaurav.kumar@example.com', 'contact' => '9000090000', 'method' => 'card', 'card' => [ 'number' => '4386289407660153', 'name' => 'Gaurav', 'expiry_month' => 11, 'expiry_year' => 30, 'cvv' => 100, ], 'authentication' => ['authentication_channel' => 'browser'], 'browser' => [ 'java_enabled' => false, 'javascript_enabled' => false, 'timezone_offset' => 11, 'color_depth' => 23, 'screen_width' => 1920, 'screen_height' => 1080, ], ]); // Response: {"razorpay_payment_id":"pay_FVmAstJWfsD3SO","next":[{"action":"redirect","url":"..."}]} ``` ### UPI S2S – collect flow (VPA) ```php // UPI S2S – collect flow (VPA) $response = $api->payment->createUpi([ 'amount' => 200, 'currency' => 'INR', 'order_id' => 'order_Jhgp4wIVHQrg5H', 'email' => 'gaurav.kumar@example.com', 'contact' => '9123456789', 'method' => 'upi', 'customer_id' => 'cust_EIW4T2etiweBmG', 'save' => true, 'ip' => '192.168.0.103', 'referer' => 'http', 'user_agent' => 'Mozilla/5.0', 'upi' => ['flow' => 'collect', 'vpa' => 'gauravkumar@exampleupi', 'expiry_time' => 5], ]); ``` ### Validate a VPA before initiating UPI payment ```php // Validate a VPA before initiating UPI payment $result = $api->payment->validateVpa(['vpa' => 'gauravkumar@exampleupi']); // {"vpa":"gauravkumar@exampleupi","success":true,"customer_name":"Gaurav Kumar"} ``` ``` -------------------------------- ### Create a Subscription in Razorpay Source: https://context7.com/razorpay/razorpay-php/llms.txt Sets up a recurring subscription for a customer. Specify plan ID, total billing cycles, and optional addons. ```php // Create a subscription $subscription = $api->subscription->create([ 'plan_id' => 'plan_Jc7wDk5iZX88wx', 'total_count' => 6, // total billing cycles 'quantity' => 1, 'customer_notify' => true, 'start_at' => 1580453311, // Unix timestamp 'expire_by' => 1580626111, 'addons' => [ ['item' => ['name' => 'Delivery charges', 'amount' => 30000, 'currency' => 'INR']], ], 'notes' => ['plan_type' => 'premium'], ]); // {"id":"sub_00000000000001","status":"created","short_url":"https://rzp.io/i/z3b1R61A9",...} ``` -------------------------------- ### Create Payment Link with Offers Source: https://github.com/razorpay/razorpay-php/blob/master/documents/paymentLink.md This snippet demonstrates how to create a payment link and associate it with a specific offer using its ID. The offer ID should be valid and active. ```php $api->paymentLink->create(array('amount'=>20000, 'currency'=>'INR', 'accept_partial'=>false, 'description' => 'For XYZ purpose', 'customer' => array('name'=>'Gaurav Kumar', 'email' => 'gaurav.kumar@example.com', 'contact'=>'+919999999999'), 'notify'=>array('sms'=>true, 'email'=>true) ,'reminder_enable'=>false , 'options'=>array('order'=>array('offers'=>array('offer_I0PqexIiTmMRnA'))))); ``` -------------------------------- ### Create Standard Payment Link Source: https://context7.com/razorpay/razorpay-php/llms.txt Create a standard payment link with options for partial payments, expiry, customer details, and notifications. Use 'accept_partial' and 'first_min_partial_amount' for partial payment support. ```php // Create a standard payment link with partial payment support $link = $api->paymentLink->create([ 'amount' => 500, 'currency' => 'INR', 'accept_partial' => true, 'first_min_partial_amount' => 100, 'expire_by' => 1691097057, 'reference_id' => 'TS1989', 'description' => 'For XYZ purpose', 'customer' => [ 'name' => 'Gaurav Kumar', 'email' => 'gaurav.kumar@example.com', 'contact' => '+919999999999', ], 'notify' => ['sms' => true, 'email' => true], 'reminder_enable' => true, 'notes' => ['policy_name' => 'Jeevan Bima'], 'callback_url' => 'https://example-callback-url.com/', 'callback_method' => 'get', ]); // {"id":"plink_...","short_url":"https://rzp.io/i/...","status":"created"} ``` -------------------------------- ### Create a Razorpay Order Source: https://context7.com/razorpay/razorpay-php/llms.txt Create an order server-side before initiating checkout. Amounts are in paise (100 paise = ₹1). Includes example of fetching order ID, status, and amount, and handling API errors. ```php use Razorpay\Api\Api; $api = new Api('rzp_test_XXXXXXXXXXXX', 'your_key_secret'); try { $order = $api->order->create([ 'amount' => 50000, // ₹500.00 in paise 'currency' => 'INR', 'receipt' => 'receipt#1', 'notes' => [ 'customer_name' => 'Gaurav Kumar', 'product_id' => 'SKU-1234', ], 'partial_payment' => false, ]); echo $order['id']; // "order_EKwxwAgItmmXdp" echo $order['status']; // "created" echo $order['amount']; // 50000 } catch (\\.Razorpay\\Api\\Errors\\Error $e) { echo $e->getMessage(); } ``` -------------------------------- ### Create Subscription Source: https://github.com/razorpay/razorpay-php/blob/master/documents/subscription.md This method allows you to create a new subscription for a customer. You need to provide plan details, customer notification preferences, and optional addons or offers. ```APIDOC ## POST /subscriptions ### Description Creates a new subscription for a customer. ### Method POST ### Endpoint /subscriptions ### Parameters #### Request Body - **plan_id** (string) - Required - The unique identifier for a plan that should be linked to the subscription. - **total_count** (string) - Required - The number of billing cycles for which the customer should be charged. - **customer_notify** (boolean) - Optional - Indicates whether the communication to the customer would be handled by you or us. - **quantity** (integer) - Optional - The number of times the customer should be charged the plan amount per invoice. - **start_at** (integer) - Optional - The timestamp, in Unix format, for when the subscription should start. If not passed, the subscription starts immediately after the authorization payment. - **expire_by** (integer) - Optional - The timestamp, in Unix format, till when the customer can make the authorization payment. - **addons** (array) - Optional - All parameters listed [here](https://razorpay.com/docs/api/payments/subscriptions/#create-a-subscription) are supported. - **notes** (array) - Optional - Notes you can enter for the contact for future reference. - **offer_id** (string) - Optional - The unique identifier of the offer that is linked to the subscription. ### Request Example ```php $api->subscription->create(array( "plan_id" => "plan_Jc7wDk5iZX88wx", "total_count" => 6, "quantity" => 1, "customer_notify" => true, "start_at" => 1580453311, "expire_by" => 1580626111, "addons" => array( array( "item" => array( "name" => "Delivery charges", "amount" => 30000, "currency" => "INR" ) ) ), "offer_id" => "offer_JCTD1XMlUmzF6Z", "notes" => array( "notes_key_1" => "Tea, Earl Grey, Hot", "notes_key_2" => "Tea, Earl Grey… decaf." ) )); ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the created subscription. - **entity** (string) - The type of entity, which is 'subscription'. - **plan_id** (string) - The ID of the plan associated with the subscription. - **status** (string) - The current status of the subscription (e.g., 'created'). - **current_start** (integer) - Timestamp for the start of the current billing cycle. - **current_end** (integer) - Timestamp for the end of the current billing cycle. - **ended_at** (integer) - Timestamp when the subscription ended. - **quantity** (integer) - The number of times the customer is charged per invoice. - **notes** (object) - Key-value pairs of notes associated with the subscription. - **charge_at** (integer) - Timestamp for the next charge. - **start_at** (integer) - Timestamp for when the subscription started. - **end_at** (integer) - Timestamp for when the subscription will end. - **auth_attempts** (integer) - Number of authorization attempts made. - **total_count** (integer) - The total number of billing cycles for the subscription. - **paid_count** (integer) - The number of paid billing cycles. - **customer_notify** (boolean) - Indicates if customer notifications are handled by Razorpay. - **created_at** (integer) - Timestamp when the subscription was created. - **expire_by** (integer) - Timestamp by which the customer can make the authorization payment. - **short_url** (string) - A short URL for the subscription. - **has_scheduled_changes** (boolean) - Indicates if there are scheduled changes for the subscription. - **change_scheduled_at** (integer) - Timestamp for scheduled changes. - **source** (string) - The source of the subscription creation (e.g., 'api'). - **offer_id** (string) - The ID of the offer linked to the subscription. - **remaining_count** (integer) - The number of remaining billing cycles. #### Response Example ```json { "id": "sub_00000000000001", "entity": "subscription", "plan_id": "plan_00000000000001", "status": "created", "current_start": null, "current_end": null, "ended_at": null, "quantity": 1, "notes":{ "notes_key_1":"Tea, Earl Grey, Hot", "notes_key_2":"Tea, Earl Grey… decaf." }, "charge_at": 1580453311, "start_at": 1580626111, "end_at": 1583433000, "auth_attempts": 0, "total_count": 6, "paid_count": 0, "customer_notify": true, "created_at": 1580280581, "expire_by": 1580626111, "short_url": "https://rzp.io/i/z3b1R61A9", "has_scheduled_changes": false, "change_scheduled_at": null, "source": "api", "offer_id":"offer_JHD834hjbxzhd38d", "remaining_count": 5 } ``` ``` -------------------------------- ### Using PSR-4 Class Loader Source: https://github.com/razorpay/razorpay-php/blob/master/libs/Requests-2.0.4/README.md Configure a PSR-4 compliant class loader to load the Requests library. Ensure the prefix and path are correctly set. ```php $loader = new Psr4ClassLoader(); $loader->addPrefix('WpOrg\Requests\', 'path/to/vendor/Requests/src'); $loader->register(); ``` -------------------------------- ### Instantiate with OAuth access token (platform partners) Source: https://context7.com/razorpay/razorpay-php/llms.txt Initialize the Razorpay API client using an OAuth access token for platform partners. ```APIDOC ## Instantiate with OAuth access token (platform partners) ```php use Razorpay\Api\Api; $api = new Api(null, null, 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...'); // All resource calls then act on behalf of the authenticated sub-merchant $payment = $api->payment->fetch('pay_G8VQzjPLoAvm6D'); ``` ``` -------------------------------- ### Create Subscription Link Source: https://github.com/razorpay/razorpay-php/blob/master/documents/subscription.md Creates a subscription link for a customer. This allows customers to authorize the first payment, after which recurring payments are automatically processed. ```APIDOC ## Create subscription link ### Description Creates a subscription link for a customer. This allows customers to authorize the first payment, after which recurring payments are automatically processed. ### Method POST (Implicit, as it's a creation operation via SDK) ### Endpoint Not explicitly defined, but SDK method is `$api->subscription->create()` ### Parameters #### Request Body Parameters - **plan_id** (string) - Required - The unique identifier for a plan that should be linked to the subscription. - **total_count** (string) - Required - The number of billing cycles for which the customer should be charged. - **customer_notify** (boolean) - Optional - Indicates whether the communication to the customer would be handled by you or us. - **quantity** (integer) - Optional - The number of times the customer should be charged the plan amount per invoice. - **start_at** (integer) - Optional - The timestamp, in Unix format, for when the subscription should start. If not passed, the subscription starts immediately after the authorization payment. - **expire_by** (integer) - Optional - The timestamp, in Unix format, till when the customer can make the authorization payment. - **addons** (array) - Optional - All parameters listed [here](https://razorpay.com/docs/api/payments/subscriptions/#create-a-subscription-link) are supported. - **notes** (array) - Optional - Notes you can enter for the contact for future reference. - **notify_info** (array) - Optional - All parameters listed [here](https://razorpay.com/docs/api/payments/subscriptions/#create-a-subscription-link) are supported. - **offer_id** (string) - Optional - The unique identifier of the offer that is linked to the subscription. ### Request Example ```php $api->subscription->create(array( "plan_id" => "plan_Jc7wDk5iZX88wx", "total_count" => 12, "quantity" => 1, "start_at" => 1561852800, "expire_by" => 1561939199, "customer_notify" => true, "addons" => array( array( "item" => array( "name" => "Delivery charges", "amount" => 30000, "currency" => "INR" ) ) ), "offer_id" => "offer_JCTD1XMlUmzF6Z", "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" ) )); ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the created subscription. - **entity** (string) - The type of entity, which is 'subscription'. - **plan_id** (string) - The ID of the plan associated with the subscription. - **status** (string) - The current status of the subscription (e.g., 'created'). - **current_start** (integer|null) - Timestamp of the current billing cycle start. - **current_end** (integer|null) - Timestamp of the current billing cycle end. - **ended_at** (integer|null) - Timestamp when the subscription ended. - **quantity** (integer) - The number of times the customer is charged per invoice. - **notes** (object) - Notes associated with the subscription. - **charge_at** (integer) - Timestamp for the next charge. - **start_at** (integer) - Timestamp when the subscription started. - **end_at** (integer) - Timestamp when the subscription will end. - **auth_attempts** (integer) - Number of authorization attempts made. - **total_count** (integer) - The total number of billing cycles for the subscription. - **paid_count** (integer) - The number of paid billing cycles. - **customer_notify** (boolean) - Indicates if customer notifications are enabled. - **created_at** (integer) - Timestamp when the subscription was created. - **expire_by** (integer) - Timestamp by which the authorization payment must be made. - **short_url** (string) - A short URL to the subscription payment page. - **has_scheduled_changes** (boolean) - Indicates if there are scheduled changes to the subscription. - **change_scheduled_at** (integer|null) - Timestamp for scheduled changes. - **source** (string) - The source of the subscription creation (e.g., 'api'). - **offer_id** (string|null) - The ID of the offer applied to the subscription. - **remaining_count** (integer) - The number of remaining billing cycles. #### Response Example ```json { "id":"sub_00000000000002", "entity":"subscription", "plan_id":"plan_00000000000001", "status":"created", "current_start":null, "current_end":null, "ended_at":null, "quantity":1, "notes":{ "notes_key_1":"Tea, Earl Grey, Hot", "notes_key_2":"Tea, Earl Grey… decaf." }, "charge_at":1580453311, "start_at":1580453311, "end_at":1587061800, "auth_attempts":0, "total_count":12, "paid_count":0, "customer_notify":true, "created_at":1580283117, "expire_by":1581013800, "short_url":"https://rzp.io/i/m0y0f", "has_scheduled_changes":false, "change_scheduled_at":null, "source": "api", "offer_id":"offer_JHD834hjbxzhd38d", "remaining_count":12 } ``` ``` -------------------------------- ### Create a Customer in Razorpay Source: https://context7.com/razorpay/razorpay-php/llms.txt Use this to create a new customer. Set 'fail_existing' to '0' to return an existing customer if a duplicate is found. ```php // Create a customer $customer = $api->customer->create([ 'name' => 'Gaurav Kumar', 'email' => 'gaurav.kumar@example.com', 'contact' => '9000090000', 'fail_existing' => '0', // '0' = return existing customer if duplicate 'notes' => ['notes_key_1' => 'VIP customer'], ]); // {"id":"cust_1Aa00000000004","entity":"customer","name":"Gaurav Kumar",...} ``` -------------------------------- ### Fetch and Capture Payment Source: https://context7.com/razorpay/razorpay-php/llms.txt Demonstrates how to fetch a single payment, check its status, capture an authorized payment with a specified amount and currency, and retrieve all payments with optional filters. ```APIDOC ## Fetch and Capture Payment ### Description This section covers operations related to fetching and capturing payments. You can fetch a single payment, check its status, capture an authorized payment, and retrieve a list of all payments with optional filtering. ### Fetch a single payment ```php // Fetch a single payment $payment = $api->payment->fetch('pay_G8VQzjPLoAvm6D'); echo $payment['status']; // "authorized" or "captured" ``` ### Capture an authorized payment ```php // Capture an authorized payment $captured = $api->payment->fetch('pay_G8VQzjPLoAvm6D') ->capture(['amount' => 50000, 'currency' => 'INR']); // Response: {"id":"pay_G8VQzjPLoAvm6D","status":"captured","amount":50000,...} ``` ### Fetch all payments (with optional filters) ```php // Fetch all payments (with optional filters) $payments = $api->payment->all([ 'from' => 1606900000, 'to' => 1606999999, 'count' => 10, 'expand[]' => 'card', // include card details inline ]); ``` ### Update payment notes ```php // Update payment notes $api->payment->fetch('pay_G8VQzjPLoAvm6D') ->edit(['notes' => ['key_1' => 'value1']]); ``` ### Fetch card details attached to a payment ```php // Fetch card details attached to a payment $card = $api->payment->fetch('pay_G8VQzjPLoAvm6D')->fetchCardDetails(); // {"id":"card_6krZ6bcjoeqyV9","network":"Visa","type":"debit","last4":"3335"} ``` ### Fetch payment with expanded card/emi/upi details ```php // Fetch payment with expanded card/emi/upi details $detail = $api->payment->fetch('pay_MLzFlOC98cJmHQ') ->expandedDetails(['expand[]' => 'card']); ``` ```