*
*/
public static function transitionComponents($params) {
- $contributionStatus = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $params['contribution_status_id']);
- $previousStatus = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $params['previous_contribution_status_id']);
// @todo fix the one place that calls this function to use Payment.create
// remove this.
// get minimum required values.
$contributionId = $params['contribution_id'];
- $contributionStatusId = $params['contribution_status_id'];
// we process only ( Completed, Cancelled, or Failed ) contributions.
- if (!$contributionId || $contributionStatus !== 'Completed') {
+ if (!$contributionId) {
return;
}
);
}
- // only pending contribution related object processed.
- if (!in_array($previousStatus, ['Pending', 'Partially paid'])) {
- // this is case when we already processed contribution object.
- return;
- }
-
if (is_array($memberships)) {
foreach ($memberships as $membership) {
if ($membership) {
}
if ($pledgePayment) {
- CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeID, $pledgePaymentIDs, $contributionStatusId);
+ CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeID, $pledgePaymentIDs, CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'));
}
}
}
$contribution = CRM_Contribute_BAO_Contribution::create($params);
+ $previousStatus = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $this->_values['contribution_status_id'] ?? NULL);
// process associated membership / participant, CRM-4395
- if ($contribution->id && $action & CRM_Core_Action::UPDATE) {
+ if ($contribution->id && $action & CRM_Core_Action::UPDATE
+ && in_array($previousStatus, ['Pending', 'Partially paid'], TRUE)
+ && 'Completed' === CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $this->getSubmittedValue('contribution_status_id'))) {
// @todo use Payment.create to do this, remove transitioncomponents function
// if contribution is being created with a completed status it should be
// created pending & then Payment.create adds the payment
CRM_Contribute_BAO_Contribution::transitionComponents([
'contribution_id' => $contribution->id,
- 'contribution_status_id' => $contribution->contribution_status_id,
- 'previous_contribution_status_id' => $this->_values['contribution_status_id'] ?? NULL,
'receive_date' => $contribution->receive_date,
]);
}
$contribution = civicrm_api3('Contribution', 'create', $value);
$contribution = $contribution['values'][$contributionID];
- // @todo add check as to whether the status is updated.
- if (!empty($value['contribution_status_id'])) {
+ $currentStatus = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $value['contribution_status_id'] ?? NULL);
+ $previousStatus = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $this->_defaultValues["field[{$contributionID}][contribution_status_id]"] ?? NULL);
+
+ if ('Completed' === $currentStatus &&
+ in_array($previousStatus, ['Pending', 'Partially paid'], TRUE)) {
// @todo - use completeorder api or make api call do this.
CRM_Contribute_BAO_Contribution::transitionComponents([
'contribution_id' => $contribution['id'],
- 'contribution_status_id' => $value['contribution_status_id'],
- 'previous_contribution_status_id' => CRM_Utils_Array::value("field[{$contributionID}][contribution_status_id]", $this->_defaultValues),
'receive_date' => $contribution['receive_date'],
]);
}