From fb3b1f9a776032fd743521bd6359f86fa85aaecf Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 28 Nov 2014 11:56:10 +0000 Subject: [PATCH] CRM 14512 provide line items of all participants to payment gateway --- CRM/Event/Form/Registration/Confirm.php | 74 +++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/CRM/Event/Form/Registration/Confirm.php b/CRM/Event/Form/Registration/Confirm.php index 41be900951..a057480bc1 100644 --- a/CRM/Event/Form/Registration/Confirm.php +++ b/CRM/Event/Form/Registration/Confirm.php @@ -765,6 +765,80 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { // do a transfer only if a monetary payment greater than 0 if ($this->_values['event']['is_monetary'] && $primaryParticipant) { if ($payment && is_object($payment)) { + + /* CRM 14512 provide line items of all participants to payment gateway *************/ + + //make note of primary contact id + $primaryContactId = $this->get('primaryContactId'); + + //build an array of cId/pId of participants + $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($registerByID, + NULL, $primaryContactId, $isTest, + TRUE + ); + + //need to copy, since we are unsetting on the way. + $copyParticipantCountLines = $participantCount; + + //lets carry all participant params w/ values. + foreach ($additionalIDs as $participantID => $contactId) { + + $participantNum = NULL; + + $participantNum = $participantID; + + if ($participantID == $registerByID) { + + $participantNum = 0; // is primary particpant + + } else { + + if ($participantNum = array_search('participant', $copyParticipantCountLines)) { + + //if no participant found break. + if ($participantNum === NULL) { + break; + } + + //unset current particpant so we don't check them again + unset($copyParticipantCountLines[$participantNum]); + //} + } + } + + // get values of line items + if ($this->_amount) { + + $amount = array(); + $amount[$participantNum]['label'] = preg_replace('//', '', $params[$participantNum]['amount_level']); + $amount[$participantNum]['amount'] = $params[$participantNum]['amount']; + $params[$participantNum]['amounts'] = $amount; + } + + if ($this->_lineItem) { + + $lineItems = $this->_lineItem; + $lineItem = array(); + + if ($lineItemValue = CRM_Utils_Array::value($participantNum, $lineItems)) { + $lineItem[] = $lineItemValue; + } + + $params[$participantNum]['lineItem'] = $lineItem; + } + + //only add additional particpants and not the primary particpant as we already have that + //added to $primaryParticipant so that this change doesn't break or require changes to existing gateway implementations + $primaryParticipant['participants_info'][$participantID] = $params[$participantNum]; + + } + + //get event custom field information + $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', $this, $this->_eventId, 0, $this->_values['event']['event_type_id']); + $primaryParticipant['eventCustomFields'] = $groupTree; + + /* END CRM 14512 */ + // call postprocess hook before leaving $this->postProcessHook(); // this does not return -- 2.25.1