From 80973fc07b469b9e652002dff76530a5651cd3e2 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 25 Apr 2024 10:14:59 +0200 Subject: [PATCH] Increment id fix --- Model/Resolver/CreateTransaction.php | 25 ++++++++----------- Plugin/UrlOverride.php | 37 ++++++++++++++++++++++++++++ etc/adminhtml/system.xml | 31 +++++++++++++++++++++++ etc/di.xml | 7 ++++++ 4 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 Plugin/UrlOverride.php create mode 100644 etc/adminhtml/system.xml create mode 100644 etc/di.xml diff --git a/Model/Resolver/CreateTransaction.php b/Model/Resolver/CreateTransaction.php index d5da582..45c4948 100644 --- a/Model/Resolver/CreateTransaction.php +++ b/Model/Resolver/CreateTransaction.php @@ -51,26 +51,21 @@ public function resolve(Field $field, $context, ResolveInfo $info, ?array $value return null; } - $args = $args['input'] ?? []; - - if (!empty($args['real_order_id'])) { - $orderId = $args['real_order_id']; - } else { - if (!isset($value['order_number'])) { - return null; - } + if (!isset($value['order_number'])) { + return null; + } - $orderId = $this->checkoutSession->getLastRealOrderId(); + $orderId = $this->checkoutSession->getLastOrderId(); - if (!$orderId) { - return null; - } + if (!$orderId) { + return null; } try { - $order = $this->orderRepository->getByIncrementId($orderId); + $order = $this->orderRepository->get($orderId); /** @var Payment $payment */ $payment = $order->getPayment(); + if (TpayInterface::CODE !== $payment->getMethod()) { return null; } @@ -88,13 +83,13 @@ public function resolve(Field $field, $context, ResolveInfo $info, ?array $value if (isset($transaction['transactionId'])) { $paymentData['additional_information']['transaction_id'] = $transaction['transactionId']; } - $this->tpayService->addCommentToHistory($orderId, 'Transaction title '.$transaction['title']); + $this->tpayService->addCommentToHistory($order->getIncrementId(), 'Transaction title '.$transaction['title']); if (true === $this->tpayConfig->redirectToChannel()) { $transactionUrl = str_replace('gtitle', 'title', $transactionUrl); } - $this->tpayService->addCommentToHistory($orderId, 'Transaction link '.$transactionUrl); + $this->tpayService->addCommentToHistory($order->getIncrementId(), 'Transaction link '.$transactionUrl); $paymentData['additional_information']['transaction_url'] = $transactionUrl; $payment->setData($paymentData); $this->tpayService->saveOrderPayment($payment); diff --git a/Plugin/UrlOverride.php b/Plugin/UrlOverride.php new file mode 100644 index 0000000..3e62ab0 --- /dev/null +++ b/Plugin/UrlOverride.php @@ -0,0 +1,37 @@ +tpayConfig = $tpayConfig; + } + + public function afterGetTpayFormData(TpayPayment $subject, $result, $name, $storeId = 0) + { + $successUrl = $this->tpayConfig->getConfigData('graphql_url_override/success_url', $storeId); + $errorUrl = $this->tpayConfig->getConfigData('graphql_url_override/error_url', $storeId); + $notificationUrl = $this->tpayConfig->getConfigData('graphql_url_override/notification_url', $storeId); + + if(!empty($successUrl)){ + $result['return_url'] = $successUrl; + } + + if(!empty($errorUrl)){ + $result['return_error_url'] = $errorUrl; + } + + if(!empty($notificationUrl)){ + $result['result_url'] = $notificationUrl; + } + + return $result; + } +} diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml new file mode 100644 index 0000000..99d38d6 --- /dev/null +++ b/etc/adminhtml/system.xml @@ -0,0 +1,31 @@ + + + + +
+ + + + 1 + + + + + + + + + + + +
+
+
diff --git a/etc/di.xml b/etc/di.xml new file mode 100644 index 0000000..087fcb5 --- /dev/null +++ b/etc/di.xml @@ -0,0 +1,7 @@ + + + + + +