Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/extmag/dhlshipping2/Helper/Request/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/extmag/dhlshipping2/Helper/Request/Rate.php
<?php
/**
 * Copyright © Extmag. All rights reserved.
 *
 * Rating - Package
 * Web Service Developer Guide
 * July 9, 2018
 */

namespace Extmag\DhlShipping\Helper\Request;

use Exception;

class Rate extends Dhl
{
    /**
     * @var string
     */
    protected $requestType = 'Rate';

    /**
     * @inheritDoc
     */
    public function formRequest()
    {
        $this->formHeaderRequest($this->requestType, $this->formNativeScheme());
    }

    /**
     * Form Native Scheme
     *
     * @return array[]
     * @throws Exception
     */
    public function formNativeScheme()
    {
        /* Delivery pickup date*/
        $timeStamp = $this->getTimezoneByAccount();
        if (empty($timeStamp)) {
            $timeStamp = $this->date->timestamp();
        } else {
            $timeStamp = $timeStamp->getTimestamp() + $timeStamp->getOffset();
        }

        if (implode("", $this->data['pickup_close_time']) < $this->date->date('Hi', $timeStamp)) {
            $timeStamp += 86400;
        }

        for ($i = 0; $i < 7; $i++) {
            if (empty($this->data['pickup_days_of_week'])
                || !in_array($this->date->date("w", $timeStamp), $this->data['pickup_days_of_week'])
                || ($this->data['saturday_pickup'] == 1 && $this->date->date("w", $timeStamp) == 6)
            ) {
                break;
            }

            $timeStamp += 86400;
        }

        /* END Delivery pickup date*/

        return [
            'GetQuote' => [
                'Request' => $this->formDhlSecurity(),
                'From' => $this->route === 'shipment' ? $this->getShipFromForRate() : $this->getShipToForRate(),
                'BkgDetails' => [
                    'PaymentCountryCode' => $this->data['shipper_country_code'],
                    'Date' => $this->date->date('Y-m-d', $timeStamp),
                    'ReadyTime' => 'PT'
                        . ($this->data['pickup_ready_time'][0] ?? '')
                        . 'H' . ($this->data['pickup_ready_time'][1] ?? '') . 'M',
                    'DimensionUnit' => $this->data['unit_dimension_for_shipper'],
                    'WeightUnit' => $this->data['unit_weight_for_shipper'],
                    /*'Volume' => $this->getVolumes(),*/
                    'Pieces' => $this->getPackages(),
                    'PaymentAccountNumber' => $this->data['account_shipper_number'],
                    'IsDutiable' => $this->isDutiable(),
                    'NetworkTypeCode' => 'AL',
                    'QtdShp' => $this->getSpecialServices($timeStamp),
                    'InsuredValue' => ($this->data['insurance'] == 1 ? (string)$this->getTotalPrice() : null),
                    'InsuredCurrency' => ($this->data['insurance'] == 1 ? $this->data['currency'] : null),
                ],
                'To' => $this->route === 'shipment' ? $this->getShipToForRate() : $this->getShipFromForRate(),
                'Dutiable' => $this->dutiable(),
            ],
        ];
    }

    /**
     * Get Special Services
     *
     * @param $timeStamp
     * @return array[]|null
     */
    protected function getSpecialServices($timeStamp)
    {
        $specialCodes = [];

        if (!empty($this->data['delivery_confirmation'])) {
            $specialCodes[] = ['SpecialServiceType' => $this->data['delivery_confirmation']];
        }

        /*if ($this->data['notification_active'] == 1) {
            $specialCodes[] = ['SpecialServiceType' => 'JA'];
        }*/

        if ($this->data['saturday_delivery'] == 1) {
            $specialCodes[] = ['SpecialServiceType' => 'AA'];
        }

        if ($this->data['saturday_pickup'] == 1 && $this->date->date("w", $timeStamp) == 6) {
            $specialCodes[] = ['SpecialServiceType' => 'AB'];
        }

        if ($this->dutiable() !== null && $this->isInternationalInvoice()) {
            $specialCodes[] = ['SpecialServiceType' => 'WY'];
        }

        if ($this->data['insurance'] == 1) {
            $specialCodes[] = ['SpecialServiceType' => 'II'];
        }

        if (!empty($specialCodes)) {
            return ['QtdShpExChrg' => $specialCodes];
        }

        return null;
    }

    /**
     * Dutiable
     *
     * @return array|null
     */
    protected function dutiable()
    {
        if ($this->isDutiable() == "Y") {
            return [
                'DeclaredCurrency' => $this->data['currency'],
                'DeclaredValue' => (string)$this->getTotalPrice(),
            ];
        }

        return null;
    }

    /**
     * Get Packages
     *
     * @return array|array[]|null
     */
    protected function getPackages()
    {
        $data = ['Piece' => []];
        foreach ($this->data['packages'] as $key => $package) {
            $item = [
                'PieceID' => $key + 1,
                /*'PackageTypeCode' => $package['type'],*/
            ];
            if (!empty($package['lengths']) && !empty($package['width']) && !empty($package['height'])) {
                $item['Height'] = (string)$package['height'];
                $item['Depth'] = (string)$package['lengths'];
                $item['Width'] = (string)$package['width'];
            } elseif (!empty($package['volumetric_weight'])) {
                $item['Height'] = 1;
                $item['Depth'] = 1;
                $item['Width'] = 1;
            }

            $item['Weight'] = (string)$package['weight'];
            if (!empty($package['volumetric_weight'])) {
                $volumeWeight = $this->getVolumeWeight($package['volumetric_weight']);
                if ((float)$package['weight'] < $volumeWeight) {
                    $item['Weight'] = (string)$volumeWeight;
                }
            }

            $data['Piece'][] = $item;
        }

        return !empty($data['Piece']) ? $data : null;
    }

    /**
     * Get Volumes
     *
     * @return array|array[]|null
     */
    /*protected function getVolumes()
    {
        $data = [];
        foreach ($this->data['packages'] as $package) {
            if (empty($package['lengths']) || empty($package['width']) || empty($package['height'])) {
                if (!empty($package['volumetric_weight'])) {
                    $data[] = (string)$package['volumetric_weight'];
                }
            }
        }

        return !empty($data) ? $data : null;
    }*/
}

Spamworldpro Mini