From 47976fbf0668937c02a0b6b57baae7108e4615d0 Mon Sep 17 00:00:00 2001 From: Volodymyr Klymenko Date: Wed, 16 Nov 2022 14:56:42 +0200 Subject: [PATCH] VIPPS-420: Receipt requests: Incorrect totals for rows and 400 errors in Profiling Requests --- .../Request/SendReceipt/OrderLinesBuilder.php | 22 +++++++++++++------ Model/Profiling/Profiler.php | 2 +- etc/module.xml | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Gateway/Request/SendReceipt/OrderLinesBuilder.php b/Gateway/Request/SendReceipt/OrderLinesBuilder.php index f5e42ef..c88b11d 100644 --- a/Gateway/Request/SendReceipt/OrderLinesBuilder.php +++ b/Gateway/Request/SendReceipt/OrderLinesBuilder.php @@ -71,14 +71,18 @@ public function build(array $buildSubject) $totalAmount = $item->getRowTotal() + $item->getTaxAmount() - $item->getDiscountAmount(); $totalAmountExcludingTax = $totalAmount - $item->getTaxAmount(); + $monitaryTotalAmount = (int)($totalAmount * 100); + $monitaryTotalAmountExcludingTax = (int)($totalAmountExcludingTax * 100); + $monitaryTaxAmount = $monitaryTotalAmount - $monitaryTotalAmountExcludingTax; + $orderLines[] = [ 'name' => $item->getName(), 'id' => $item->getSku(), - 'totalAmount' => (int)($totalAmount * 100), - 'totalAmountExcludingTax' => (int)($totalAmountExcludingTax * 100), - 'totalTaxAmount' => (int)($item->getTaxAmount() * 100), - 'taxPercentage' => $totalAmount > 0 - ? (int)round($item->getTaxAmount() * 100 / $totalAmount) + 'totalAmount' => $monitaryTotalAmount, + 'totalAmountExcludingTax' => $monitaryTotalAmountExcludingTax, + 'totalTaxAmount' => $monitaryTaxAmount, + 'taxPercentage' => $monitaryTotalAmountExcludingTax > 0 + ? (int)round($monitaryTaxAmount * 100 / $monitaryTotalAmountExcludingTax) : $item->getTaxPercent(), 'unitInfo' => [ 'unitPrice' => (int)($item->getPrice() * 100), @@ -91,14 +95,18 @@ public function build(array $buildSubject) ]; } + $monitaryShippingTotalAmount = (int)($order->getShippingInclTax() * 100); + $monitaryShippingTotalAmountExcludingTax = (int)($order->getShippingAmount() * 100); + $monitaryShippingTaxAmount = $monitaryShippingTotalAmount - $monitaryShippingTotalAmountExcludingTax; + $orderLines[] = [ 'name' => $order->getShippingDescription(), 'id' => 'shipping', 'totalAmount' => (int)($order->getShippingInclTax() * 100), 'totalAmountExcludingTax' => (int)($order->getShippingAmount() * 100), 'totalTaxAmount' => (int)($order->getShippingTaxAmount() * 100), - 'taxPercentage' => $order->getShippingInclTax() > 0 - ? (int)round($order->getShippingTaxAmount() * 100 / $order->getShippingInclTax()) + 'taxPercentage' => $monitaryShippingTotalAmountExcludingTax > 0 + ? (int)round($monitaryShippingTaxAmount * 100 / $monitaryShippingTotalAmountExcludingTax) : 0, 'discount' => (int)($order->getShippingDiscountAmount() * 100), 'isReturn' => false, diff --git a/Model/Profiling/Profiler.php b/Model/Profiling/Profiler.php index 87af60d..97d8881 100644 --- a/Model/Profiling/Profiler.php +++ b/Model/Profiling/Profiler.php @@ -195,7 +195,7 @@ private function packArray($data) { $recursive = function ($data, $indent = '') use (&$recursive) { $output = '{' . PHP_EOL; - foreach ($data as $key => $value) { + foreach ((array)$data as $key => $value) { if (is_array($value)) { $output .= $indent . ' ' . $key . ': ' . $recursive($value, $indent . ' ') . PHP_EOL; } elseif (!is_object($value)) { diff --git a/etc/module.xml b/etc/module.xml index 1634aa0..927133c 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -14,7 +14,7 @@ ~ IN THE SOFTWARE. --> - +