Skip to content

Commit

Permalink
Merged in VIPPS-196-to-2.3 (pull request #75)
Browse files Browse the repository at this point in the history
VIPPS-196: Order amount in Vipps is not the same as in Magento

Approved-by: Volodymyr Klymenko <[email protected]>
Approved-by: Serhiy Shkolyarenko <[email protected]>
  • Loading branch information
Ostap Smolyar committed Feb 25, 2019
2 parents 5220d97 + 50c5aec commit 7ff0e49
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Gateway/Command/CaptureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function __construct(
public function execute(array $commandSubject)
{
$amount = $this->subjectReader->readAmount($commandSubject);
$amount = (int)($this->formatPrice($amount) * 100);
$amount = (int)round($this->formatPrice($amount) * 100);

$response = $this->paymentDetailsProvider->get($commandSubject);
$transaction = $this->transactionBuilder->setData($response)->build();
Expand Down Expand Up @@ -219,14 +219,14 @@ private function captureBasedOnPaymentDetails($commandSubject, Transaction $tran
{
$payment = $this->subjectReader->readPayment($commandSubject);
$amount = $this->subjectReader->readAmount($commandSubject);
$amount = (int)($this->formatPrice($amount) * 100);
$amount = (int)round($this->formatPrice($amount) * 100);

$orderAdapter = $payment->getOrder();
$orderIncrementId = $orderAdapter->getOrderIncrementId();

$order = $this->orderRepository->get($orderAdapter->getId());

$magentoTotalDue = (int)($this->formatPrice($order->getTotalDue()) * 100);
$magentoTotalDue = (int)round($this->formatPrice($order->getTotalDue()) * 100);
$vippsTotalDue = $transaction->getTransactionSummary()->getRemainingAmountToCapture();

$deltaTotalDue = $magentoTotalDue - $vippsTotalDue;
Expand Down
6 changes: 3 additions & 3 deletions Gateway/Command/RefundCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function __construct(
public function execute(array $commandSubject)
{
$amount = $this->subjectReader->readAmount($commandSubject);
$amount = (int)($this->formatPrice($amount) * 100);
$amount = (int)round($this->formatPrice($amount) * 100);

$response = $this->paymentDetailsProvider->get($commandSubject);
$transaction = $this->transactionBuilder->setData($response)->build();
Expand Down Expand Up @@ -220,14 +220,14 @@ private function refundBasedOnPaymentDetails($commandSubject, Transaction $trans
{
$payment = $this->subjectReader->readPayment($commandSubject);
$amount = $this->subjectReader->readAmount($commandSubject);
$amount = (int)($this->formatPrice($amount) * 100);
$amount = (int)round($this->formatPrice($amount) * 100);

$orderAdapter = $payment->getOrder();
$orderIncrementId = $orderAdapter->getOrderIncrementId();

$order = $this->orderRepository->get($orderAdapter->getId());

$magentoTotalRefunded = (int)($this->formatPrice($order->getTotalRefunded()) * 100);
$magentoTotalRefunded = (int)round($this->formatPrice($order->getTotalRefunded()) * 100);
$vippsTotalRefunded = $transaction->getTransactionSummary()->getRefundedAmount();

$deltaTotalRefunded = $vippsTotalRefunded - $magentoTotalRefunded;
Expand Down
4 changes: 2 additions & 2 deletions Gateway/Request/Initiate/TransactionDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ public function build(array $buildSubject)
$quote = $payment->getQuote();

$amount = $this->subjectReader->readAmount($buildSubject);
$amount = (int)($this->formatPrice($amount) * 100);
$amount = (int)round($this->formatPrice($amount) * 100);

if ($buildSubject[self::PAYMENT_TYPE_KEY] == self::PAYMENT_TYPE_EXPRESS_CHECKOUT) {
$shippingAddress = $quote->getShippingAddress();
$shippingAddress->setShippingMethod(null);
$quote->collectTotals();

$amount = (int)($this->formatPrice($quote->getGrandTotal()) * 100);
$amount = (int)round($this->formatPrice($quote->getGrandTotal()) * 100);
}

return [
Expand Down
2 changes: 1 addition & 1 deletion Gateway/Request/TransactionDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function build(array $buildSubject)

$amount = $this->subjectReader->readAmount($buildSubject);
if ($amount) {
$transactionData[self::$transaction][self::$amount] = (int)($this->formatPrice($amount) * 100);
$transactionData[self::$transaction][self::$amount] = (int)round($this->formatPrice($amount) * 100);
}

return $transactionData;
Expand Down
2 changes: 1 addition & 1 deletion Model/OrderPlace.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ private function prepareQuote($quote)
*/
private function validateAmount(CartInterface $quote, Transaction $transaction)
{
$quoteAmount = (int)($this->formatPrice($quote->getGrandTotal()) * 100);
$quoteAmount = (int)round($this->formatPrice($quote->getGrandTotal()) * 100);
$vippsAmount = (int)$transaction->getTransactionInfo()->getAmount();

if ($quoteAmount != $vippsAmount) {
Expand Down

0 comments on commit 7ff0e49

Please sign in to comment.