diff --git a/payrexx/config.xml b/payrexx/config.xml index 08ee27d..fe21013 100644 --- a/payrexx/config.xml +++ b/payrexx/config.xml @@ -2,7 +2,7 @@ payrexx - + diff --git a/payrexx/controllers/front/gateway.php b/payrexx/controllers/front/gateway.php index 4b5b6c7..f068d77 100644 --- a/payrexx/controllers/front/gateway.php +++ b/payrexx/controllers/front/gateway.php @@ -5,7 +5,7 @@ * needs please refer to http://www.prestashop.com for more information. * * @author Payrexx - * @copyright 2023 Payrexx + * @copyright 2024 Payrexx * @license MIT License */ if (!defined('_PS_VERSION_')) { @@ -19,7 +19,24 @@ class PayrexxGatewayModuleFrontController extends ModuleFrontController { - public function initContent() + /** + * Process post values. + */ + public function postProcess() + { + try { + $this->processWebhook(); + echo 'Webhook processed successfully'; + } catch (Exception $e) { + echo 'Webhook Error: ' . $e->getMessage(); + } + exit; // Avoid template load error. + } + + /** + * Process webhook values + */ + private function processWebhook() { if (version_compare(_PS_VERSION_, '1.7.6', '<')) { $payrexxOrderService = new PayrexxOrderService(); @@ -35,11 +52,11 @@ public function initContent() $order = Order::getByCartId($cartId); if (!$this->validRequest($transaction, $cartId, $requestStatus)) { - exit; + return; } if (!$prestaStatus = $payrexxOrderService->getPrestaStatusByPayrexxStatus($requestStatus)) { - exit; + return; } $pm = $payrexxDbService->getPaymentMethodByCartId($cartId); @@ -56,18 +73,17 @@ public function initContent() 'transaction_id' => $transaction['id'], ] ); - exit; + return; } if ($order->module !== $this->module->name) { - exit; + return; } // Update status if transition allowed if ($order && $payrexxOrderService->transitionAllowed($prestaStatus, $order->current_state)) { $payrexxOrderService->updateOrderStatus($prestaStatus, $order); } - exit; } private function validRequest($transaction, $cartId, $requestStatus): bool diff --git a/payrexx/payrexx.php b/payrexx/payrexx.php index 32bbd49..d975d09 100644 --- a/payrexx/payrexx.php +++ b/payrexx/payrexx.php @@ -31,7 +31,7 @@ public function __construct() $this->name = 'payrexx'; $this->tab = 'payments_gateways'; $this->module_key = '0c4dbfccbd85dd948fd9a13d5a4add90'; - $this->version = '1.5.1'; + $this->version = '1.5.2'; $this->author = 'Payrexx'; $this->is_eu_compatible = 1; $this->ps_versions_compliancy = ['min' => '1.7']; diff --git a/payrexx/src/Service/PayrexxOrderService.php b/payrexx/src/Service/PayrexxOrderService.php index 6dab6ca..8c983c6 100644 --- a/payrexx/src/Service/PayrexxOrderService.php +++ b/payrexx/src/Service/PayrexxOrderService.php @@ -27,6 +27,12 @@ class PayrexxOrderService // ID 10 const PS_STATUS_BANKWIRE = 'PS_OS_BANKWIRE'; + // ID 4 + const PS_STATUS_SHIPPING = 'PS_OS_SHIPPING'; + + // ID 5 + const PS_STATUS_DELIVERED = 'PS_OS_DELIVERED'; + /** * @param $cartId * @param $prestaStatus @@ -98,16 +104,33 @@ public function getPrestaStatusByPayrexxStatus($transactionStatus) */ public function transitionAllowed($newStatus, $oldStatusId) { + $refundStatusId = (int) \Configuration::get(self::PS_STATUS_REFUND); + $newStatusId = (int) \Configuration::get($newStatus); + if ($oldStatusId === $newStatusId && $newStatusId !== $refundStatusId) { + return false; + } + $orderFinalStatuses = [ + (int) \Configuration::get(self::PS_STATUS_REFUND), + (int) \Configuration::get(self::PS_STATUS_PAYMENT), + (int) \Configuration::get(self::PS_STATUS_SHIPPING), + (int) \Configuration::get(self::PS_STATUS_DELIVERED), + ]; + switch ($newStatus) { case self::PS_STATUS_ERROR: - return !in_array($oldStatusId, [(int) \Configuration::get(self::PS_STATUS_PAYMENT), (int) \Configuration::get(self::PS_STATUS_REFUND)]); - case self::PS_STATUS_REFUND: - return in_array($oldStatusId, [(int) \Configuration::get(self::PS_STATUS_PAYMENT), (int) \Configuration::get(self::PS_STATUS_REFUND)]); case self::PS_STATUS_PAYMENT: - return $oldStatusId !== (int) \Configuration::get(self::PS_STATUS_PAYMENT); case self::PS_STATUS_BANKWIRE: - return $oldStatusId !== (int) \Configuration::get(self::PS_STATUS_BANKWIRE); + return !in_array($oldStatusId, $orderFinalStatuses); + case self::PS_STATUS_REFUND: + return in_array( + $oldStatusId, + [ + (int) \Configuration::get(self::PS_STATUS_PAYMENT), + (int) \Configuration::get(self::PS_STATUS_REFUND), + ] + ); } + return false; } /**