<?php
// Define endpoint
define('API_ENDPOINT', 'https://test-merchant.hipaywallet.com/api'); // HiPay PRO production platform
$resource = API_ENDPOINT . '/user-account/website';

// Define credentials
define('API_USERNAME', 'd7127352538c3bd60985a6b0cf21ed79');
define('API_PASSWORD', '381177b7c94e8dd3ac92c1c9e2127564');
$credentials = API_USERNAME . ':' . API_PASSWORD;


// Create query parameters
$queryParameters = array(
            'name'                   	=> "ROUTE 66",
            'url'                 		=> "https://route66.store",
            'contact_email'       		=> "contact@route66.store",
            'business_line'				=> '18',
            'topic'						=> '175',
 //           'php-auth-subaccount-id'   	=> "754524",
            );

//print_r($queryParameters);
// Create a new cURL resourse
$curl = curl_init();

// Define HTTP Headers
$header = array(
     'php-auth-subaccount-id:"754524"'
);


// Create cURL options array
$options = array(
	CURLOPT_URL => $resource,
	CURLOPT_USERPWD => $credentials,
	CURLOPT_HTTPHEADER => $header,
	CURLOPT_RETURNTRANSFER =>true,
	CURLOPT_FAILONERROR => false,
	CURLOPT_HEADER =>true,
	CURLOPT_POST => true,
	CURLOPT_POSTFIELDS => http_build_query($queryParameters),
	CURLOPT_SSL_VERIFYPEER  => false,
);

foreach ($options as $option => $value) {
	curl_setopt($curl, $option, $value);
}

// Execute the given cURL session
if (false === ($result = curl_exec($curl))) {
	//throw new RuntimeException(curl_error($curl), curl_errno($curl));
	echo "<br/><strong>Error: </strong><br/>";
	var_dump(curl_error($curl), curl_errno($curl));
	exit();
}

echo "<br/><strong>Return: </strong><br/>" . $result . "<br/>";

// Clean the answer 
$status = (int)curl_getinfo($curl, CURLINFO_HTTP_CODE);
$response = json_decode($result);
var_dump($response);
if (floor($status/100) != 2) {
	//throw new RuntimeException($response->message, $response->code);
	var_dump($response->message, $response->code);
	exit();
}

// Close cURL
curl_close($curl);

?>