From a580b06983ef3dcc7f44e8bc4166d41dd5e7cfd0 Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Tue, 8 Oct 2019 11:58:43 +0200 Subject: [PATCH 1/4] Make sure we create a ParticipantPayment record for each participant in an event registration --- CRM/Event/Form/Participant.php | 14 ++++++-------- CRM/Event/Form/Registration.php | 23 +++++++++-------------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 57c853c2e777..744488841467 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -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 diff --git a/CRM/Event/Form/Registration.php b/CRM/Event/Form/Registration.php index f6a19f5d8649..52aef54782e6 100644 --- a/CRM/Event/Form/Registration.php +++ b/CRM/Event/Form/Registration.php @@ -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); From 32f63457671a660c11ab72b3cbd9b9f60b753d38 Mon Sep 17 00:00:00 2001 From: sarvesh211999 Date: Fri, 18 Oct 2019 05:40:01 +0530 Subject: [PATCH 2/4] added test case for multiple paymentrecords check --- .../Event/Form/Registration/ConfirmTest.php | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php index f37ae9d2da8a..4f5c8ddc025d 100644 --- a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php +++ b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php @@ -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' => 'participant1@example.com', + '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' => 'participant2@example.com', + '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' => 'participant3@example.com', + '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); + } + } + } From b95bd23b8b9eaba8500d0e916c648e4e576e43cc Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Wed, 30 Oct 2019 14:21:35 +0000 Subject: [PATCH 3/4] Fix getComponentDetails to return all participant IDs, not just the last one --- CRM/Contribute/BAO/Contribution.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 3b23775878b1..078cb52ec26c 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -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'])) { From d67809b04a615db2718aeb3ff6e3dcf6212761bc Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Thu, 14 Nov 2019 14:28:10 +1300 Subject: [PATCH 4/4] Further work to convert participant emails to multiple --- CRM/Contribute/BAO/Contribution.php | 38 +++++++++++++++-------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 078cb52ec26c..85042f39c19c 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -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. @@ -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); @@ -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); @@ -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); + } } }