![]() 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/ |
<?php /** * Copyright © Extmag. All rights reserved. */ namespace Extmag\DhlShipping\Helper\Request; use Exception; use Extmag\Shiplab\Helper\Request; use Extmag\Shiplab\Model\LogsFactory; class Dhl extends Request { /** * @var string */ protected $carrier = 'dhl'; /** * FormDhlSecurity * * @param $isCache * @return array * @throws Exception */ public function formDhlSecurity($isCache = true) { $account = null; if (!$isCache) { try { $account = $this->shipperAccountRepository->getById($this->data['account_id']); } catch (Exception $e) { $account = null; } } return [ 'ServiceHeader' => [ 'MessageTime' => $this->timezone->date($this->getTimezoneByAccount())->format('Y-m-d\TH:i:sP'), 'MessageReference' => hash("haval128,3", $this->data['context']), 'SiteID' => $account ? $account->getUserId() : $this->data['account_user_id'], 'Password' => $account ? $account->getPassword() : $this->data['account_password'], ], 'MetaData' => [ 'SoftwareName' => 'ExtmagShiplab', 'SoftwareVersion' => '1.0', ], ]; } /** * Form Dhl Security Without Meta * * @param $isCache * @return array[] * @throws Exception */ public function formDhlSecurityWithoutMeta($isCache = true) { $account = null; if (!$isCache) { try { $account = $this->shipperAccountRepository->getById($this->data['account_id']); } catch (Exception $e) { $account = null; } } return [ 'ServiceHeader' => [ 'MessageTime' => $this->timezone->date($this->getTimezoneByAccount())->format('Y-m-d\TH:i:sP'), 'MessageReference' => hash("haval128,3", $this->data['context']), 'SiteID' => $account ? $account->getUserId() : $this->data['account_user_id'], 'Password' => $account ? $account->getPassword() : $this->data['account_password'], ], ]; } /** * Get COD * * @return array|string[] */ protected function getCOD() { $data = []; if ($this->data['cod'] == 1) { $data = [ 'SpecialServiceType' => 'KB', ]; } return $data; } /** * Get Shipper For Rate * * @param $type * @return array */ protected function getShipperForRate($type = 'shipper_') { return [ 'CountryCode' => $this->data[$type . 'country_code'], 'Postalcode' => $this->data[$type . 'postal_code'], 'City' => $this->data[$type . 'city'], ]; } /** * Get Shipper * * @param $type * @return array */ protected function getShipper($type = 'shipper_') { $regionName = $this->getRegionName( $this->data[$type . 'country_code'], $this->data[$type . 'state_code'] ); $registrationNumbers = null; if (!empty($this->data['ship_from_tax_number'])) { $registrationNumbers['RegistrationNumber'][] = [ 'Number' => $this->data['ship_from_tax_number'], 'NumberTypeCode' => 'VAT', 'NumberIssuerCountryCode' => $this->data[$type . 'country_code'], ]; } if (!empty($this->data['ship_from_eori_number'])) { $registrationNumbers['RegistrationNumber'][] = [ 'Number' => $this->data['ship_from_eori_number'], 'NumberTypeCode' => 'EOR', 'NumberIssuerCountryCode' => $this->data[$type . 'country_code'], ]; } return [ 'ShipperID' => $this->data['account_shipper_number'], 'CompanyName' => $this->data[$type . 'company_name'], 'SuiteDepartmentName' => null, 'RegisteredAccount' => null, 'AddressLine1' => $this->data[$type . 'street_1'] ?? null, 'AddressLine2' => $this->data[$type . 'street_2'] ?: null, 'AddressLine3' => $this->data[$type . 'street_3'] ?: null, 'City' => $this->data[$type . 'city'], 'Division' => $regionName, 'DivisionCode' => ($regionName !== null ? ($this->data[$type . 'state_code'] ?? null) : null), 'PostalCode' => $this->data[$type . 'postal_code'], 'CountryCode' => $this->data[$type . 'country_code'], 'CountryName' => $this->getCountryName($this->data[$type . 'country_code']), 'Contact' => [ 'PersonName' => $this->data[$type . 'name'], 'PhoneNumber' => $this->data[$type . 'phone'], 'PhoneExtension' => null, 'FaxNumber' => null, 'Telex' => null, 'Email' => null, 'MobilePhoneNumber' => null, ], 'Suburb' => null, 'RegistrationNumbers' => $registrationNumbers, ]; } /** * Get Ship To For Rate * * @return array */ protected function getShipToForRate() { $type = 'ship_to_'; return [ 'CountryCode' => $this->data[$type . 'country_code'], 'Postalcode' => $this->data[$type . 'postal_code'], 'City' => $this->data[$type . 'city'], ]; } /** * Get Ship To * * @return array */ protected function getShipTo() { $type = 'ship_to_'; $regionName = $this->getRegionName( $this->data[$type . 'country_code'], $this->data[$type . 'state_code'] ); $registrationNumbers = null; if (!empty($this->data[$type . 'tax_number'])) { $registrationNumbers['RegistrationNumber'][] = [ 'Number' => $this->data[$type . 'tax_number'], 'NumberTypeCode' => 'VAT', 'NumberIssuerCountryCode' => $this->data[$type . 'country_code'], ]; } return [ 'CompanyName' => $this->data[$type . 'company_name'], 'AddressLine1' => $this->data[$type . 'street_1'], 'AddressLine2' => $this->data[$type . 'street_2'] ?? null, 'AddressLine3' => $this->data[$type . 'street_3'] ?? null, 'City' => $this->data[$type . 'city'], 'Division' => $regionName, 'DivisionCode' => ($regionName !== null ? ($this->data[$type . 'state_code'] ?? null) : null), 'PostalCode' => $this->data[$type . 'postal_code'], 'CountryCode' => $this->data[$type . 'country_code'], 'CountryName' => $this->getCountryName($this->data[$type . 'country_code']), 'Contact' => [ 'PersonName' => $this->data[$type . 'name'], 'PhoneNumber' => $this->data[$type . 'phone'], 'Email' => $this->data[$type . 'email'] ?? null, ], 'RegistrationNumbers' => $registrationNumbers, ]; } /** * Get Place To * * @return array */ protected function getPlaceTo() { $type = 'ship_to_'; $regionName = $this->getRegionName($this->data[$type . 'country_code'], $this->data[$type . 'state_code']); return [ 'ResidenceOrBusiness' => ($this->data[$type . 'destination_type'] == 'residential' ? 'R' : null), 'CompanyName' => $this->data[$type . 'company_name'], 'AddressLine1' => $this->data[$type . 'street_1'], 'AddressLine2' => $this->data[$type . 'street_2'] ?? null, 'AddressLine3' => $this->data[$type . 'street_3'] ?? null, 'City' => $this->data[$type . 'city'], 'CountryCode' => $this->data[$type . 'country_code'], 'DivisionCode' => ($regionName !== null ? ($this->data[$type . 'state_code'] ?? null) : null), 'Division' => $regionName, 'PostalCode' => $this->data[$type . 'postal_code'], 'PackageLocation' => null, 'Suburb' => null, ]; } /** * Get Ship From For Rate * * @return array */ protected function getShipFromForRate() { $type = 'ship_from_'; return [ 'CountryCode' => $this->data[$type . 'country_code'], 'Postalcode' => $this->data[$type . 'postal_code'], 'City' => $this->data[$type . 'city'], ]; } /** * Get Ship From * * @return array */ protected function getShipFrom() { $type = 'ship_from_'; $regionName = $this->getRegionName($this->data[$type . 'country_code'], $this->data[$type . 'state_code']); return [ 'CompanyName' => $this->data[$type . 'company_name'], 'AddressLine1' => $this->data[$type . 'street_1'], 'AddressLine2' => $this->data[$type . 'street_2'] ?? null, 'AddressLine3' => $this->data[$type . 'street_3'] ?? null, 'City' => $this->data[$type . 'city'], 'Division' => $regionName, 'DivisionCode' => ($regionName !== null ? ($this->data[$type . 'state_code'] ?? null) : null), 'PostalCode' => $this->data[$type . 'postal_code'], 'CountryCode' => $this->data[$type . 'country_code'], 'CountryName' => $this->getCountryName($this->data[$type . 'country_code']), 'Contact' => [ 'PersonName' => $this->data[$type . 'name'], 'PhoneNumber' => $this->data[$type . 'phone'], 'Email' => $this->data[$type . 'email'] ?? null, ], ]; } /** * Get Place From * * @return array */ protected function getPlaceFrom() { $type = 'ship_from_'; $regionName = $this->getRegionName($this->data[$type . 'country_code'], $this->data[$type . 'state_code']); return [ 'ResidenceOrBusiness' => ($this->data[$type . 'destination_type'] == 'residential' ? 'R' : null), 'CompanyName' => $this->data[$type . 'company_name'], 'AddressLine1' => $this->data[$type . 'street_1'], 'AddressLine2' => $this->data[$type . 'street_2'] ?? null, 'AddressLine3' => $this->data[$type . 'street_3'] ?? null, 'City' => $this->data[$type . 'city'], 'CountryCode' => $this->data[$type . 'country_code'], 'DivisionCode' => ($regionName !== null ? ($this->data[$type . 'state_code'] ?? null) : null), 'Division' => $regionName, 'PostalCode' => $this->data[$type . 'postal_code'], 'PackageLocation' => null, 'SuburbName' => null, ]; } /** * Get Region Name * * @param $countryCode * @param $regionCode * @return mixed|null */ protected function getRegionName($countryCode, $regionCode) { $proviceCodes = $this->provinceCodes->toArray(); return $proviceCodes[$countryCode][$regionCode]['name'] ?? null; } /** * Get Country Name * * @param $countryCode * @return null */ protected function getCountryName($countryCode) { return empty($countryCode) ? null : $this->countryFactory->create()->loadByCode($countryCode)->getName(); } /** * Is International Invoice * * @return bool */ protected function isInternationalInvoice() { return $this->data['ship_to_country_code'] != $this->data['ship_from_country_code'] && $this->data['invoice_active'] == 1 && $this->route == 'shipment'; } /** * Is Dutiable * * @return string */ protected function isDutiable() { if ($this->isInternational() && (!$this->manager->isCountryInEU($this->data['ship_from_country_code']) || !$this->manager->isCountryInEU($this->data['ship_to_country_code']) ) && $this->data['is_dutiable'] == 1 && $this->route == 'shipment' ) { return 'Y'; } return 'N'; } }