Skip to content

Commit

Permalink
Merge pull request #12 from agileware/CIVIEWAY-207
Browse files Browse the repository at this point in the history
Mark pending contribution as failed when validate pending transactions exceeds retries
  • Loading branch information
agileware-justin authored Jan 10, 2021
2 parents c34bb83 + aee9787 commit 4f5b589
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions CRM/eWAYRecurring/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -95,6 +96,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;

}
Expand Down

0 comments on commit 4f5b589

Please sign in to comment.