I need to create a PHP json object like { 12345 }
and post it through cURL, but my code:
$json = json_encode(array($CaseID), JSON_FORCE_OBJECT);
returns a string "{"0":"15876285"}"
representing an associative array.
public function RetrieveCase($CaseID) {
$json = json_encode(array($CaseID), JSON_FORCE_OBJECT);
//*** FOR DEBUG ONLY
$f = fopen('sti_error.log', 'w');
$curl = curl_init($this->signifyd_api_endpoint);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($json)));
curl_setopt($curl, CURLOPT_USERPWD, $this->signifyd_trans_key . ":");
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Return response instead of printing.
curl_setopt($curl, CURLOPT_TIMEOUT, 3);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($curl, CURLOPT_VERBOSE, 1); //** FOR DEBUG ONLY
curl_setopt($curl, CURLOPT_STDERR, $f);
curl_setopt($curl, CURLOPT_HEADER, 1); //** FOR DEBUG ONLY
curl_setopt($curl, CURLINFO_HEADER_OUT, true); //** FOR DEBUG ONLY
//** For debg only
$fp = fopen ("sti_output.log", "w") or die("Unable to open stdout for writing.
");
curl_setopt($curl, CURLOPT_FILE, $fp);
$response = curl_exec($curl);
if (!$response) {
$this->session->data['error'] = 'SIGNIFYD RetrieveCase failed: ' . curl_error($curl) . '(#' . curl_errno($curl) . ')';
curl_close($curl);
return false;
}
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
fclose($f);
//$this->load->language('payment/signifyd_transaction_investigation');
// HHTP Status Code 201 CREATED - The resource requested was successfully created.
if ($httpcode != '201') {
return $this->getCase($response);
}
$this->session->data['error'] = 'SIGNIFYD RetrieveCase failed response: ' . $response;
return false; }