1. Go to this page and download the library: Download epay-et/php-sdk 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/ */
epay-et / php-sdk example snippets
use Epay\Epay;
$epay = new Epay(['api_key' => getenv('EPAY_SECRET_KEY')]);
$session = $epay->payments->initialize([
'amount' => '250.00',
'currencyCode' => 'ETB',
'customerPhone' => '+251911234567',
'merchantReference' => 'order_123',
'returnUrl' => 'https://yourstore.com/orders/123/complete',
], idempotencyKey: 'order_123');
// Save $session['reference'], then send the customer to pay.
header('Location: ' . $session['checkoutUrl']);
use GuzzleHttp\Client as GuzzleClient;
$http = new GuzzleClient([
'proxy' => 'http://proxy.internal:8080',
'http_errors' => false, // let the SDK map statuses and retry
]);
$epay = new Epay(['api_key' => $key], $http);
$page = $epay->transactions->list();
$page->data(); // exactly this page, no extra requests
$page->hasMore(); // bool
$page->nextPage(); // the next TransactionPage, or null
$recent = $epay->transactions->list()->toArray(50); // cap the walk
foreach ($epay->transactions->list()->pages() as $page) { // page at a time
processBatch($page->data());
}
$epay->paymentProviders->list(); // compact, for dropdowns
$epay->paymentProviders->getAll(); // with category and isEnabled
$epay->paymentProviders->listEnabled(); // only what you can route to today
match ($event['event']) {
'payment.success' => fulfil($event['reference']),
'payment.failed', 'payment.cancelled' => release($event['reference']),
'payment.refunding', 'payment.refunded', 'payment.reversed' => reconcile($event),
default => null, // an event this SDK version does not know yet
};
use Epay\Epay;
final class CheckoutController
{
public function __construct(private readonly Epay $epay) {}
public function store(Request $request)
{
$session = $this->epay->payments->initialize([
'amount' => $request->string('amount')->value(),
'currencyCode' => 'ETB',
'customerPhone' => $request->string('phone')->value(),
'merchantReference' => $order->id,
], idempotencyKey: $order->id);
return redirect()->away($session['checkoutUrl']);
}
}
use Epay\Laravel\VerifyEpayWebhook;
Route::post('/webhooks/epay', function (Request $request) {
$event = VerifyEpayWebhook::event($request);
ProcessEpayEvent::dispatch($event); // acknowledge fast, process later
return response()->noContent(200);
})->middleware('epay.webhook');