PHP code example of saeidgi / blupay
1. Go to this page and download the library: Download saeidgi/blupay 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/ */
saeidgi / blupay example snippets
use BluPay;
$tokenResp = BluPay::driver()->requestToken(
amount: 12000,
resNum: 'ORDER-123',
redirectUrl: route('pay.callback'),
cellNumber: '09120000000'
);
if (!$tokenResp->success) {
return response()->json([
'errorCode' => $tokenResp->errorCode,
'errorDesc' => $tokenResp->errorDesc,
], 422);
}
$token = $tokenResp->token;
return redirect()->away(
BluPay::driver()->redirectUrl($token)
);
use BluPay;
use Illuminate\Http\Request;
Route::post('/pay/callback', function (Request $request) {
$refNum = $request->input('RefNum');
$verify = BluPay::driver()->verify($refNum);
if ($verify->success !== true) {
return response()->json([
'ok' => false,
'resultCode' => $verify->resultCode,
'resultDescription' => $verify->resultDescription,
], 400);
}
// IMPORTANT: Compare verified amount with your expected amount before fulfilling the order.
return response()->json([
'ok' => true,
'transactionDetail' => $verify->transactionDetail,
]);
})->name('pay.callback');
$reverse = BluPay::driver()->reverse($refNum);
if (!$reverse->success) {
// handle failed reverse
}
$tokenResp->ipgUrlFromHeader;