Is your callback route publicly accessable? If it's on localhost, toyyibpay API will not reach it. If that's the case you could use https://ngrok.com/ to create tunnel for testing
Jul 13, 2021
3
Level 6
api callback unable to log response
I implemented an external API that allows payment to my application.
In my controller:
public function createBill(){
//$user = User::find(auth()->id());
$option = array(
'userSecretKey'=>config('toyyibpay.key'),
'categoryCode'=>config('toyyibpay.category'),
'billName'=>'FUIYOH HUB',
'billDescription'=>'Top Up Credit',
'billPriceSetting'=>0,
'billPayorInfo'=>0,
'billAmount'=>0,
'billReturnUrl'=>route('toyyibpay-status'),
'billCallbackUrl'=>route('toyyibpay-callback'),
'billExternalReferenceNo' => '',
'billTo'=>'',
'billEmail'=>'',
'billPhone'=>'',
'billSplitPayment'=>0,
'billSplitPaymentArgs'=>'',
'billPaymentChannel'=>0,
'billContentEmail'=>'Thank you for using our platform!',
'billChargeToCustomer'=>2
);
$url = 'https://dev.toyyibpay.com/index.php/api/createBill';
$response = Http::asForm()->post($url,$option);
//this line below throwing the error
$billCode = $response[0]['BillCode'];
//dd($billCode);
return redirect('https://dev.toyyibpay.com/'.$billCode);
}
public function paymentStatus(){
//if success save payment record to db
$response = request()->all();
Log::info($response);
return $response;
}
public function callback(){
$response = request()->all();
Log::info($response);
}
Route:
Route::get('/toyyibpay','ToyyibpayController@createBill')->name('toyyibpay-create');
Route::get('/toyyibpay-status','ToyyibpayController@paymentStatus')->name('toyyibpay-status');
Route::post('/toyyibpay-callback','ToyyibpayController@callback')->name('toyyibpay-callback');
I omitted the CSRF for the post request in VerifyCsrfToken.php:
protected $except = [
'toyyibpay-callback'
];
I want to log the response from the callback to make sure it is working. After a successful transaction, my log file shows:
[2021-07-13 08:57:55] local.INFO: array (
'status_id' => '1',
'billcode' => 'h5bz62x1',
'order_id' => NULL,
'msg' => 'ok',
'transaction_id' => 'TP70269027515316130721',
)
1 meaning transaction is successful but it only logs the response from paymentStatus() and not in the callback function. Why is it not working?
Please or to participate in this conversation.