/** * Accepts an invoice or creditmemo and returns an \AvaTax\Line object * * @param \Magento\Sales\Api\Data\InvoiceInterface|\Magento\Sales\Api\Data\CreditmemoInterface $data * @param $credit * @return \AvaTax\Line|bool * @throws MetaData\ValidationException */ public function getShippingLine($data, $credit) { $shippingAmount = $data->getBaseShippingAmount(); // If shipping rate doesn't have cost associated with it, do nothing if ($shippingAmount <= 0) { return false; } if ($credit) { $shippingAmount *= -1; } $storeId = $data->getStoreId(); $itemCode = $this->config->getSkuShipping($storeId); $data = ['No' => $this->getLineNumber(), 'ItemCode' => $itemCode, 'TaxCode' => $this->taxClassHelper->getAvataxTaxCodeForShipping(), 'Description' => self::SHIPPING_LINE_DESCRIPTION, 'Qty' => 1, 'Amount' => $shippingAmount, 'Discounted' => false]; try { $data = $this->metaDataObject->validateData($data); } catch (ValidationException $e) { $this->avaTaxLogger->error('Error validating line: ' . $e->getMessage(), ['data' => var_export($data, true)]); } /** @var $line \AvaTax\Line */ $line = $this->lineFactory->create(); $this->populateLine($data, $line); return $line; }