From c30cc94e799bfa1c39aa4cf82ea7b3cf0c173bdd Mon Sep 17 00:00:00 2001 From: Justin Freeman Date: Mon, 11 Jan 2021 09:36:25 +1100 Subject: [PATCH 1/2] CIVIEWAY-207 Mark pending contribution as failed when validate pending transactions exceeds retries --- CRM/eWAYRecurring/Utils.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/CRM/eWAYRecurring/Utils.php b/CRM/eWAYRecurring/Utils.php index 3e9c3d9..29926bf 100644 --- a/CRM/eWAYRecurring/Utils.php +++ b/CRM/eWAYRecurring/Utils.php @@ -23,7 +23,7 @@ public function validatePendingTransactions($params = []) { // Fetch all transactions to validate $transactionsToValidate = civicrm_api3('EwayContributionTransactions', 'get', [ 'status' => self::STATUS_IN_QUEUE, - 'tries' => ['<' => self::MAX_TRIES], + 'tries' => ['<=' => self::MAX_TRIES], 'sequential' => TRUE, ]); @@ -95,6 +95,31 @@ public function validatePendingTransactions($params = []) { $apiResponse['deleted']++; } } + + // Mark all pending transactions that have exceeded the retry limit as failed + + $transactionsPendingMaxTries = civicrm_api3('EwayContributionTransactions', 'get', [ + 'status' => self::STATUS_IN_QUEUE, + 'tries' => ['>' => self::MAX_TRIES], + 'sequential' => TRUE, + ]); + + $transactionsPendingMaxTries = $transactionsPendingMaxTries['values']; + + foreach ($transactionsPendingMaxTries as $transactionPendingMaxTries) { + $contributionId = $transactionPendingMaxTries['contribution_id']; + try { + // Mark contribution as failed + civicrm_api3('Contribution', 'create', [ + 'id' => $contributionID, + 'contribution_status_id' => 'Failed', + ]); + + } catch (CiviCRM_API3_Exception $e) { + // Contribution not found. + } + } + return $apiResponse; } From aee978747d4cb641a79c9d81d7076c17e4754a7b Mon Sep 17 00:00:00 2001 From: Justin Freeman Date: Mon, 11 Jan 2021 09:43:40 +1100 Subject: [PATCH 2/2] CIVIEWAY-207 Change greater than equal comparison and update comment --- CRM/eWAYRecurring/Utils.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CRM/eWAYRecurring/Utils.php b/CRM/eWAYRecurring/Utils.php index 29926bf..ee0e642 100644 --- a/CRM/eWAYRecurring/Utils.php +++ b/CRM/eWAYRecurring/Utils.php @@ -10,6 +10,7 @@ class CRM_eWAYRecurring_Utils { public const MAX_TRIES = 7; // Giving up after 7 tries is ~ 2h in a // run-every-15-minutes scenario. + // Counter starts from zero. /** * Validate pending transactions. @@ -23,7 +24,7 @@ public function validatePendingTransactions($params = []) { // Fetch all transactions to validate $transactionsToValidate = civicrm_api3('EwayContributionTransactions', 'get', [ 'status' => self::STATUS_IN_QUEUE, - 'tries' => ['<=' => self::MAX_TRIES], + 'tries' => ['<' => self::MAX_TRIES], 'sequential' => TRUE, ]); @@ -100,7 +101,7 @@ public function validatePendingTransactions($params = []) { $transactionsPendingMaxTries = civicrm_api3('EwayContributionTransactions', 'get', [ 'status' => self::STATUS_IN_QUEUE, - 'tries' => ['>' => self::MAX_TRIES], + 'tries' => ['>=' => self::MAX_TRIES], 'sequential' => TRUE, ]);