1. Go to this page and download the library: Download thejano/fib-payment-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/ */
use TheJano\FibPayment\Facades\FibPayment;
$status = FibPayment::status('payment-uuid');
use TheJano\FibPayment\Facades\FibPayment;
$result = FibPayment::cancel('payment-uuid');
// Returns [] on success
use TheJano\FibPayment\Facades\FibPayment;
$result = FibPayment::refund('payment-uuid');
// Returns [] on success
use TheJano\FibPayment\Facades\FibPayment;
$token = FibPayment::getToken();
// Returns the raw OAuth2 access token string
// routes/web.php (exclude from CSRF protection — it is a server-to-server POST)
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\FibCallbackController;
Route::post('/fib/callback', FibCallbackController::class);
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use TheJano\FibPayment\Facades\FibPayment;
use TheJano\FibPayment\Exceptions\FibPaymentException;
class FibCallbackController extends Controller
{
public function __invoke(Request $request)
{
$paymentId = $request->input('id');
try {
// Re-verify against FIB instead of trusting the callback body.
$payment = FibPayment::status($paymentId);
} catch (FibPaymentException $e) {
report($e);
return response()->noContent(500);
}
if (($payment['status'] ?? null) === 'PAID') {
// Fulfil the order, mark it paid, etc.
}
return response()->noContent();
}
}
use TheJano\FibPayment\Services\PaymentService;
class CheckoutService
{
public function __construct(private PaymentService $payments) {}
public function startPayment(int $amount, string $description): array
{
return $this->payments->create($amount, $description);
}
}
use TheJano\FibPayment\Facades\FibPayment;
use TheJano\FibPayment\Exceptions\FibPaymentException;
try {
$payment = FibPayment::create(1000, 'Order #5');
} catch (FibPaymentException $e) {
$httpStatus = $e->getStatusCode(); // int, e.g. 400 or 422
$body = $e->getResponseBody(); // mixed — the decoded JSON response body
$message = $e->getMessage(); // string — 'FIB payment request failed.'
// Log or handle accordingly
\Log::error('FIB payment failed', [
'status' => $httpStatus,
'body' => $body,
]);
}