PHP code example of comestro / laravel-razorpay

1. Go to this page and download the library: Download comestro/laravel-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/ */

    

comestro / laravel-razorpay example snippets


use Comestro\Razorpay\Facades\Razorpay;

// Create an order for ₹500
$order = Razorpay::createOrder(500, 'receipt_1234');

// Get the Order ID to pass to your frontend frontend JS
$orderId = $order->id; 

use Illuminate\Http\Request;
use Comestro\Razorpay\Facades\Razorpay;

public function verify(Request $request)
{
    $isValid = Razorpay::verifySignature(
        $request->input('razorpay_order_id'),
        $request->input('razorpay_payment_id'),
        $request->input('razorpay_signature')
    );

    if ($isValid) {
        return "Payment successful and verified!";
    }

    return "Signature verification failed.";
}

use Comestro\Razorpay\Facades\Razorpay;

// Create a new Customer
$customer = Razorpay::customer()->create([
    'name'  => 'Gaurav Kumar',
    'email' => '[email protected]',
    'contact' => '9123456780',
]);

// Fetch a specific Payment
$payment = Razorpay::payment()->fetch('pay_29QQoUBi66xm2f');

// Refund a Payment
$refund = Razorpay::refund()->create([
    'payment_id' => 'pay_29QQoUBi66xm2f',
    'amount'     => 1000 // 1000 paise
]);

// Fetch all Orders
$orders = Razorpay::order()->all();

// Create a Subscription
$subscription = Razorpay::subscription()->create([
    'plan_id'     => 'plan_7wAosPWtrkjx6G',
    'customer_id' => 'cust_4t1YmEwb757Lw5',
    'total_count' => 6,
]);

use Comestro\Razorpay\Facades\Razorpay;

// 1. Payments
$payment = Razorpay::payment()->fetch('pay_29QQoUBi66xm2f');
$captured = Razorpay::payment()->fetch('pay_29QQoUBi66xm2f')->capture(['amount' => 50000]); // 500 INR

// 2. Orders
$order = Razorpay::order()->create([
    'receipt' => 'receipt_1', 'amount' => 50000, 'currency' => 'INR'
]);
$orders = Razorpay::order()->all();

// 3. Customers
$customer = Razorpay::customer()->create([
    'name' => 'Gaurav Kumar', 'email' => '[email protected]'
]);

// 4. Refunds
$refund = Razorpay::refund()->create([
    'payment_id' => 'pay_29QQoUBi66xm2f', 'amount' => 1000 
]);

// 5. Tokens
$tokens = Razorpay::token()->all(['customer_id' => 'cust_1234']);

// 6. Cards
$card = Razorpay::card()->fetch('card_1234');

// 7. Transfers
$transfer = Razorpay::transfer()->create([
    'account' => 'acc_1234', 'amount' => 100, 'currency' => 'INR'
]);

// 8. Virtual Accounts
$va = Razorpay::virtualAccount()->create([
    'receiver_types' => ['bank_account'], 'description' => 'First Virtual Account'
]);

// 9. Addons
$addon = Razorpay::addon()->create([
    'subscription_id' => 'sub_1234', 'item' => ['name' => 'Extra', 'amount' => 30000, 'currency' => 'INR']
]);

// 10. Plans
$plan = Razorpay::plan()->create([
    'item' => ['name' => 'Premium', 'amount' => 50000, 'currency' => 'INR'],
    'period' => 'monthly', 'interval' => 1
]);

// 11. Subscriptions
$subscription = Razorpay::subscription()->create([
    'plan_id' => 'plan_1234', 'customer_id' => 'cust_1234', 'total_count' => 6
]);

// 12. Invoices
$invoice = Razorpay::invoice()->create([
    'type' => 'invoice', 'customer_id' => 'cust_1234',
    'line_items' => [['name' => 'Masterclass', 'amount' => 10000]]
]);
$issued = Razorpay::invoice()->fetch('inv_1234')->issue();

// 13. Items
$item = Razorpay::item()->create([
    'name' => 'Book', 'amount' => 50000, 'currency' => 'INR'
]);

// 14. QR Codes
$qr = Razorpay::qrCode()->create([
    'type' => 'upi_qr', 'name' => 'Store Front', 'usage' => 'single_use', 'fixed_amount' => true,
    'payment_amount' => 30000
]);

// 15. Payment Links
$link = Razorpay::paymentLink()->create([
    'amount' => 1000, 'currency' => 'INR', 'description' => 'Payment for service'
]);

// 16. Settlements
$settlements = Razorpay::settlement()->all();

// 17. Webhooks
$webhook = Razorpay::webhook()->create([
    'url' => 'https://example.com/webhook', 'events' => ['payment.authorized'],
    'secret' => 'my_secret_key'
]);

// 18. Fund Accounts
$fundAccount = Razorpay::fundAccount()->create([
    'customer_id' => 'cust_1234', 'account_type' => 'bank_account',
    'bank_account' => ['name' => 'Gaurav Kumar', 'ifsc' => 'HDFC0000053', 'account_number' => '765432123456789']
]);

$client = Razorpay::client();
bash
php artisan vendor:publish --tag=razorpay-config