<?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-CND10","direct-token":"eyJpcCI6IjE3Mi4yMS4xMTIuMTYxIiwiZGYiOiIyZjkxMWY3ZDk4MmQ0MzA2OGEzZmI3NjFkZWVkM2YyNSJ9","notify-url":"https://virtual-store.com/notifications/","test-mode": 0,"payment-group":"credit_card","country":"BR","language":"cebolas"},"payer":{"name":"João Pagão","email":"payer@uolinc.com","phone-area-code":"11","phone-number":"988881234","document":{"type":"CPF","number":"00000000191"},"birth-date":"1982-12-20"}}';
$headerPost = new header($content, 'https://api.boacompra.com/payment-methods');
print_r($headerPost->generateHeader());
preferences:
38.69 ms | 402 KiB | 5 Q