From bd5fc76b429dfdeed4e1211393030c3ed47b42d7 Mon Sep 17 00:00:00 2001 From: bohdan Date: Tue, 11 Apr 2023 13:09:55 +0200 Subject: [PATCH] #32835 fix after QA --- CHANGELOG.md | 3 ++ composer.json | 2 +- .../Payment/PaymentFinalizeController.php | 2 +- .../TransactionsControlController.php | 7 +++- src/MoptWorldline.php | 2 +- src/Service/PaymentHandler.php | 36 ++++++++++++++----- 6 files changed, 39 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de46cb97..ead87487 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 1.6.0 +- Auto-cancel for payment status open (0) and redirected (46) + # 1.5.0 - Order item statuses diff --git a/composer.json b/composer.json index 2063dac2..16f6f1a1 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "mediaopt/worldline", "description": "Worldline Online Payments", - "version": "1.5.0", + "version": "1.6.0", "type": "shopware-platform-plugin", "license": "proprietary", "config": { diff --git a/src/Controller/Payment/PaymentFinalizeController.php b/src/Controller/Payment/PaymentFinalizeController.php index 4fdd52cb..3b5a0ab7 100644 --- a/src/Controller/Payment/PaymentFinalizeController.php +++ b/src/Controller/Payment/PaymentFinalizeController.php @@ -95,7 +95,7 @@ public function finalizeTransaction(Request $request, SalesChannelContext $sales $this->transactionStateHandler ); - $paymentHandler->updatePaymentStatus($hostedCheckoutId); + $paymentHandler->updatePaymentStatus($hostedCheckoutId, true); $finishUrl = $this->buildFinishUrl($request, $order, $salesChannelContext, $context); diff --git a/src/Controller/TransactionsControl/TransactionsControlController.php b/src/Controller/TransactionsControl/TransactionsControlController.php index abfb4c26..930b5909 100644 --- a/src/Controller/TransactionsControl/TransactionsControlController.php +++ b/src/Controller/TransactionsControl/TransactionsControlController.php @@ -200,6 +200,11 @@ public function enableButtons(Request $request, Context $context): JsonResponse } } + $lockButtons = false; + if (array_key_exists(Form::CUSTOM_FIELD_WORLDLINE_PAYMENT_TRANSACTION_IS_LOCKED, $customFields)) { + $lockButtons = $customFields[Form::CUSTOM_FIELD_WORLDLINE_PAYMENT_TRANSACTION_IS_LOCKED]; + } + [$allowedActions, $allowedAmounts] = Payment::getAllowed($customFields); } catch (\Exception $e) { return $this->response(false, $e->getMessage()); @@ -211,7 +216,7 @@ public function enableButtons(Request $request, Context $context): JsonResponse 'allowedAmounts' => $allowedAmounts, 'log' => $log, 'worldlinePaymentStatus' => $itemsStatus, - 'worldlineLockButtons' => false, + 'worldlineLockButtons' => $lockButtons, ]); } diff --git a/src/MoptWorldline.php b/src/MoptWorldline.php index 75e566eb..9529d472 100644 --- a/src/MoptWorldline.php +++ b/src/MoptWorldline.php @@ -23,7 +23,7 @@ class MoptWorldline extends Plugin { const PLUGIN_NAME = 'MoptWorldline'; - const PLUGIN_VERSION = '1.5.0'; + const PLUGIN_VERSION = '1.6.0'; /** * @param InstallContext $installContext diff --git a/src/Service/PaymentHandler.php b/src/Service/PaymentHandler.php index 8c6cc73a..408e08b0 100644 --- a/src/Service/PaymentHandler.php +++ b/src/Service/PaymentHandler.php @@ -76,12 +76,13 @@ public function getOrderId(): string /** * @param string $hostedCheckoutId + * @param bool $isFinalize * @return int * @throws \Exception */ - public function updatePaymentStatus(string $hostedCheckoutId): int + public function updatePaymentStatus(string $hostedCheckoutId, bool $isFinalize = false): int { - $status = $this->updatePaymentTransactionStatus($hostedCheckoutId); + $status = $this->updatePaymentTransactionStatus($hostedCheckoutId, $isFinalize); $this->updateOrderTransactionState($status, $hostedCheckoutId); return $status; @@ -95,10 +96,9 @@ public function updatePaymentStatus(string $hostedCheckoutId): int */ public function createPayment(int $worldlinePaymentMethodId): CreateHostedCheckoutResponse { - $order = $this->order; $orderObject = null; if (in_array($worldlinePaymentMethodId, PaymentProducts::PAYMENT_PRODUCT_NEED_DETAILS)) { - $criteria = new Criteria([$order->getId()]); + $criteria = new Criteria([$this->order->getId()]); $criteria->addAssociation('lineItems') ->addAssociation('deliveries.positions.orderLineItem') ->addAssociation('orderCustomer.customer') @@ -111,7 +111,7 @@ public function createPayment(int $worldlinePaymentMethodId): CreateHostedChecko $orderObject = $this->orderRepository->search($criteria, $this->context)->first(); } - $amountTotal = (int)round($order->getAmountTotal() * 100); + $amountTotal = (int)round($this->order->getAmountTotal() * 100); $currencyISO = $this->getCurrencyISO(); $this->log(AdminTranslate::trans($this->translator->getLocale(), 'buildingOrder')); @@ -146,8 +146,7 @@ public function createPayment(int $worldlinePaymentMethodId): CreateHostedChecko */ public function createHostedTokenizationPayment(array $iframeData): CreatePaymentResponse { - $order = $this->order; - $amountTotal = (int)round($order->getAmountTotal() * 100); + $amountTotal = (int)round($this->order->getAmountTotal() * 100); $currencyISO = $this->getCurrencyISO(); $this->log(AdminTranslate::trans($this->translator->getLocale(), 'buildingHostdTokenizationOrder')); @@ -372,10 +371,11 @@ public function refundPayment(string $hostedCheckoutId, int $amount, array $item /** * @param string $hostedCheckoutId + * @param bool $isFinalize * @return string * @throws \Exception */ - private function updatePaymentTransactionStatus(string $hostedCheckoutId): string + private function updatePaymentTransactionStatus(string $hostedCheckoutId, bool $isFinalize = false): string { $this->log('gettingPaymentDetails', 0, ['hostedCheckoutId' => $hostedCheckoutId]); $paymentDetails = $this->adapter->getPaymentDetails($hostedCheckoutId); @@ -389,7 +389,25 @@ private function updatePaymentTransactionStatus(string $hostedCheckoutId): strin //Check log for any outer actions $this->compareLog($paymentDetails); - $this->saveOrderCustomFields($status, $hostedCheckoutId); + + //finalize for direct sales case + $autoCapture = $this->adapter->getPluginConfig(Form::AUTO_CAPTURE); + if ($isFinalize && $autoCapture == Form::AUTO_CAPTURE_IMMEDIATELY && in_array($status, Payment::STATUS_CAPTURED)) { + $amountTotal = (int)round($this->order->getAmountTotal() * 100); + $this->saveOrderCustomFields( + $status, + $hostedCheckoutId, + [ + 'toCaptureOrCancel' => 0, + 'toRefund' => $amountTotal, + ], + [], + $this->buildOrderItemStatus(true) + ); + } else { + $this->saveOrderCustomFields($status, $hostedCheckoutId); + } + return $status; }