From 3d6a264e25a8abb56efbad931f79d8b576657ed0 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 25 Feb 2019 19:35:50 +1300 Subject: [PATCH] [REF] extract activity payment. THis is likely not it's last resting place but it does make the functions involved a lot simpler now --- CRM/Contribute/BAO/Contribution.php | 46 ++++++++++++++++++----------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index d906b9fbac..89e688f6c4 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -883,6 +883,33 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { return self::$_exportableFields; } + /** + * @param $contributionId + * @param $paymentType + * @param $participantId + * + * @param $financialTrxn + */ + protected static function recordPaymentActivity($contributionId, $participantId, $financialTrxn) { + $activityType = ($financialTrxn->total_amount < 0) ? 'Refund' : 'Payment'; + if ($participantId) { + $inputParams['id'] = $participantId; + $values = []; + $ids = []; + $component = 'event'; + $entityObj = CRM_Event_BAO_Participant::getValues($inputParams, $values, $ids); + $entityObj = $entityObj[$participantId]; + } + else { + $entityObj = new CRM_Contribute_BAO_Contribution(); + $entityObj->id = $contributionId; + $entityObj->find(TRUE); + $component = 'contribution'; + } + + self::addActivityForPayment($entityObj, $financialTrxn, $activityType, $component, $contributionId); + } + /** * @inheritDoc */ @@ -3815,25 +3842,8 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac } } - // activity creation if (!empty($financialTrxn)) { - if ($participantId) { - $inputParams['id'] = $participantId; - $values = array(); - $ids = array(); - $component = 'event'; - $entityObj = CRM_Event_BAO_Participant::getValues($inputParams, $values, $ids); - $entityObj = $entityObj[$participantId]; - } - else { - $entityObj = new CRM_Contribute_BAO_Contribution(); - $entityObj->id = $contributionId; - $entityObj->find(TRUE); - $component = 'contribution'; - } - $activityType = ($paymentType == 'refund') ? 'Refund' : 'Payment'; - - self::addActivityForPayment($entityObj, $financialTrxn, $activityType, $component, $contributionId); + self::recordPaymentActivity($contributionId, $participantId, $financialTrxn); return $financialTrxn; } -- 2.25.1