Skip to content

Commit

Permalink
Merge pull request #4 from wirecard/explicit-amount-precision
Browse files Browse the repository at this point in the history
#3: Add amount precision to calculateQuoteChecksum
  • Loading branch information
wd-chofer authored Jul 6, 2016
2 parents 5321426 + 0c66fae commit 35ebf41
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
16 changes: 13 additions & 3 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,16 @@ public function getLanguage()
return $locale;
}

/**
* get amount precision
*
* @return int
*/
public function getPrecision()
{
return 2;
}

/**
* @return bool|\Zend\Http\Header\HeaderInterface
*/
Expand Down Expand Up @@ -310,15 +320,15 @@ public function getPayolutionLink($mId)
*/
public function calculateQuoteChecksum($quote)
{
$data = $quote->getBaseGrandTotal() .
$data = round($quote->getBaseGrandTotal(), $this->getPrecision()) .
$quote->getBaseCurrencyCode() .
$quote->getCustomerEmail();

foreach ($quote->getAllVisibleItems() as $item) {
/** @var \Magento\Quote\Model\Quote\Item $item */
$data .= $item->getSku();
$data .= $item->getPrice();
$data .= $item->getTaxAmount();
$data .= round($item->getPrice(), $this->getPrecision());
$data .= round($item->getTaxAmount(), $this->getPrecision());
}

$address = $quote->getBillingAddress();
Expand Down
11 changes: 5 additions & 6 deletions Model/AbstractPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ public function initPaymentByCart(CheckoutCart $cart, $urls, \Magento\Framework\
$init->setOrderReference(sprintf('%010d', $orderId));
$init->uniqueId = $this->_getUniqueId($cart);

$precision = 2;
$init->setAmount(round($cart->getQuote()->getBaseGrandTotal(), $precision))
$init->setAmount(round($cart->getQuote()->getBaseGrandTotal(), $this->_dataHelper->getPrecision()))
->setCurrency($quote->getCurrency()->getBaseCurrencyCode())
->setPaymentType($this->_paymentMethod)
->setOrderDescription($this->getUserDescription($quote))
Expand Down Expand Up @@ -178,15 +177,15 @@ public function initPaymentByCart(CheckoutCart $cart, $urls, \Magento\Framework\
$bitem = new \WirecardCEE_Stdlib_Basket_Item();
$bitem->setDescription($item->getProduct()->getName());
$bitem->setArticleNumber($item->getSku());
$bitem->setUnitPrice(number_format($item->getPrice(), $precision, '.', ''));
$bitem->setTax(number_format($item->getTaxAmount(), $precision, '.', ''));
$bitem->setUnitPrice(number_format($item->getPrice(), $this->_dataHelper->getPrecision(), '.', ''));
$bitem->setTax(number_format($item->getTaxAmount(), $this->_dataHelper->getPrecision(), '.', ''));
$basket->addItem($bitem, (int) $item->getQty());
}

$bitem = new \WirecardCEE_Stdlib_Basket_Item();
$bitem->setArticleNumber('shipping');
$bitem->setUnitPrice(number_format($quote->getShippingAddress()->getShippingAmount(), $precision, '.', ''));
$bitem->setTax(number_format($quote->getShippingAddress()->getShippingTaxAmount(), $precision, '.', ''));
$bitem->setUnitPrice(number_format($quote->getShippingAddress()->getShippingAmount(), $this->_dataHelper->getPrecision(), '.', ''));
$bitem->setTax(number_format($quote->getShippingAddress()->getShippingTaxAmount(), $this->_dataHelper->getPrecision(), '.', ''));
$bitem->setDescription($quote->getShippingAddress()->getShippingDescription());
$basket->addItem($bitem);

Expand Down

0 comments on commit 35ebf41

Please sign in to comment.