diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 6c05ac6b7..cc3f9c0b5 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -1022,6 +1022,34 @@ public static function formRule($values, $files, $self) { $errorMsg['contribution_status_id'] = ts("Please select a valid payment status before updating."); } + if (CRM_Utils_Array::value('record_contribution', $values) && + !empty($values['trxn_id']) + ) { + $trxnId = $values['trxn_id']; + $excludeContributionId = NULL; + + // exclude that participant's own contribution from the duplicate check. + if ($self->_id && $self->_paymentId) { + $excludeContributionId = CRM_Core_DAO::getFieldValue( + 'CRM_Event_DAO_ParticipantPayment', + $self->_id, + 'contribution_id', + 'participant_id' + ); + } + + $dupQuery = "SELECT id FROM civicrm_contribution WHERE trxn_id = %1"; + $dupParams = [1 => [$trxnId, 'String']]; + if ($excludeContributionId) { + $dupQuery .= " AND id != %2"; + $dupParams[2] = [$excludeContributionId, 'Integer']; + } + $dupDao = CRM_Core_DAO::executeQuery($dupQuery, $dupParams); + if ($dupDao->fetch()) { + $errorMsg['trxn_id'] = ts('Transaction ID already exists in Database.'); + } + } + // do the amount validations. //skip for update mode since amount is freeze, CRM-6052 if ((