PHP code example of sdpayhub / laravel-payzy

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

    

sdpayhub / laravel-payzy example snippets


use Sdpayhub\Payzy\Facades\Payzy;

$response = Payzy::gateway('razorpay')
    ->amount(1000)          // amount in paise (₹10.00)
    ->currency('INR')
    ->orderId('ORDER-1001')
    ->create();

use Sdpayhub\Payzy\Facades\Payzy;

$response = Payzy::gateway('razorpay')
    ->amount(1000)
    ->currency('INR')
    ->orderId('ORDER-1001')
    ->create();

if ($response->isSuccess()) {
    // Save this ID in your database
    $transactionId = $response->getGatewayTransactionId();
}

if ($response->isRedirect()) {
    // Send the customer to the payment page
    return redirect()->away($response->getRedirectUrl());
}

// Something went wrong
return back()->with('error', $response->getMessage());

Payzy::gateway('stripe')->amount(1000)->currency('USD')->orderId('ORDER-1')->create();
Payzy::gateway('paypal')->amount(1000)->currency('USD')->orderId('ORDER-1')->create();
Payzy::gateway('paytm')->amount(1000)->currency('INR')->orderId('ORDER-1')->create();
Payzy::gateway('phonepe')->amount(1000)->currency('INR')->orderId('ORDER-1')->create();
Payzy::using('authorizenet')->charge([
    'amount' => 1000,
    'currency' => 'USD',
    'order_id' => 'ORDER-1',
    'opaque_data' => [
        'dataDescriptor' => 'COMMON.ACCEPT.INAPP.PAYMENT',
        'dataValue' => $acceptJsNonce,
    ],
]);

$pay = Payzy::using('razorpay');

// Check status
$status = $pay->status('pay_xxxxx');

// Full refund
$refund = $pay->refund('pay_xxxxx');

// Partial refund (amount in paise/cents)
$partial = $pay->partialRefund([
    'payment_id' => 'pay_xxxxx',
    'amount' => 250,
]);

// Capture (when payment was authorized first)
$capture = $pay->capture([
    'payment_id' => 'pay_xxxxx',
    'amount' => 1000,
]);

$response->isSuccess();               // true / false
$response->getGatewayTransactionId(); // gateway payment / order id
$response->getMessage();              // human-readable message
$response->getData();                 // useful fields as array
$response->isRedirect();              // needs browser redirect?
$response->getRedirectUrl();          // URL to send the user to

Payzy::gateway('razorpay')
    ->amount(1000)
    ->currency('INR')
    ->orderId('ORDER-1001')
    ->idempotencyKey('checkout-ORDER-1001')
    ->create();

use Sdpayhub\Payzy\Events\PaymentSuccess;

// In a listener:
public function handle(PaymentSuccess $event): void
{
    $gateway = $event->gateway;
    $txnId = $event->response->getGatewayTransactionId();

    // Mark the order as paid in your app
}

use Sdpayhub\Payzy\Exceptions\PayzyException;
use Sdpayhub\Payzy\Facades\Payzy;

try {
    $response = Payzy::using('razorpay')->charge([
        'amount' => 1000,
        'currency' => 'INR',
        'order_id' => 'ORDER-1001',
    ]);
} catch (PayzyException $e) {
    // Safe to log — secrets are not in the message by design
    report($e);

    return back()->with('error', 'Payment could not be started.');
}
bash
php artisan vendor:publish --tag=payzy-config
bash
php artisan queue:work