IPP Europe

PHP Code Example: Curl request to update the Company Descriptor

You are here:

Updating and personalizing the ‘Company Descriptor’ field is an efficient way to provide better customer service, reduce transaction disputes, and subtly increase brand visibility, though its utility is limited to transactions processed by VISA and MasterCard.

However, it’s important to note that the relevance of the ‘Company Descriptor’ field is specific to certain types of transactions. Presently, it’s only applicable for transactions processed through VISA and MasterCard.

The below PHP script makes use of cURL, to update the Company Descriptor.

Code Example for changing Company Descriptor

				
					<?php

$data = array(
    'user_id' => 'User ID',
    'session_id' => 'Session ID',
    'processing' => array('descriptor' => 'New Descriptor'),
);

//Encode the array into JSON.
$data_json = json_encode($data);

//API URL
$url = 'https://api.ippeurope.com/company/data/update';

//Initiate cURL.
$ch = curl_init($url);

//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);

//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);

//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 

//Execute the request
$result = curl_exec($ch);

if(!$result){
    die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
}

//Close the cURL handle.
curl_close($ch);

//Do something with the result.
echo $result;
?>

				
			

Note that you’ll need to replace ‘User ID’ and ‘Session ID’ with your actual user_id and session_id.

This code sends a JSON object to the specified URL. The server receiving this request should be expecting an application/json content-type.

The cURL session is initialized with curl_init(), passing the URL to which the POST request will be made as the argument.

curl_setopt() is then used to set various options for the cURL transfer:

  • CURLOPT_POST is set to 1, indicating that a POST request will be made.
  • CURLOPT_POSTFIELDS is set to the JSON string we created, which contains the data to be sent in the request.
  • CURLOPT_HTTPHEADER is set to an array containing 'Content-Type: application/json', specifying that the content of the request is JSON.

curl_exec() is then called to execute the configured cURL session. It returns false if the request fails, so if this happens, an error message is displayed and the script dies using die().

After the request is completed, curl_close() is used to close the cURL session, and the result of the feedback of the request is output with echo.