Skip to content

Commit

Permalink
Merge pull request #455 from BoulangerV/MAGE-505-Fix_Paydirekt_Shippi…
Browse files Browse the repository at this point in the history
…ng_VAT

Mage 505 fix paydirekt shipping vat
  • Loading branch information
Florian Bender authored Nov 27, 2020
2 parents d7c7b0d + 34c5a44 commit 9a13727
Showing 1 changed file with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ protected function _initQuoteItems(Payone_Api_Request_Parameter_Invoicing_Transa
$params['pr'] = $this->_convertItemPrice($itemData);
$params['no'] = $number;
$params['de'] = $itemData->getName();
$params['va'] = $itemData->getTaxPercent();
$params['va'] = round($itemData->getTaxPercent() * 100, 0);

$item = new Payone_Api_Request_Parameter_Invoicing_Item();
$item->init($params);
Expand All @@ -516,14 +516,11 @@ protected function _initQuoteItems(Payone_Api_Request_Parameter_Invoicing_Transa
*/
protected function _convertItemPrice(Mage_Sales_Model_Quote_Item $itemData)
{
// If tax is applied after discount, the item hold the tax compensation for that discount
// we have then to substract it from the item price
$dTC = $itemData->getDiscountTaxCompensation();
if ($this->configPayment->getCurrencyConvert()) {
return $itemData->getBasePriceInclTax() - $dTC;
return $itemData->getBasePriceInclTax();
}

return $itemData->getPriceInclTax() - $dTC;
return $itemData->getPriceInclTax();
}

/**
Expand All @@ -537,18 +534,14 @@ protected function _initsetShippingItem(Payone_Api_Request_Parameter_Invoicing_T
$sku = $this->getFactory()->helper()->__(self::DEFAULT_SHIPPING_SKU);
}

$shippingVatRatio = $this->quote->getShippingAddress()->getShippingTaxAmount()
/ $this->quote->getShippingAddress()->getShippingAmount();
if (is_nan($shippingVatRatio) || !is_numeric($shippingVatRatio)) {
$shippingVatRatio = 0;
}
$shippingVatRatio = $this->fetchShippingVatRatio($this->quote);

$params['it'] = Payone_Api_Enum_InvoicingItemType::SHIPMENT;
$params['id'] = $sku;
$params['pr'] = $this->_convertShippingAmount($this->quote->getShippingAddress());
$params['no'] = 1;
$params['de'] = 'Shipping Costs';
$params['va'] = round($shippingVatRatio * 100, 2);
$params['va'] = round($shippingVatRatio * 100, 0);

$item = new Payone_Api_Request_Parameter_Invoicing_Item();
$item->init($params);
Expand Down Expand Up @@ -612,6 +605,24 @@ protected function _convertDiscountAmount()
return $this->quote->getShippingAddress()->getDiscountAmount();
}

/**
* @param Mage_Sales_Model_Quote $quote
* @return float
*/
protected function fetchShippingVatRatio(Mage_Sales_Model_Quote $quote)
{
$store = $quote->getStore();
$taxCalculation = Mage::getModel('tax/calculation');
$request = $taxCalculation->getRateRequest(null, null, null, $store);
$taxRateId = Mage::getStoreConfig('tax/classes/shipping_tax_class', $store);
$shippingVatRatio = $taxCalculation->getRate($request->setProductClassId($taxRateId));
if (is_nan($shippingVatRatio) || !is_numeric($shippingVatRatio)) {
$shippingVatRatio = 0.00;
}

return $shippingVatRatio;
}

/**
* @return Payone_Core_Helper_Config
*/
Expand Down

0 comments on commit 9a13727

Please sign in to comment.