Skip to content

Commit

Permalink
Merge pull request #32 from payrexx/bugfix/PP-12929
Browse files Browse the repository at this point in the history
bugfix/PP-12929: Webhooks for Confirmed Transactions Should Not Be Sent After 60 Days.
  • Loading branch information
vinothss4u authored Nov 6, 2024
2 parents b923a1f + fe2a34d commit f30714a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 14 deletions.
2 changes: 1 addition & 1 deletion payrexx/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>payrexx</name>
<displayName><![CDATA[Payrexx]]></displayName>
<version><![CDATA[1.5.1]]></version>
<version><![CDATA[1.5.2]]></version>
<description><![CDATA[Accept payments using Payrexx Payment gateway]]></description>
<author><![CDATA[Payrexx]]></author>
<tab><![CDATA[payments_gateways]]></tab>
Expand Down
30 changes: 23 additions & 7 deletions payrexx/controllers/front/gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* needs please refer to http://www.prestashop.com for more information.
*
* @author Payrexx <[email protected]>
* @copyright 2023 Payrexx
* @copyright 2024 Payrexx
* @license MIT License
*/
if (!defined('_PS_VERSION_')) {
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion payrexx/payrexx.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
33 changes: 28 additions & 5 deletions payrexx/src/Service/PayrexxOrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit f30714a

Please sign in to comment.