PHP code example of usimpay / usimpay-laravel
1. Go to this page and download the library: Download usimpay/usimpay-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/ */
usimpay / usimpay-laravel example snippets
use USIMPay\Laravel\USIMPayClient;
$response = app(USIMPayClient::class)->initializePayment([
'customer_name' => 'Customer Name',
'customer_email' => '[email protected] ',
'customer_phone' => '+60123456789',
'payment_ref' => 'INV-2026-00001',
'amount' => 150.00,
'payment_description' => 'Invoice Payment',
'direct_url' => route('payments.redirect', ['payment' => $payment->id]),
'callback_url' => route('payments.callback'),
]);
if ($response->success) {
$payment->update([
'gateway_bill_id' => $response->billId,
]);
return redirect()->away($response->paymentUrl);
}
return back()->withErrors([
'payment' => $response->message,
]);
use USIMPay;
$response = USIMPay::createPayment($payload);
use USIMPay;
$status = USIMPay::verifyPaymentStatus($billId);
if (! $status->success) {
abort(400, $status->message ?? 'Payment verification failed');
}
if ($status->isPaid()) {
$payment->markAsPaid($status->toArray());
}
$paymentInfo = USIMPay::getPaymentInfo($billId);
if ($paymentInfo->success) {
$amount = $paymentInfo->amount;
$paymentRef = $paymentInfo->paymentRef;
$fpxTxnId = $paymentInfo->fpxTxnId;
}
$checksum = USIMPay::generateChecksum([
'customer_name' => 'Customer Name',
'customer_email' => '[email protected] ',
'payment_ref' => 'INV-2026-00001',
'amount' => 150.00,
'payment_description' => 'Invoice Payment',
]);
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use USIMPay;
public function callback(Request $request): JsonResponse
{
$billId = $request->input('bill_id');
$paymentRef = $request->input('payment_ref');
$verified = USIMPay::verifyPaymentStatus($billId);
if (! $verified->success) {
return response()->json(['message' => 'Payment verification failed'], 400);
}
$payment = Payment::where('payment_ref', $paymentRef)->firstOrFail();
if ($verified->isPaid()) {
$payment->markAsPaid($verified->toArray());
} else {
$payment->markAsFailed($verified->toArray());
}
return response()->json(['status' => 'success']);
}
USIMPay::verifyCallbackSignature($request->getContent(), $request->header('X-UsimPay-Signature'));
bash
php artisan vendor:publish --tag=usimpay-config