Issue
I have this function where I enroll a token to make a transaction process without the need to key-in of credentials.
Some blogs stated that curl exec does the job in executing the curl, but nothing is happening with this function. can I somehow trigger this CURL using submit button in form? also, how can I know the errors of CURL?
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'url here',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"clientIp": $_clientip,
"ipAddress": $_ipaddress,
"merchantId": $_mid,
"notificationUrl": $_noturl,
"requestId": $_requestid,
"responseUrl": $_resurl,
"signature": "1f4856d7868b1c352e015211e79df194d6fa1babc624084dd00027bf89538184d75f19991d008c1d99d2b5a28c2eea7f928e304611562eb838216e3664eac628",
"trxType": "createtoken",
"verify": "Y",
"address1": $_addr1,
"address2": $_addr2,
"city": $_city,
"country": $_country,
"email": $_email,
"fName": $_fname,
"lName": $_lname,
"mName": $_mname,
"mobile": $_mobile,
"phone": $_phone,
"state": $_state,
"postal": ""
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Idempotency-Key: HMCENRO202001140009T',
'Authorization: Basic Og=='
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Solution
you can try it via defining the body as structured representation and then transform it to JSON:
$recipient['dst'] = "+000000";
$message['recipients'] = array($recipient);
$message['text'] = "this is a test message";
$job['messages'] = array($message);
$json = json_encode($job);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'url here',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $json,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Idempotency-Key: HMCENRO202001140009T',
'Authorization: Basic Og=='
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Answered By - michael kaltenecker