From c88d1ec7111e3613f38066dc0ea96d705e536924 Mon Sep 17 00:00:00 2001 From: kGablo Date: Mon, 22 Jan 2024 11:32:11 +0100 Subject: [PATCH] Direct fix --- Controller/tpay/Create.php | 3 ++ .../Transaction/TransactionApiFacade.php | 28 +++++++++++++++++++ Model/Tpay.php | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Controller/tpay/Create.php b/Controller/tpay/Create.php index 392c321..c9320e3 100644 --- a/Controller/tpay/Create.php +++ b/Controller/tpay/Create.php @@ -139,6 +139,9 @@ private function prepareTransaction($orderId, array $additionalPaymentInformatio } } + $data = $this->transaction->originApiFieldCorrect($data); + $data = $this->transaction->translateGroupToChannel($data, $this->tpay->redirectToChannel()); + if (isset($data['channel']) && $data['channel']) { return $this->transaction->createWithInstantRedirection($data); } diff --git a/Model/ApiFacade/Transaction/TransactionApiFacade.php b/Model/ApiFacade/Transaction/TransactionApiFacade.php index 620d521..99d4e2f 100755 --- a/Model/ApiFacade/Transaction/TransactionApiFacade.php +++ b/Model/ApiFacade/Transaction/TransactionApiFacade.php @@ -79,6 +79,34 @@ public function channels(): array return $channels; } + public function translateGroupToChannel(array $data, bool $redirectToChannel): array + { + if ($redirectToChannel && $this->useOpenApi && $data['group'] && !$data['channel']) { + foreach ($this->openApi->channels() as $channel) { + $group = $channel->groups[0]; + if ($group['id'] == $data['group']) { + $data['channel'] = $channel->id; + $data['group'] = null; + + return $data; + } + } + } + + return $data; + } + + public function originApiFieldCorrect(array $data): array + { + if (!$this->isOpenApiUse() && (int) $data['group'] != TransactionOriginApi::BLIK_CHANNEL) { + unset($data['channel']); + unset($data['currency']); + unset($data['language']); + } + + return $data; + } + private function getCurrentApi() { return $this->useOpenApi ? $this->openApi : $this->originApi; diff --git a/Model/Tpay.php b/Model/Tpay.php index b0fc16d..7d9ee55 100755 --- a/Model/Tpay.php +++ b/Model/Tpay.php @@ -236,7 +236,7 @@ public function onlyOnlineChannels(): bool public function redirectToChannel(): bool { - return true; + return (bool) $this->getConfigData('general_settings/redirect_directly_to_channel'); } public function setTitle(string $title): void