PHP code example of efati / payment-gateway

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

    

efati / payment-gateway example snippets


use App\Payment\Managers\PaymentManager; // Or use Facade
use PaymentGateway\Facades\Payment;
use App\Payment\DTOs\PaymentRequestDTO;

$dto = new PaymentRequestDTO(
    amount: 10000,
    orderId: 'ORD-123',
    callbackUrl: route('payment.callback'),
    description: 'Order payment',
    mobile: '09123456789'
);

$result = Payment::initialize($dto);

// Use Zarinpal
Payment::zarinpal()->initialize($dto);

use PaymentGateway\Facades\Payment;
use PaymentGateway\DTOs\PaymentVerifyDTO;

$dto = new PaymentVerifyDTO(
    amount: 10000,
    authority: request('Authority'), // or whatever the gateway sends
    gateway: 'zarinpal'
);

try {
    $receipt = Payment::verify($dto);
    // $receipt['ref_id'], $receipt['tracking_code']

    return "Payment Successful! Ref ID: " . $receipt['ref_id'];
} catch (\PaymentGateway\Exceptions\PaymentException $e) {
    return "Payment Failed: " . $e->getMessage();
}

// config/payment.php
'models' => [
    'bank' => \App\Models\Bank::class,
    'gateway' => \App\Models\PaymentGateway::class,
    'transaction' => \App\Models\PaymentTransaction::class,
],
bash
php artisan payment:install
bash
php artisan migrate
bash
php artisan db:seed --class=PaymentGateway\Database\Seeders\BankSeeder
php artisan db:seed --class=PaymentGateway\Database\Seeders\GatewaySeeder
bash
php artisan vendor:publish --tag=efati-payment-models