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/clientes/dpaschoal/hook/masterdata_saver.php
<?php

function saveToMasterData($order, $orderId, $apiKey, $apiToken, $accountName, $currentState)
{

    if ($currentState != 'payment-approved') {
        exit;
    }

    $orderSeller = $order['sellers'][0]['name'] ?? '';

    // Blocked sellers list
    $blockedSellers = [
        'dpaschoal273itajai',
        'dpaschoal282hubcampinas',
        'dpaschoal286hubcachoeirinha',
        'dpaschoal300hubguarulhos',
        'dpaschoal303hubribeiraopreto',
        'dpaschoal304hubduquedecaxias',
        'dpaschoal308hububerlandia',
        'dpaschoal309hubsaojosedospinhais',
        'dpaschoal310hubcascavel',
        'dpaschoal311serra',
        'dpaschoal311hubserra',
        'dpaschoal314hubcarazinho',
        'dpaschoaltopservicesp',
        'dpaschoal175campinas'
    ];

    if (in_array($orderSeller, $blockedSellers)) {
        logDebug("🚫 Skipping Master Data save — Seller is blocked: $orderSeller");
        return;
    }

    $isPickup = false;
    foreach ($order['shippingData']['logisticsInfo'] as $logisticsItem) {
        if (($logisticsItem['deliveryChannel'] ?? '') === 'pickup-in-point') {
            $isPickup = true;
            break;
        }
    }

    if (!$isPickup) {
        logDebug("Order is not for pickup. Skipping Master Data save.");
        return;
    }

    $pickupInfo = $order['shippingData']['logisticsInfo'][0]['pickupStoreInfo'] ?? [];
    $pickupAddress = $pickupInfo['address'] ?? [];
    $pickupCompanyName = $pickupInfo['friendlyName'] ?? '';
    $pickupCompanyAddress = $pickupAddress ? formatAddress($pickupAddress) : '';
    $customerEmail = $order['clientProfileData']['email'] ?? '';
    $shippingEstimate = $order['shippingData']['logisticsInfo'][0]['shippingEstimate'] ?? '';

    $customerEmailDecrypted = null;

    if (!empty($order['marketingData']['utmipage'])) {
        $utmiPageData = $order['marketingData']['utmipage'];

        $jsonDecoded = json_decode($utmiPageData, true);
        if (is_array($jsonDecoded) && isset($jsonDecoded[0]['userProperties'])) {
            $encodedEmail = $jsonDecoded[0]['userProperties'];
            $customerEmailDecrypted = base64_decode($encodedEmail);
        } else {
            $customerEmailDecrypted = base64_decode($utmiPageData);
        }
    }

    $payload = [
        "orderId" => $orderId,
        "customerName" => $order['clientProfileData']['firstName'] . ' ' . $order['clientProfileData']['lastName'],
        "customerEmail" => $customerEmail,
        "customerEmailDecrypted" => $customerEmailDecrypted ?? $customerEmail,
        "isReadyForPickup" => false,
        "isTriggerFired" => false,
        "pickupCompanyName" => $pickupCompanyName,
        "pickupCompanyAddress" => $pickupCompanyAddress,
        "shippingEstimate" => $shippingEstimate,
        "orderSeller" => $orderSeller
    ];

    $saveUrl = "https://$accountName.vtexcommercestable.com.br/api/dataentities/OH/documents";
    $saveResponse = vtexPostRequest($saveUrl, $apiKey, $apiToken, $payload);
    logDebug("Master Data Payload: " . json_encode($payload));
    logDebug("Master Data Save Response: " . $saveResponse);
}