diff --git a/Gateway/Command/CaptureCommand.php b/Gateway/Command/CaptureCommand.php index bb6effe9..e8b68bae 100644 --- a/Gateway/Command/CaptureCommand.php +++ b/Gateway/Command/CaptureCommand.php @@ -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(); @@ -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; diff --git a/Gateway/Command/RefundCommand.php b/Gateway/Command/RefundCommand.php index 2916e9a1..797fc7d2 100644 --- a/Gateway/Command/RefundCommand.php +++ b/Gateway/Command/RefundCommand.php @@ -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(); @@ -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; diff --git a/Gateway/Http/Client/Curl.php b/Gateway/Http/Client/Curl.php index 7d79f5f4..b48e28db 100644 --- a/Gateway/Http/Client/Curl.php +++ b/Gateway/Http/Client/Curl.php @@ -57,16 +57,6 @@ class Curl implements ClientInterface */ private $logger; - /** - * @var array - */ - private $allowedFields = [ - 'orderId', - 'customerInfo', - 'merchantInfo', - 'transaction', - ]; - /** * Curl constructor. * @@ -125,7 +115,7 @@ private function place(TransferInterface $transfer) /** @var MagentoCurl $adapter */ $adapter = $this->adapterFactory->create(); $options = $this->getBasicOptions(); - $requestBody = $this->preparePostFields($transfer->getBody()); + $requestBody = $transfer->getBody(); if ($transfer->getMethod() === Request::METHOD_PUT) { $options = $options + [ @@ -152,24 +142,6 @@ private function place(TransferInterface $transfer) } } - /** - * Remove all fields that are not marked as known. - * - * @param array $fields - * @return array - */ - private function preparePostFields($fields) - { - $allowedFields = $this->allowedFields; - $fields = array_filter( - $fields, - function ($key) use ($allowedFields) { return in_array($key, $allowedFields);}, - ARRAY_FILTER_USE_KEY - ); - - return $fields; - } - /** * @param $headers * diff --git a/Gateway/Http/TransferFactory.php b/Gateway/Http/TransferFactory.php index 7664e4a4..09662011 100644 --- a/Gateway/Http/TransferFactory.php +++ b/Gateway/Http/TransferFactory.php @@ -54,6 +54,16 @@ class TransferFactory implements TransferFactoryInterface */ private $urlParams = []; + /** + * @var array + */ + private $allowedFields = [ + 'orderId', + 'customerInfo', + 'merchantInfo', + 'transaction', + ]; + /** * TransferFactory constructor. * @@ -91,9 +101,7 @@ public function create(array $request) ClientInterface::HEADER_PARAM_X_REQUEST_ID => $request['requestId'] ?? $this->generateRequestId() ]); - if (isset($request['requestId'])) { - unset($request['requestId']); - } + $request = $this->filterPostFields($request); $this->transferBuilder ->setBody($this->getBody($request)) @@ -103,6 +111,24 @@ public function create(array $request) return $this->transferBuilder->build(); } + /** + * Remove all fields that are not marked as allowed. + * + * @param array $fields + * @return array + */ + private function filterPostFields($fields) + { + $allowedFields = $this->allowedFields; + $fields = array_filter( + $fields, + function ($key) use ($allowedFields) { return in_array($key, $allowedFields);}, + ARRAY_FILTER_USE_KEY + ); + + return $fields; + } + /** * Generating Url. * diff --git a/Gateway/Request/Initiate/TransactionDataBuilder.php b/Gateway/Request/Initiate/TransactionDataBuilder.php index bc9a9b3d..09e4bfbc 100644 --- a/Gateway/Request/Initiate/TransactionDataBuilder.php +++ b/Gateway/Request/Initiate/TransactionDataBuilder.php @@ -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 [ diff --git a/Gateway/Request/TransactionDataBuilder.php b/Gateway/Request/TransactionDataBuilder.php index a38ded17..6bedbeec 100644 --- a/Gateway/Request/TransactionDataBuilder.php +++ b/Gateway/Request/TransactionDataBuilder.php @@ -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; diff --git a/Model/OrderPlace.php b/Model/OrderPlace.php index 55230673..4a11a6c8 100644 --- a/Model/OrderPlace.php +++ b/Model/OrderPlace.php @@ -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) { diff --git a/composer.json b/composer.json index 697e6444..7e6b0112 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "magento2-module", "description": "Vipps Payment Method", "license": "proprietary", - "version": "1.2.2", + "version": "1.2.3", "require": { "magento/framework": "101.0.*", "magento/module-sales": "101.0.*",