@ 2017-07-12T21:20:31Z <?php
class header
{
private $secretKey = '123';
private $storeId = 10;
public function __construct($content, $url)
{
$this->setContentMd5($content);
$this->setHttpVerb($url);
}
private function setContentMd5($content)
{
$this->contentMd5 = md5($content);
}
private function setHttpVerb($url)
{
if (parse_url($url, PHP_URL_QUERY)) {
$this->httpVerb = parse_url($url, PHP_URL_PATH).'?'.parse_url($url, PHP_URL_QUERY);
} else {
$this->httpVerb = parse_url($url, PHP_URL_PATH);
}
}
private function generateAuthorization()
{
return hash_hmac(
'sha256',
$this->httpVerb . $this->contentMd5,
$this->secretKey
);
}
public function generateHeader()
{
$headers = array(
'Accept' => 'application/vnd.boacompra.com.v1+json; charset=UTF-8',
'Content-Type' => 'application/json',
'Content-MD5' => $this->contentMd5,
'Authorization' => $this->storeId . ':' . $this->generateAuthorization()
);
return $headers;
}
}
echo 'POST EXAMPLE <br /> <pre>';
$content = '{"payment-method":{"reference":"ID-CND","direct-token":"ndsfjnasdfnsdakfjndsakfjndsakfjnasdkfasdfdsf==","notify-url":"https://virtual-store.com/notifications/","test-mode":0,"payment-group":"credit_card","country":"BR","language":"en-US"},"payer":{"name":"Payer Pagador","email":"payer@uolinc.com","phone-area-code":"11","phone-number":"988881234","document":{"type":"CNPJ","number":"26974884000179"},"birth-date":"1982-12-20"}}';
$headerPost = new header($content, 'https://api.boacompra.com/payment-methods');
print_r($headerPost->generateHeader());
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.2.0 - 8.2.18 , 8.3.0 - 8.3.7 POST EXAMPLE <br /> <pre>
Deprecated: Creation of dynamic property header::$contentMd5 is deprecated in /in/eBaAN on line 15
Deprecated: Creation of dynamic property header::$httpVerb is deprecated in /in/eBaAN on line 23
Array
(
[Accept] => application/vnd.boacompra.com.v1+json; charset=UTF-8
[Content-Type] => application/json
[Content-MD5] => c44a9fcf93ac06541034e26a92f8c854
[Authorization] => 10:cf93b6649b36eb57c0443b7ea849a48c57de8799c629ce72819adb41f0f3c286
)
Output for 7.0.0 - 7.0.31 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 POST EXAMPLE <br /> <pre>Array
(
[Accept] => application/vnd.boacompra.com.v1+json; charset=UTF-8
[Content-Type] => application/json
[Content-MD5] => c44a9fcf93ac06541034e26a92f8c854
[Authorization] => 10:cf93b6649b36eb57c0443b7ea849a48c57de8799c629ce72819adb41f0f3c286
)
preferences:dark mode live preview
171.47 ms | 403 KiB | 235 Q