diff --git a/src/Processor/CheckoutProcessor.php b/src/Processor/CheckoutProcessor.php index b3b1df31a..4347a24a2 100644 --- a/src/Processor/CheckoutProcessor.php +++ b/src/Processor/CheckoutProcessor.php @@ -88,6 +88,8 @@ public function run(CheckoutData $data) throw CouldNotProcessCheckout::failedToFindCart($data->getCartId()); } + $cartTotal = (int) round($cart->getOrderTotal(true) * SaferPayConfig::AMOUNT_MULTIPLIER_FOR_API); + if (!$data->getCreateAfterAuthorization()) { $this->processCreateOrder($cart, $data->getPaymentMethod()); } @@ -109,7 +111,8 @@ public function run(CheckoutData $data) $data->getSelectedCard(), $data->getFieldToken(), $data->getSuccessController(), - $data->getIsWebhook() + $data->getIsWebhook(), + $cartTotal ); } catch (\Exception $exception) { throw new SaferPayApiException('Failed to initialize payment API', SaferPayApiException::INITIALIZE); @@ -196,7 +199,8 @@ private function processInitializePayment( $selectedCard, $fieldToken, $successController, - $isWebhook + $isWebhook, + $cartTotal = null ) { $request = $this->saferPayInitialize->buildRequest( $paymentMethod, @@ -204,7 +208,8 @@ private function processInitializePayment( $selectedCard, $fieldToken, $successController, - $isWebhook + $isWebhook, + $cartTotal ); return $this->saferPayInitialize->initialize($request, $isBusinessLicense); diff --git a/src/Service/Request/InitializeRequestObjectCreator.php b/src/Service/Request/InitializeRequestObjectCreator.php index 4278d9ed8..5abb8db55 100755 --- a/src/Service/Request/InitializeRequestObjectCreator.php +++ b/src/Service/Request/InitializeRequestObjectCreator.php @@ -57,14 +57,17 @@ public function create( $customerId, $isBusinessLicence, $alias = null, - $fieldToken = null + $fieldToken = null, + $cartTotal = null ) { $requestHeader = $this->requestObjectCreator->createRequestHeader(); $terminalId = Configuration::get(SaferPayConfig::TERMINAL_ID . SaferPayConfig::getConfigSuffix()); - $cartDetails = $cart->getSummaryDetails(); - $totalPrice = $cartDetails['total_price'] * SaferPayConfig::AMOUNT_MULTIPLIER_FOR_API; - $totalPrice = (int) (round($totalPrice)); + $totalPrice = $cartTotal; + if ($cartTotal === null) { + $cartDetails = $cart->getSummaryDetails(); + $totalPrice = (int) round($cartDetails['total_price'] * SaferPayConfig::AMOUNT_MULTIPLIER_FOR_API); + } $payment = $this->requestObjectCreator->createPayment($cart, $totalPrice); $payer = new Payer(); diff --git a/src/Service/SaferPayInitialize.php b/src/Service/SaferPayInitialize.php index 4e4befa11..cdc5ca9fd 100755 --- a/src/Service/SaferPayInitialize.php +++ b/src/Service/SaferPayInitialize.php @@ -111,7 +111,8 @@ public function buildRequest( $selectedCard = -1, $fieldToken = null, $successController = null, - $isWebhook = 1 + $isWebhook = 1, + $cartTotal = null ) { $customerEmail = $this->context->customer->email; $cartId = $this->context->cart->id; @@ -155,7 +156,8 @@ public function buildRequest( $this->context->cart->id_customer, $isBusinessLicence, $alias, - $fieldToken + $fieldToken, + $cartTotal ); return $initializeRequest;