Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kuns25's avatar

Error Exception Array to String Conversion in Curl

Hi I'm trying to to Integrate Hubtel Payment Gateway but getting Array to string Conversion Error Exception .

if i do CURLOPT_POSTFIELDS =>http_build_query ($invoice), im getting blank response

please help

     $items = ["name" => "Harry Potter", "quantity" => 1, "unitPrice" => 50];
      $invoice = array("items" => $items, "totalAmount" => 1, "description" => "test", "callbackUrl" => "https://localhost:8000/status","returnUrl"=>"https://localhost:8000/return","cancellationUrl"=>"https://localhost:8000/cancel",
        "merchantBusinessLogoUrl"=>"https://localhost:8000/wallet","merchantAccountNumber"=>"HM0409180006","clientReference"=> '1');
      $curl = curl_init();

      curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.hubtel.com/v2/pos/onlinecheckout/items/initiate",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => $invoice,
        CURLOPT_HTTPHEADER => array(
          "Authorization: Basic bjJXS0o1Qjo0saMWU4NzA4ZS0wODVkLTQ0NDwUtOTQ3ZS1hZjBiODlkNzI1OWY=",
          "Content-Type: application/json",
          "Postman-Token: 2bd373c8-3669-4f5f-93e9-d3001af0a9cff",
          "cache-control: no-cache"
        ),
      ));
0 likes
3 replies
mvd's avatar

Hi @kuns25,

You need to use http_build_query.

CURLOPT_POSTFIELDS => http_build_query($invoice),

Did you not to forget to execute the api request?

curl_exec($curl)
kuns25's avatar

@MVD - @mvd yes I'm excecuting the api request ,just forgot to add in above question , if im using http_build_query i'm getting blank response

Please or to participate in this conversation.