Skip to content

Commit

Permalink
Merge pull request #64 from avadev/release/2.4.1
Browse files Browse the repository at this point in the history
Release/2.4.1
  • Loading branch information
avl-asheesh-singh authored Nov 4, 2022
2 parents d3a51b0 + 5ff2291 commit 7a0456f
Show file tree
Hide file tree
Showing 23 changed files with 143 additions and 60 deletions.
2 changes: 1 addition & 1 deletion BaseProvider/Framework/Rest/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion BaseProvider/Model/Queue/Consumer/ApiLogConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/Form/Field/CustomShippingMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Framework/AppInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface AppInterface
/**
* Connector version
*/
const APP_VERSION = '2.4.0';
const APP_VERSION = '2.4.1';
/**
* Avalara APP String
*/
Expand Down
73 changes: 57 additions & 16 deletions Framework/Interaction/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion Framework/Interaction/Rest/Definitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 3 additions & 1 deletion Framework/Interaction/Rest/Tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
27 changes: 15 additions & 12 deletions Framework/Interaction/Tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Helper/AvaTaxClientWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 10 additions & 6 deletions Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -1292,7 +1292,7 @@ public function getConfigDataArray(string $configPath)
{
return explode(
',',
$this->scopeConfig->getValue(
(string)$this->scopeConfig->getValue(
$configPath
)
);
Expand Down Expand Up @@ -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);
}
}
23 changes: 20 additions & 3 deletions Helper/CustomsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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++;
Expand Down
4 changes: 2 additions & 2 deletions Helper/Multishipping/Checkout/AddressValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()),
];
}
}
Expand Down
2 changes: 1 addition & 1 deletion Model/Config/Source/CarrierMethodProviders/Fedex.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
Expand Down
2 changes: 1 addition & 1 deletion Model/Config/Source/CarrierMethodProviders/UPS.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
Expand Down
2 changes: 1 addition & 1 deletion Model/Config/Source/CarrierMethodProviders/USPS.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
Expand Down
2 changes: 1 addition & 1 deletion Model/Config/Source/CarrierShippingMethodsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Model/Config/Source/RegionFilterList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
2 changes: 1 addition & 1 deletion Model/Plugin/CartTotalRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 7a0456f

Please sign in to comment.