From 3e337b6fb1bb81f92e30dc928d6072c74d8eccf9 Mon Sep 17 00:00:00 2001 From: Nirav Patel Date: Fri, 4 Nov 2022 15:14:15 +0530 Subject: [PATCH 1/2] Release 2.4.1 - Tranport field issue resolved --- Framework/AppInterface.php | 2 +- Framework/Interaction/Rest/Definitions.php | 2 +- Framework/Interaction/Tax.php | 27 ++++++++++++---------- composer.json | 2 +- docs/getting-started.md | 2 +- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Framework/AppInterface.php b/Framework/AppInterface.php index d02422fd..7bc437c0 100644 --- a/Framework/AppInterface.php +++ b/Framework/AppInterface.php @@ -20,7 +20,7 @@ interface AppInterface /** * Connector version */ - const APP_VERSION = '2.4.0'; + const APP_VERSION = '2.4.1'; /** * Avalara APP String */ diff --git a/Framework/Interaction/Rest/Definitions.php b/Framework/Interaction/Rest/Definitions.php index 7c66d946..138d0a66 100644 --- a/Framework/Interaction/Rest/Definitions.php +++ b/Framework/Interaction/Rest/Definitions.php @@ -25,7 +25,7 @@ class Definitions extends \ClassyLlama\AvaTax\Framework\Interaction\Rest implements \ClassyLlama\AvaTax\Api\RestDefinitionsInterface { - const PARAMETERS_FILTER = 'id=621'; + const PARAMETERS_FILTER = 'name=Transport'; /** * @var RestConfig */ diff --git a/Framework/Interaction/Tax.php b/Framework/Interaction/Tax.php index c51c598a..c16ae437 100644 --- a/Framework/Interaction/Tax.php +++ b/Framework/Interaction/Tax.php @@ -431,19 +431,22 @@ protected function convertTaxQuoteDetailsToRequest( $storeId = $quote->getStoreId(); $serialized_transport = $this->config->getVATTransport($storeId); $shipping_method = $quote->getShippingAddress()->getShippingMethod(); - $config_transports = $this->serialize->unserialize($serialized_transport); $transport_parameters_value = $this->config::AVATAX_PARAMETERS_TRANSPORT_DEFAULT_VALUE; - if($config_transports && !empty($config_transports)) - { - foreach($config_transports as $config_transport) - { - if($shipping_method == $config_transport['transport_shipping']) - { - $transport_parameters_value = $config_transport['transport']; - break; - } - } - } + if($serialized_transport && !empty($serialized_transport)) + { + $config_transports = $this->serialize->unserialize($serialized_transport); + if($config_transports && !empty($config_transports)) + { + foreach($config_transports as $config_transport) + { + if($shipping_method == $config_transport['transport_shipping']) + { + $transport_parameters_value = $config_transport['transport']; + break; + } + } + } + } $data = [ 'store_id' => $store->getId(), 'commit' => false, // quotes should never be committed diff --git a/composer.json b/composer.json index b4a07f61..237a75f9 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "avalara/avatax-magento", "type": "magento2-module", - "version": "2.4.0", + "version": "2.4.1", "license": "OSL-3.0", "description": "Magento module for Avalara's AvaTax suite of business tax calculation and processing services. Uses the AvaTax REST v2 API.", "require": { diff --git a/docs/getting-started.md b/docs/getting-started.md index 863bdaa2..2b35b165 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -57,7 +57,7 @@ This is the recommended installation method as it allows you to easily update th 1. Require the desired version of AvaTax. Latest version can be installed by running following command: ``` - composer require avalara/avatax-magento:2.4.0 + composer require avalara/avatax-magento:2.4.1 ``` 2. Setup the AvaTax module in magento From 5ff2291fd405854b0d9d6b4700f070a578a9d19f Mon Sep 17 00:00:00 2001 From: Nirav Patel Date: Fri, 4 Nov 2022 16:42:26 +0530 Subject: [PATCH 2/2] Release2.4.1 - Queue error fixed --- BaseProvider/Framework/Rest/ApiClient.php | 2 +- .../Model/Queue/Consumer/ApiLogConsumer.php | 2 +- .../Form/Field/CustomShippingMethods.php | 2 +- Framework/Interaction/Rest.php | 73 +++++++++++++++---- Framework/Interaction/Rest/Tax.php | 4 +- Helper/AvaTaxClientWrapper.php | 2 +- Helper/Config.php | 16 ++-- Helper/CustomsConfig.php | 23 +++++- .../Checkout/AddressValidation.php | 4 +- .../Source/CarrierMethodProviders/Fedex.php | 2 +- .../Source/CarrierMethodProviders/UPS.php | 2 +- .../Source/CarrierMethodProviders/USPS.php | 2 +- .../Source/CarrierShippingMethodsProvider.php | 2 +- Model/Config/Source/RegionFilterList.php | 2 +- Model/Plugin/CartTotalRepository.php | 2 +- Model/Queue/Processing/NormalProcessing.php | 24 +++++- .../Model/ShippingInformationManagement.php | 2 +- .../ExtensionAttributesPersistencePlugin.php | 2 +- 18 files changed, 124 insertions(+), 44 deletions(-) diff --git a/BaseProvider/Framework/Rest/ApiClient.php b/BaseProvider/Framework/Rest/ApiClient.php index b76a77ed..46e39928 100644 --- a/BaseProvider/Framework/Rest/ApiClient.php +++ b/BaseProvider/Framework/Rest/ApiClient.php @@ -152,7 +152,7 @@ public function restCall( $params ); $body = (string) $response->getBody(); - $JsonBody = json_decode($body, $getArray); + $JsonBody = json_decode((string)$body, $getArray); if (($this->responseType == 'array') && (!is_null($JsonBody))) { return $JsonBody; } else { diff --git a/BaseProvider/Model/Queue/Consumer/ApiLogConsumer.php b/BaseProvider/Model/Queue/Consumer/ApiLogConsumer.php index 5df6fbb3..cad8280d 100644 --- a/BaseProvider/Model/Queue/Consumer/ApiLogConsumer.php +++ b/BaseProvider/Model/Queue/Consumer/ApiLogConsumer.php @@ -86,7 +86,7 @@ public function consume(\ClassyLlama\AvaTax\BaseProvider\Api\Data\QueueInterface $success = true; $response = []; $payload = $queueJob->getPayload(); - $payload = json_decode($payload, true); + $payload = json_decode((string)$payload, true); $client = $this->restClient; if (count($payload) > 0) { foreach($payload as $method=>$arguments) { diff --git a/Block/Adminhtml/Form/Field/CustomShippingMethods.php b/Block/Adminhtml/Form/Field/CustomShippingMethods.php index bfc72119..af9ee1a9 100644 --- a/Block/Adminhtml/Form/Field/CustomShippingMethods.php +++ b/Block/Adminhtml/Form/Field/CustomShippingMethods.php @@ -42,7 +42,7 @@ class CustomShippingMethods extends \Magento\Config\Block\System\Config\Form\Fie */ public static function parseSerializedValue($config) { - $parsedValue = (array)json_decode($config ?? '', true); + $parsedValue = (array)json_decode((string)$config ?? '', true); $shippingCodesById = []; foreach ($parsedValue as $value) { diff --git a/Framework/Interaction/Rest.php b/Framework/Interaction/Rest.php index c0839d51..542a08a9 100644 --- a/Framework/Interaction/Rest.php +++ b/Framework/Interaction/Rest.php @@ -155,22 +155,7 @@ protected function handleException($exception, $request = null, $logLevel = LOG_ if ($response !== null) { try { - $logMessage = __( - 'AvaTax connection error: %1', - trim( - array_reduce( - (array)$response['error']['details'], - function ($error, $detail) { - if (isset($detail['severity']) && $detail['severity'] !== 'Exception' && $detail['severity'] !== 'Error') { - return $error; - } - - return $error . ' ' . $detail['description']; - }, - '' - ) - ) - ); + $logMessage = $this->prepareErrorForHandleException($response); } catch (\Exception $ex) { $logMessage = __( 'AvaTax connection error: %1', $ex->getMessage()); @@ -205,6 +190,62 @@ function ($error, $detail) { throw new AvataxConnectionException($logMessage, $exception); } + /** + * prepare Error or Errors to Handle Exception + * + * @param array $response + * @return \Magento\Framework\Phrase + */ + protected function prepareErrorForHandleException(array $response) + { + $logMessage = __("AvaTax connection error"); + if (isset($response['error'])) { + $logMessage = __( + 'AvaTax connection error: %1', + trim( + array_reduce( + (array)$response['error']['details'], + function ($error, $detail) { + if (isset($detail['severity']) && $detail['severity'] !== 'Exception' && $detail['severity'] !== 'Error') { + return $error; + } + + return $error . ' ' . $detail['description']; + }, + '' + ) + ) + ); + } + if (isset($response['errors'])) { + $messages = ''; + foreach($response['errors'] as $error){ + if ($messages != '') { + $messages .= ' '; + } + if (is_string($error)) { + $messages .= ' '.$error; + } + if (is_array($error)) { + $messages .= trim( + array_reduce( + (array)$error, + function ($err1, $err2) { + return $err1 . ' ' . $err2; + }, + '' + ) + ); + } + } + $messages = trim($messages); + if ($messages != '') { + $logMessage = __("AvaTax connection error: %1", $messages); + } + } + return $logMessage; + } + /** * Convert a simple object to a data object * diff --git a/Framework/Interaction/Rest/Tax.php b/Framework/Interaction/Rest/Tax.php index e9d24fe7..25625213 100644 --- a/Framework/Interaction/Rest/Tax.php +++ b/Framework/Interaction/Rest/Tax.php @@ -141,7 +141,8 @@ public function getTax( $request, $isProduction = null, $scopeId = null, $scopeT 'customerCode' => $request->getCustomerCode(), 'dateTime' => $request->getDate(), ]); - + $this->customsConfigHelper->initNextIncrementForWithParameter(); + $this->setTransactionDetails($transactionBuilder, $request); $this->setLineDetails($transactionBuilder, $request); $logContext['extra']['LineCount'] = $transactionBuilder->getCurrentLineNumber() - 1; @@ -388,6 +389,7 @@ public function getTaxBatch( 'customerCode' => $request->getCustomerCode(), 'dateTime' => $request->getDate(), ]); + $this->customsConfigHelper->initNextIncrementForWithParameter(); $this->setTransactionDetails($transactionBuilder, $request); try { $this->setLineDetails($transactionBuilder, $request); diff --git a/Helper/AvaTaxClientWrapper.php b/Helper/AvaTaxClientWrapper.php index a60df59d..06c8064d 100644 --- a/Helper/AvaTaxClientWrapper.php +++ b/Helper/AvaTaxClientWrapper.php @@ -84,7 +84,7 @@ protected function executeRequest($verb, $apiUrl, $guzzleParams) // The body is already encoded as JSON, we need to decode it first so we don't double-encode it if (is_string($guzzleParams['body'])) { - $guzzleParams['body'] = json_decode($guzzleParams['body']); + $guzzleParams['body'] = json_decode((string)$guzzleParams['body']); } $this->logger->debug( diff --git a/Helper/Config.php b/Helper/Config.php index 958a87aa..a05c1898 100644 --- a/Helper/Config.php +++ b/Helper/Config.php @@ -501,14 +501,14 @@ public function isAddressTaxable(\Magento\Framework\DataObject $address, $storeI $isTaxable = true; // Filtering just by country (not region) if (!$this->getFilterTaxByRegion($storeId)) { - $countryFilters = explode(',', $this->getTaxCalculationCountriesEnabled($storeId)); + $countryFilters = explode(',', (string)$this->getTaxCalculationCountriesEnabled($storeId)); $countryId = $address->getCountryId(); if (!in_array($countryId, $countryFilters)) { $isTaxable = false; } // Filtering by region within countries } else { - $regionFilters = explode(',', $this->getRegionFilterList($storeId)); + $regionFilters = explode(',', (string)$this->getRegionFilterList($storeId)); $entityId = $address->getRegionId() ?: $address->getCountryId(); if (!in_array($entityId, $regionFilters)) { $isTaxable = false; @@ -1281,7 +1281,7 @@ public function getShippingTaxCode($store = null) */ public function getTableExemptions() { - return explode(",", $this->scopeConfig->getValue(self::XML_PATH_AVATAX_ADVANCED_AVATAX_TABLE_EXEMPTIONS)); + return explode(",", (string)$this->scopeConfig->getValue(self::XML_PATH_AVATAX_ADVANCED_AVATAX_TABLE_EXEMPTIONS)); } /** @@ -1292,7 +1292,7 @@ public function getConfigDataArray(string $configPath) { return explode( ',', - $this->scopeConfig->getValue( + (string)$this->scopeConfig->getValue( $configPath ) ); @@ -1336,10 +1336,14 @@ public function getTaxationPolicy($store = null) */ public function getVATTransport($store = null) { - return stripslashes( $this->scopeConfig->getValue( + $VATTransportMapping = $this->scopeConfig->getValue( self::XML_PATH_AVATAX_VAT_TRANSPORT, ScopeInterface::SCOPE_STORE, $store - ) ); + ); + if (is_null($VATTransportMapping)) { + $VATTransportMapping = ''; + } + return stripslashes((string)$VATTransportMapping); } } diff --git a/Helper/CustomsConfig.php b/Helper/CustomsConfig.php index 79e3c79b..0d70e927 100644 --- a/Helper/CustomsConfig.php +++ b/Helper/CustomsConfig.php @@ -138,7 +138,7 @@ public function getGroundShippingMethods($store = null, $scopeType = ScopeInterf { return explode( ',', - $this->scopeConfig->getValue( + (string)$this->scopeConfig->getValue( self::XML_PATH_AVATAX_CUSTOMS_GROUND_SHIPPING_METHODS, $scopeType, $store @@ -156,7 +156,7 @@ public function getOceanShippingMethods($store = null, $scopeType = ScopeInterfa { return explode( ',', - $this->scopeConfig->getValue( + (string)$this->scopeConfig->getValue( self::XML_PATH_AVATAX_CUSTOMS_OCEAN_SHIPPING_METHODS, $scopeType, $store @@ -174,7 +174,7 @@ public function getAirShippingMethods($store = null, $scopeType = ScopeInterface { return explode( ',', - $this->scopeConfig->getValue( + (string)$this->scopeConfig->getValue( self::XML_PATH_AVATAX_CUSTOMS_AIR_SHIPPING_METHODS, $scopeType, $store @@ -262,6 +262,23 @@ public function getShippingTypeForMethod($method, $scopeId = null, $scopeType = // Return default method return $this->getDefaultShippingType($scopeId, $scopeType); } + + /** + * Init parameters next increment for each new transaction + * + * @return CustomsConfig + */ + public function initNextIncrementForWithParameter() + { + $this->withParameterIncrementId = 0; + return $this; + } + + /** + * Next place for parameters in a transaction + * + * @return int + */ public function getNextIncrementForWithParameter() { return $this->withParameterIncrementId++; diff --git a/Helper/Multishipping/Checkout/AddressValidation.php b/Helper/Multishipping/Checkout/AddressValidation.php index 8ca1650f..039b0125 100755 --- a/Helper/Multishipping/Checkout/AddressValidation.php +++ b/Helper/Multishipping/Checkout/AddressValidation.php @@ -89,7 +89,7 @@ public function validateAddress( $address ) { $result = []; - if (in_array($address->getCountryId(), explode(',', $this->customerAddressBlock->getCountriesEnabled()))) { + if (in_array($address->getCountryId(), explode(',', (string)$this->customerAddressBlock->getCountriesEnabled()))) { /** @var AddressInterface $result */ try { $validAddress = $this->validation->validateAddress($address, @@ -110,7 +110,7 @@ public function validateAddress( 'validAddressHtml' => $this->prepareAddressString($validAddress, $changedFields), 'originalAddressHtml' => $this->prepareAddressString($address), 'hasChoice' => $this->customerAddressBlock->getChoice(), - 'instructions' => json_decode($this->customerAddressBlock->getInstructions()), + 'instructions' => json_decode((string)$this->customerAddressBlock->getInstructions()), ]; } } diff --git a/Model/Config/Source/CarrierMethodProviders/Fedex.php b/Model/Config/Source/CarrierMethodProviders/Fedex.php index e200e1ce..fe052aeb 100644 --- a/Model/Config/Source/CarrierMethodProviders/Fedex.php +++ b/Model/Config/Source/CarrierMethodProviders/Fedex.php @@ -46,7 +46,7 @@ public function getConfiguredMethods() try { $allowedMethods = $this->carrier->getConfigData('allowed_methods'); if ($allowedMethods) { - return explode(",", $allowedMethods); + return explode(",", (string)$allowedMethods); } else { return []; } diff --git a/Model/Config/Source/CarrierMethodProviders/UPS.php b/Model/Config/Source/CarrierMethodProviders/UPS.php index 9f67c6c6..e63063ed 100644 --- a/Model/Config/Source/CarrierMethodProviders/UPS.php +++ b/Model/Config/Source/CarrierMethodProviders/UPS.php @@ -53,7 +53,7 @@ public function getConfiguredMethods() try { $allowedMethods = $this->carrier->getConfigData('allowed_methods'); if ($allowedMethods) { - return explode(",", $allowedMethods); + return explode(",", (string)$allowedMethods); } else { return []; } diff --git a/Model/Config/Source/CarrierMethodProviders/USPS.php b/Model/Config/Source/CarrierMethodProviders/USPS.php index 11e70add..9990637c 100644 --- a/Model/Config/Source/CarrierMethodProviders/USPS.php +++ b/Model/Config/Source/CarrierMethodProviders/USPS.php @@ -46,7 +46,7 @@ public function getConfiguredMethods() try { $allowedMethods = $this->carrier->getConfigData('allowed_methods'); if ($allowedMethods) { - return explode(",", $allowedMethods); + return explode(",", (string)$allowedMethods); } else { return []; } diff --git a/Model/Config/Source/CarrierShippingMethodsProvider.php b/Model/Config/Source/CarrierShippingMethodsProvider.php index 80e46b8b..724d2dbe 100644 --- a/Model/Config/Source/CarrierShippingMethodsProvider.php +++ b/Model/Config/Source/CarrierShippingMethodsProvider.php @@ -87,7 +87,7 @@ protected function getCarrierConfig($configPath) { list($scopeType, $scopeId) = $this->getScopeInfo(); - return explode(',', $this->scopeConfig->getValue($configPath, $scopeType, $scopeId)); + return explode(',', (string)$this->scopeConfig->getValue($configPath, $scopeType, $scopeId)); } /** diff --git a/Model/Config/Source/RegionFilterList.php b/Model/Config/Source/RegionFilterList.php index 17887dca..a15c7825 100644 --- a/Model/Config/Source/RegionFilterList.php +++ b/Model/Config/Source/RegionFilterList.php @@ -130,6 +130,6 @@ protected function getCountryList() $scopeType = \Magento\Store\Model\ScopeInterface::SCOPE_STORE; } - return explode(',', $this->config->getTaxCalculationCountriesEnabled($scopeId, $scopeType)); + return explode(',', (string)$this->config->getTaxCalculationCountriesEnabled($scopeId, $scopeType)); } } diff --git a/Model/Plugin/CartTotalRepository.php b/Model/Plugin/CartTotalRepository.php index 4b85370d..4f30fa8b 100644 --- a/Model/Plugin/CartTotalRepository.php +++ b/Model/Plugin/CartTotalRepository.php @@ -67,7 +67,7 @@ public function afterGet(TotalRepository $subject, TotalsInterface $totals, $car continue; } - $message = json_decode($address->getAvataxMessages()); + $message = json_decode((string)$address->getAvataxMessages()); if(is_array($message)) { $messages[] = $message; diff --git a/Model/Queue/Processing/NormalProcessing.php b/Model/Queue/Processing/NormalProcessing.php index 7e94882e..9b08f0a2 100644 --- a/Model/Queue/Processing/NormalProcessing.php +++ b/Model/Queue/Processing/NormalProcessing.php @@ -166,6 +166,24 @@ protected function processWithAvaTax(Queue $queue, $entity): GetTaxResponseInter $e->getMessage() ); + $this->handleErrorofProcessWithAvaTax($message, $queue, $entity, $e); + + throw new Exception($message, 0, $e); + } + + return $processSalesResponse; + } + + /** + * @param \Magento\Framework\Phrase $message + * @param Queue $queue + * @param InvoiceInterface|CreditmemoInterface $entity + * @param Exception $e + * @return void + */ + protected function handleErrorofProcessWithAvaTax(\Magento\Framework\Phrase $message, Queue $queue, $entity, Exception $e): void + { + try { // Log the error $this->avaTaxLogger->error( $message, @@ -185,11 +203,9 @@ protected function processWithAvaTax(Queue $queue, $entity): GetTaxResponseInter // Update the queue record // and add comment to order $this->resetQueueingForProcessing($queue, $message, $entity); - - throw new Exception($message, null, $e); + } catch (Exception $e) { + // do nothing } - - return $processSalesResponse; } /** diff --git a/Plugin/Checkout/Model/ShippingInformationManagement.php b/Plugin/Checkout/Model/ShippingInformationManagement.php index 8212a57b..7ad22c70 100644 --- a/Plugin/Checkout/Model/ShippingInformationManagement.php +++ b/Plugin/Checkout/Model/ShippingInformationManagement.php @@ -186,7 +186,7 @@ public function aroundSaveAddressInformation( $enabledAddressValidationCountries = explode( ',', - $this->config->getAddressValidationCountriesEnabled($storeId) + (string)$this->config->getAddressValidationCountriesEnabled($storeId) ); if (!in_array($shippingAddress->getCountryId(), $enabledAddressValidationCountries)) { $shouldValidateAddress = false; diff --git a/Plugin/Model/ResourceModel/ExtensionAttributesPersistencePlugin.php b/Plugin/Model/ResourceModel/ExtensionAttributesPersistencePlugin.php index f7b69a3d..a8bc7524 100644 --- a/Plugin/Model/ResourceModel/ExtensionAttributesPersistencePlugin.php +++ b/Plugin/Model/ResourceModel/ExtensionAttributesPersistencePlugin.php @@ -88,7 +88,7 @@ protected function getJoinDirectivesForType($extensibleEntityClass) } $extensibleInterfaceName = $this->extensionAttributesFactory->getExtensibleInterfaceName($extensibleEntityClass); - $stringArray = explode('\\', $extensibleInterfaceName); + $stringArray = explode('\\', (string)$extensibleInterfaceName); $extensibleEntityName = strtolower(str_replace('Interface', '', end($stringArray))); return array_filter(