File: /home/storage/5/78/dd/wicomm2/public_html_backup/clientes/fazbem/index.php
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, DELETE, PUT, PATCH, OPTIONS');
header('Access-Control-Allow-Headers: access-control-allow-headers,access-control-allow-methods,access-control-allow-origin,content-type');
header('Content-Type: application/json');
header("Access-Control-Allow-Credentials: true");
ini_set('display_errors', 1);
set_time_limit(0);//evitar Fatal error: Maximum execution time of 30 seconds exceeded
function GET($url){
/**
* headers do curl
*/
$headers = array(
'accept: application/vnd.vtex.ds.v10+json',
"content-type: application/json",
"rest-range: resources=0-900",
"x-vtex-api-appkey: vtexappkey-epharma-ILSXBP",
"x-vtex-api-apptoken: PCNSMPCWSWGGMALLYQYRBEEHMBHVVHTMEAYVFKFYAVGPXPNYACIQJLKEUWJYTANTFBYHUTKZQAWGVNAYJYYICLQEPGDPOOEJWRYDWIIECLRRHHKOOSUCPPETAUONODVH"
);
/**
* iniciando a sessao
*/
$cSession = curl_init();
/**
* aplicando as variaveis
*/
curl_setopt($cSession, CURLOPT_URL, $url);
curl_setopt($cSession, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($cSession, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cSession, CURLOPT_HTTPHEADER, $headers);
/**
* executando curl
*/
$result = curl_exec($cSession);
$result = json_decode($result, true);
/**
* fechando a conexao curl
*/
curl_close($cSession);
/**
* retorno da funcao com var_dump
*/
return $result;
}
function UPDATE($url, $data){
$headers = array(
'accept: application/vnd.vtex.ds.v10+json',
"content-type: application/json",
"rest-range: resources=0-900",
"x-vtex-api-appkey: vtexappkey-epharma-ILSXBP",
"x-vtex-api-apptoken: PCNSMPCWSWGGMALLYQYRBEEHMBHVVHTMEAYVFKFYAVGPXPNYACIQJLKEUWJYTANTFBYHUTKZQAWGVNAYJYYICLQEPGDPOOEJWRYDWIIECLRRHHKOOSUCPPETAUONODVH"
);
/**
* iniciando a sessao
*/
$cSession = curl_init();
/**
* aplicando as variaveis
*/
curl_setopt($cSession, CURLOPT_URL, $url);
curl_setopt($cSession, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($cSession, CURLOPT_POSTFIELDS, $data );
curl_setopt($cSession, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cSession, CURLOPT_HTTPHEADER, $headers);
/**
* executando curl
*/
$result = curl_exec($cSession);
$result = json_decode($result, true);
/**
* fechando a conexao curl
*/
curl_close($cSession);
/**
* retorno da funcao com var_dump
*/
return $result;
}
function POST($url, $data){
$headers = array(
'accept: application/vnd.vtex.ds.v10+json',
"content-type: application/json",
"rest-range: resources=0-900",
"x-vtex-api-appkey: vtexappkey-epharma-ILSXBP",
"x-vtex-api-apptoken: PCNSMPCWSWGGMALLYQYRBEEHMBHVVHTMEAYVFKFYAVGPXPNYACIQJLKEUWJYTANTFBYHUTKZQAWGVNAYJYYICLQEPGDPOOEJWRYDWIIECLRRHHKOOSUCPPETAUONODVH"
);
/**
* iniciando a sessao
*/
$cSession = curl_init();
/**
* aplicando as variaveis
*/
curl_setopt($cSession, CURLOPT_URL, $url);
curl_setopt($cSession, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($cSession, CURLOPT_POSTFIELDS, $data );
curl_setopt($cSession, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cSession, CURLOPT_HTTPHEADER, $headers);
/**
* executando curl
*/
$result = curl_exec($cSession);
$result = json_decode($result, true);
/**
* fechando a conexao curl
*/
curl_close($cSession);
/**
* retorno da funcao com var_dump
*/
return $result;
}
function getAuth(){
$url = "https://fazbem.vtexcommercestable.com.br/api/dataentities/CA/search?send=false&_fields=_all";
$result = GET($url);
foreach ($result as $items) {
$send = $items["send"];
$storeCnpj = $items["storeCnpj"];
$authorizationId = $items["authorizationId"];
var_dump('$result itens:', $result);
if($send === false) {
cancelAuth($authorizationId, $send, $storeCnpj);
}
}
}
function cancelAuth($authorizationId, $send, $storeCnpj){
var_dump('$authorizationId, $send, $storeCnpj:', $authorizationId, $send, $storeCnpj);
$url = "https://apimarketplace.epharma.com.br/epharma/Authorization/Cancel";
$data = array("storeSequenceId" => 1, "storeCnpj" => $storeCnpj, "authorizationId" => $authorizationId);
$result = POST($url, json_encode($data));
var_dump('$cancelAuth itens:', $result);
if ($result != NULL) {
updateAuth($authorizationId, $send, $storeCnpj);
}
}
function updateAuth($authorizationId, $send, $storeCnpj){
$url = "https://fazbem.vtexcommercestable.com.br/api/dataentities/CA/documents?authorizationId=$authorizationIdItem";
$data = array("send" => true, "storeCnpj" => $storeCnpj, "authorizationId" => $authorizationId);
$result = PATCH($url, json_encode($data));
if ($result != NULL) {
var_dump("Documento '$authorizationId' atualizado com sucesso.");
}
}
getAuth();
?>