Coupon API – Example code

PHP

 

Coupon API – Shared function


function LiquidRequest($service, $username, $password, $salt, $data,
$sigFields) {
 $isoTimestamp = date('c');

 $sigValues = '';
 foreach ($sigFields as $sigField)
 if (isset($data[$sigField]))
 $sigValues .= $data[$sigField];

 $dataJson = json_encode($data);

 $ch = curl_init('https://api.barcodes.no/v3' . $service);
 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
 curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
 curl_setopt($ch, CURLOPT_POSTFIELDS, $dataJson);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_HTTPHEADER, array(
 'Content-Type: application/json'
 , 'Content-Length: ' . strlen($dataJson)
 , 'X-Liquid-Date: ' . $isoTimestamp
 , 'X-Liquid-Signature: ' . sha256($isoTimestamp . $sigValues .
$salt)
 ));
 // curl_setopt($ch, CURLOPT_VERBOSE, true); // ...if you
need to see what is going on
 // curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888'); // ...if you
are behind a proxy
 // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // ...if you
need to disable certificate verification
 // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

 $result = curl_exec($ch);
 curl_close($ch);
 return $result;
}

 

Coupon API – IssueRequest

 
require_once('couponapi_common.php');
// Fields are described in specification document.
$data = array(
 'TransactionId' => '12345'
 , 'ScheduleId' => '3673'
 , 'UserRef' => '4740306214'
 , 'ExpirationDate' => '2016-12-31'
 , 'ExternalRef' => array()
);
$sigFields = array('ScheduleId', 'UserRef', 'TransactionId');
$resultJson = LiquidRequest('/IssueRequest', 'username', 'password',
'salt', $data, $sigFields);
$result = json_decode($resultJson);
echo "\nYour result: " . print_r($result, true);

 

Coupon API – GetContent

To be updated.

 

 

Coupon API – GetReport

 
require_once('couponapi_common.php');
// Fields are described in specification document.
$data = array(
 'ReportName' => 'ValidationReport'
 , 'Period' => 'Day'
 , 'Date' => '2015-12-31'
);
$sigFields = array('ReportName', 'Period', 'Date');
$resultJson = LiquidRequest('/Report', 'username', 'password', 'salt',
$data, $sigFields);
$result = json_decode($resultJson);
echo "\nYour result: " . print_r($result, true);