Skip to content

Commit 4a1b4c8

Browse files
authored
Merge pull request #193 from paynl/feature/PLUG-5162
PLUG-5162 - paylink fix
2 parents 6b9aa1d + 79a2f63 commit 4a1b4c8

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

includes/classes/PPMFWC/Gateways.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use PayNL\Sdk\Model\Pay\PayOrder;
34
use PayNL\Sdk\Model\Pay\PayStatus;
45
use PayNL\Sdk\Util\Exchange;
56

@@ -1023,6 +1024,27 @@ public static function ppmfwc_getGateWayById($payment_profile_id)
10231024
return null;
10241025
}
10251026

1027+
/**
1028+
* @param string $action
1029+
* @param PayOrder $payOrder
1030+
* @param Exchange $exchange
1031+
* @return void
1032+
* @throws Exception
1033+
*/
1034+
private static function validateExchange(string $action, PayOrder $payOrder, Exchange $exchange): void
1035+
{
1036+
if ($payOrder->isPending() && $action != self::ACTION_PENDING) {
1037+
$exchange->setResponse(false, 'Unexpected action (' . $action . ') for order state pending.');
1038+
1039+
} elseif ($payOrder->isCancelled() && $action != self::ACTION_CANCEL) {
1040+
$exchange->setResponse(false, 'Unexpected action (' . $action . ') for order state cancelled.');
1041+
1042+
} elseif ($payOrder->isRefunded() && $action != self::ACTION_REFUND && $action != self::ACTION_REFUND_ADD) {
1043+
$exchange->setResponse(false, 'Unexpected action (' . $action . ') for order state refunded.');
1044+
1045+
}
1046+
}
1047+
10261048
/**
10271049
* Handles the Pay. Exchange requests
10281050
* @phpcs:ignore Squiz.Commenting.FunctionComment.MissingReturn
@@ -1042,9 +1064,7 @@ public static function ppmfwc_onExchange()
10421064
$payOrder = $exchange->process(PPMFWC_Helper_Config::getPayConfig());
10431065
$payOrderId = $payOrder->getOrderId();
10441066

1045-
if ($payOrder->isPending()) {
1046-
$exchange->setResponse(true, 'Ignoring pending.');
1047-
}
1067+
self::validateExchange($action, $payOrder, $exchange);
10481068

10491069
$order_id = $exchange->getReference();
10501070
$methodId = $payOrder->getPaymentMethod();

0 commit comments

Comments
 (0)