1. Go to this page and download the library: Download codetay/bankapi-laravel 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/ */
codetay / bankapi-laravel example snippets
use BankApi\Laravel\Facades\BankApi;
$page = BankApi::banking()->transactions(limit: 50);
foreach ($page->autoPaging() as $transaction) {
// ...
}
$created = BankApi::webhookEndpoints()->create(
url: 'https://myapp.test/hooks/bankapi',
eventTypes: ['bank.credit'],
);
// $created->secret (whsec_...) is shown ONLY here — store it now.
use BankApi\Webhook\Event;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
Route::post('/webhooks/bankapi', function (Request $request) {
/** @var Event $event */
$event = $request->attributes->get('bankapi_event');
// handled asynchronously via the BankApiWebhookReceived listener below;
// just acknowledge quickly here.
return response()->noContent();
})->middleware('bankapi.webhook');
namespace App\Listeners;
use BankApi\Laravel\Events\BankApiWebhookReceived;
use BankApi\Webhook\EventType;
use Illuminate\Contracts\Queue\ShouldQueue;
final class HandleBankApiWebhook implements ShouldQueue
{
public function handle(BankApiWebhookReceived $listenerEvent): void
{
$event = $listenerEvent->event; // BankApi\Webhook\Event
if (WebhookDelivery::query()->where('webhook_id', $event->webhookId)->exists()) {
return; // already processed
}
// An event type newer than this SDK still arrives here — isKnown()
// is false for it instead of the call throwing, so skip it below.
match (true) {
$event->type === EventType::BANK_CREDIT => ProcessCredit::dispatch($event->data),
default => null,
};
WebhookDelivery::create(['webhook_id' => $event->webhookId]);
}
}