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();
}