From 61cec1b5fd2ff2b9bf42d621da3b2abfe5322444 Mon Sep 17 00:00:00 2001 From: Patrick Lam Date: Sun, 14 Jan 2024 17:11:40 +1300 Subject: [PATCH] fix bug saving a new recurring contribution to the database I experienced a bug in CiviCRM 5.69.2 with the Stripe plugin from mjw. Adding a new recurring contribution (for an annual membership), CiviCRM reports the error: 2024-01-12 04:49:44-0500 [error] CRM_Contribute_Form_Contribution_Confirm::completeTransaction CRM_Core_Exception: contribution_status_id is not a valid integer and the error message "Failed to update contribution in database". I tracked this down to the code patched here in contributionRecur, which attempts to store "In Progress" as the contribution_status_id, which is indeed not a valid integer. It looks like everywhere else in the code, CiviCRM is going to do a PseudoConstant lookup to store the relevant ID. I've modified the code here to match the convention elsewhere. The patch appears to work on my own install of CiviCRM. I don't have a CiviCRM account yet. I was planning to report it on the bug tracker, but my account hasn't been approved yet. Anyway, I can report it there once I have an account. Or not, if you just merge this patch. Thanks for all the work maintaining this software! --- CRM/Contribute/BAO/ContributionRecur.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CRM/Contribute/BAO/ContributionRecur.php b/CRM/Contribute/BAO/ContributionRecur.php index df1dea9185b3..d4346795d6f4 100644 --- a/CRM/Contribute/BAO/ContributionRecur.php +++ b/CRM/Contribute/BAO/ContributionRecur.php @@ -940,7 +940,7 @@ public static function updateOnNewPayment($recurringContributionID, $paymentStat if ($paymentStatus == 'Completed' && CRM_Contribute_PseudoConstant::contributionStatus($existing['contribution_status_id'], 'name') == 'Pending') { - $params['contribution_status_id'] = 'In Progress'; + $params['contribution_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'In Progress'); } if ($paymentStatus == 'Failed') { $params['failure_count'] = $existing['failure_count']; @@ -948,7 +948,7 @@ public static function updateOnNewPayment($recurringContributionID, $paymentStat $params['modified_date'] = date('Y-m-d H:i:s'); if (!empty($existing['installments']) && self::isComplete($recurringContributionID, $existing['installments'])) { - $params['contribution_status_id'] = 'Completed'; + $params['contribution_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'); $params['next_sched_contribution_date'] = 'null'; $params['end_date'] = 'now'; }