@nickywan123 just dd the response
$response = Http::asForm()->post($url,$option);
dd($response);
//this line below throwing the error
$billCode = $response[0]['BillCode'];
dd($billCode);
and see what you have
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am trying to make an external API call to my website. I create a createBill() method that looks like below:
public function createBill(){
$option = array(
'userSecretKey'=>config('toyyibpay.key'),
'categoryCode'=>config('toyyibpay.category'),
'billName'=>'Fuiyoh Hub',
'billDescription'=>'Payment Credit',
'billPriceSetting'=>0,
'billPayorInfo'=>1,
'billAmount'=>0,
'billReturnUrl'=>route('toyyibpay-status'),
'billCallbackUrl'=>route('toyyibpay-callback'),
'billExternalReferenceNo' => 'Bill-001',
'billTo'=>'example',
'billEmail'=>'[email protected]',
'billPhone'=>'01942411',
'billSplitPayment'=>0,
'billSplitPaymentArgs'=>'',
'billPaymentChannel'=>'0',
'billContentEmail'=>'Thank you for purchasing our product!',
'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);
}
Route:
Route::get('/toyyibpay','ToyyibpayController@createBill')->name('toyyibpay-create');
When I tried to call the API using guzzle, I am shown an error:
Undefined offset: 0
Upon further debugging, this line of code is the one that gives the error:
$billCode = $response[0]['BillCode'];
Based on the API docs, I am expected to get a sample result like:
[{"BillCode":"gcbhict9"}]
How do I retrieve the BillCode response?
Please or to participate in this conversation.