Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/financial#74 Create ParticipantPayment record for every participant when registering multiple participants for event #15555

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -2504,7 +2504,7 @@ public static function getComponentDetails($contributionId) {
$componentDetails['event'] = $dao->event_id;
}
if ($dao->participant_id) {
$componentDetails['participant'] = $dao->participant_id;
$componentDetails['participant'][] = $dao->participant_id;
}
if ($dao->membership_id) {
if (!isset($componentDetails['membership'])) {
Expand Down Expand Up @@ -2881,24 +2881,22 @@ public function loadRelatedObjects(&$input, &$ids, $loadAll = FALSE) {
// make sure event exists and is valid
$event = new CRM_Event_BAO_Event();
$event->id = $ids['event'];
if ($ids['event'] &&
!$event->find(TRUE)
) {
if ($ids['event'] && !$event->find(TRUE)) {
throw new Exception("Could not find event: " . $ids['event']);
}

$this->_relatedObjects['event'] = &$event;
$this->_relatedObjects['event'] = $event;

$participant = new CRM_Event_BAO_Participant();
$participant->id = $ids['participant'];
if ($ids['participant'] &&
!$participant->find(TRUE)
) {
throw new Exception("Could not find participant: " . $ids['participant']);
}
$participant->register_date = CRM_Utils_Date::isoToMysql($participant->register_date);
foreach ($ids['participant'] ?? [] as $participantID) {
$participant = new CRM_Event_BAO_Participant();
$participant->id = $participantID;
if (!$participant->find(TRUE)) {
throw new Exception("Could not find participant: " . $participantID);
}
$participant->register_date = CRM_Utils_Date::isoToMysql($participant->register_date);

$this->_relatedObjects['participant'] = &$participant;
$this->_relatedObjects['participant'][] = $participant;
}

// get the payment processor id from event - this is inaccurate see CRM-16923
// in future we should look at throwing an exception here rather than an dubious guess.
Expand Down Expand Up @@ -3194,7 +3192,9 @@ public function _gatherMessageValues($input, &$values, $ids = []) {
}
}
else {
$values = array_merge($values, $this->loadEventMessageTemplateParams((int) $ids['event'], (int) $this->_relatedObjects['participant']->id, $this->id));
$values = array_merge($values,
$this->loadEventMessageTemplateParams((int) $ids['event'], (int) $this->_relatedObjects['participant']->id, $this->id)
);
}

$groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', NULL, $this->id);
Expand Down Expand Up @@ -4464,7 +4464,6 @@ public static function completeOrder($input, &$ids, $objects, $transaction, $con
$inputContributionWhiteList[] = 'financial_type_id';
}

$participant = CRM_Utils_Array::value('participant', $objects);
$recurContrib = CRM_Utils_Array::value('contributionRecur', $objects);
$recurringContributionID = (empty($recurContrib->id)) ? NULL : $recurContrib->id;
$event = CRM_Utils_Array::value('event', $objects);
Expand Down Expand Up @@ -4557,9 +4556,12 @@ public static function completeOrder($input, &$ids, $objects, $transaction, $con
// @todo this should be set by the function that sends the mail after sending.
$contributionParams['receipt_date'] = $changeDate;
}
$participantParams['id'] = $participant->id;
$participantParams['status_id'] = 'Registered';
civicrm_api3('Participant', 'create', $participantParams);
foreach ($objects['participant'] as $participantObject) {
// Update all related participants to registered
$participantParams['id'] = $participantObject->id;
$participantParams['status_id'] = 'Registered';
civicrm_api3('Participant', 'create', $participantParams);
}
}
}

Expand Down
14 changes: 6 additions & 8 deletions CRM/Event/Form/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -1399,14 +1399,12 @@ public function submit($params) {
}

// Insert payment record for this participant
if (empty($contributionParams['id'])) {
foreach ($this->_contactIds as $num => $contactID) {
$participantPaymentParams = [
'participant_id' => $participants[$num]->id,
'contribution_id' => $contributions[$num]->id,
];
civicrm_api3('ParticipantPayment', 'create', $participantPaymentParams);
}
foreach ($this->_contactIds as $num => $contactID) {
$participantPaymentParams = [
'participant_id' => $participants[$num]->id,
'contribution_id' => $contributions[$num]->id,
];
civicrm_api3('ParticipantPayment', 'create', $participantPaymentParams);
}

// CRM-11124
Expand Down
23 changes: 9 additions & 14 deletions CRM/Event/Form/Registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,24 +715,19 @@ public function confirmPostProcess($contactID = NULL, $contribution = NULL) {
'Participant'
);

$createPayment = (CRM_Utils_Array::value('amount', $this->_params, 0) != 0) ? TRUE : FALSE;

// force to create zero amount payment, CRM-5095
// we know the amout is zero since createPayment is false
if (!$createPayment &&
(isset($contribution) && $contribution->id) &&
$this->_priceSetId &&
$this->_lineItem
) {
$createPayment = TRUE;
if ($contribution) {
$contributionID = $contribution->id;
}
elseif (CRM_Utils_Array::value('contributionID', $this->_params)) {
$contributionID = $this->_params['contributionID'];
}

if ($createPayment && $this->_values['event']['is_monetary'] && !empty($this->_params['contributionID'])) {
$paymentParams = [
if (!empty($contributionID)) {
$participantPaymentParams = [
'participant_id' => $participant->id,
'contribution_id' => $contribution->id,
'contribution_id' => $contributionID,
];
civicrm_api3('ParticipantPayment', 'create', $paymentParams);
civicrm_api3('ParticipantPayment', 'create', $participantPaymentParams);
}

$this->assign('action', $this->_action);
Expand Down
81 changes: 81 additions & 0 deletions tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,4 +576,85 @@ public function testNoteSubmission() {
list($contact_id, $participant_id) = $this->submitWithNote($event, $contact_id);
}

/**
* Test for Multiple participant.
*/
public function testMultipleParticipant() {
$params = ['is_monetary' => 1, 'financial_type_id' => 1];
$event = $this->eventCreate($params);
CRM_Event_Form_Registration_Confirm::testSubmit([
'id' => $event['id'],
'contributeMode' => 'direct',
'registerByID' => $this->createLoggedInUser(),
'totalAmount' => 440,
'event' => reset($event['values']),
'params' => [
[
'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}",
'first_name' => 'Participant1',
'last_name' => 'LastName',
'email-Primary' => '[email protected]',
'additional_participants' => 2,
'payment_processor_id' => 0,
'bypass_payment' => '',
'MAX_FILE_SIZE' => '33554432',
'is_primary' => 1,
'is_pay_later' => 1,
'campaign_id' => NULL,
'defaultRole' => 1,
'participant_role_id' => '1',
'currencyID' => 'USD',
'amount_level' => 'Tiny-tots (ages 5-8) - 1',
'amount' => '100.00',
'tax_amount' => 10,
'ip_address' => '127.0.0.1',
'invoiceID' => '57adc34957a29171948e8643ce906332',
'trxn_id' => '123456789',
'button' => '_qf_Register_upload',
],
[
'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}",
'first_name' => 'Participant2',
'last_name' => 'LastName',
'email-Primary' => '[email protected]',
'campaign_id' => NULL,
'is_pay_later' => 1,
'participant_role_id' => '1',
'currencyID' => 'USD',
'amount_level' => 'Tiny-tots (ages 9-18) - 1',
'amount' => '200.00',
'tax_amount' => 20,
],
[
'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}",
'first_name' => 'Participant3',
'last_name' => 'LastName',
'email-Primary' => '[email protected]',
'campaign_id' => NULL,
'is_pay_later' => 1,
'participant_role_id' => '1',
'currencyID' => 'USD',
'amount_level' => 'Tiny-tots (ages 5-8) - 1',
'amount' => '100.00',
'tax_amount' => 10,
],
],
]);
$participants = $this->callAPISuccess('Participant', 'get', [])['values'];
$participantsPayment = $this->callAPISuccess('ParticipantPayment', 'get', [])['values'];

$ids_participant = array_column($participants, 'participant_id');

$ids_payment_participant = array_column($participantsPayment, 'participant_id');
if ($ids_participant == $ids_payment_participant) {
$this->assertTrue(TRUE);
}
else {
$this->assertFalse(TRUE);
}
}

}