HEX
Server: Apache
System: Linux vpshost11508.publiccloud.com.br 5.15.179-grsec-vpshost-10.lc.el8.x86_64 #1 SMP Mon Apr 7 12:04:45 -03 2025 x86_64
User: wicomm2 (10002)
PHP: 8.3.0
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: /home/storage/5/78/dd/wicomm2/public_html/blackfriday/lib/VTEX.php
<?php
require_once __DIR__.'/Utils.php';

class VTEXClient {
  private string $account;
  private string $env;
  private string $appKey;
  private string $appToken;
  private string $entity;

  public function __construct() {
    foreach (['VTEX_ACCOUNT','VTEX_APPKEY','VTEX_APPTOKEN'] as $c) {
      if (!defined($c) || constant($c) === '') {
        throw new Exception("$c não configurado em config/config.php");
      }
    }
    $this->account  = VTEX_ACCOUNT;
    $this->env      = defined('VTEX_ENVIRONMENT') ? VTEX_ENVIRONMENT : 'vtexcommercestable';
    $this->appKey   = VTEX_APPKEY;
    $this->appToken = VTEX_APPTOKEN;
    $this->entity   = defined('VTEX_DATA_ENTITY') ? VTEX_DATA_ENTITY : 'BF';
  }

  private function url(string $path): string {
    return "https://{$this->account}.{$this->env}.com.br{$path}";
  }

  public function saveBF(array $payload): array {
    $url = $this->url("/api/dataentities/{$this->entity}/documents");
    $ch = curl_init($url);
    curl_setopt_array($ch, [
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_POST => true,
      CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'X-VTEX-API-AppKey: '.$this->appKey,
        'X-VTEX-API-AppToken: '.$this->appToken
      ],
      CURLOPT_POSTFIELDS => json_encode($payload, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES),
      CURLOPT_TIMEOUT => 30
    ]);
    $res = curl_exec($ch);
    if ($res === false) throw new Exception('VTEX request failed: '.curl_error($ch));
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    $json = json_decode($res, true);
    if ($code >= 300) throw new Exception("VTEX error $code: $res");
    return $json ?: ['raw'=>$res];
  }
}