PHP code example of artpar / razorpay

1. Go to this page and download the library: Download artpar/razorpay library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

artpar / razorpay example snippets


use Razorpay\Api\Api;

$api = new Api($api_key, $api_secret);
$order = $api->order->create(array('receipt' => '123', 'amount' => 100, 'currency' => 'INR')); // Creates order
$order = $api->order->fetch($orderId); // Returns a particular order
$api->order->all($options); // Returns array of order objects
$api->payment->all($options); // Returns array of payment objects
$payment = $api->payment->fetch($id); // Returns a particular payment
$api->payment->fetch($id)->capture(array('amount'=>$amount)); // Captures a payment
$api->refund->create(array('payment_id' => $id)); // Creates refund for a payment
$api->refund->create(array('payment_id' => $id, 'amount'=>$refundAmount)); // Creates partial refund for a payment
$refund = $api->refund->fetch($refundId); // Returns a particular refund
$card = $api->card->fetch($cardId); // Returns a particular card
$customer = $api->customer->create(array('name' => 'Razorpay User', 'email' => '[email protected]')); // Creates customer
$customer = $api->customer->fetch($customerId); // Returns a particular customer
$api->customer->edit(array('name' => 'Razorpay User', 'email' => '[email protected]')); // Edits customer
$token = $api->customer->token()->fetch($tokenId); // Returns a particular token
$api->customer->token()->all($options); // Returns array of token objects
$api->customer->token()->delete($tokenId); // Deletes a token

// To get the payment details
echo $payment->amount;
echo $payment->currency;
// And so on for other attributes

// Transfers
$api->payment->fetch($paymentId)->transfer(['account' => $accountId, 'amount'=> 100, 'currency'=> 'INR]);
$transfers = $api->transfer->all();
$transfers = $api->payment->fetch($paymentId)->transfers();
$editedTransfer = $api->transfer->fetch($transferId)->edit($options);
$reversal = $api->transfer->fetch($transferId)->reverse();