}
/**
- * @param $contributionId
- * @param $participantId
- * @param array $financialTrxn
+ * Record an activity when a payment is received.
+ *
+ * @todo this is intended to be moved to payment BAO class as a protected function
+ * on that class. Currently being cleaned up. The addActivityForPayment doesn't really
+ * merit it's own function as it makes the code less rather than more readable.
+ *
+ * @param int $contributionId
+ * @param int $participantId
+ * @param string $totalAmount
+ * @param string $currency
+ * @param string $trxnDate
*
- * @param $financialTrxn
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- protected static function recordPaymentActivity($contributionId, $participantId, $financialTrxn) {
- $activityType = ($financialTrxn->total_amount < 0) ? 'Refund' : 'Payment';
+ protected static function recordPaymentActivity($contributionId, $participantId, $totalAmount, $currency, $trxnDate) {
+ $activityType = ($totalAmount < 0) ? 'Refund' : 'Payment';
+
if ($participantId) {
$inputParams['id'] = $participantId;
$values = [];
$entityObj->find(TRUE);
$title = ts('Contribution');
}
-
- self::addActivityForPayment($entityObj->contact_id, $financialTrxn, $activityType, $title, $contributionId);
+ // @todo per block above this is not a logical splitting off of functionality.
+ self::addActivityForPayment($entityObj->contact_id, $activityType, $title, $contributionId, $totalAmount, $currency, $trxnDate);
}
/**
}
if (!empty($financialTrxn)) {
- self::recordPaymentActivity($contributionId, $participantId, $financialTrxn);
+ self::recordPaymentActivity($contributionId, $participantId, $financialTrxn->total_amount, $financialTrxn->currency, $financialTrxn->trxn_date);
return $financialTrxn;
}
/**
* @param int $targetCid
- * @param $trxnObj
* @param $activityType
* @param string $title
* @param int $contributionId
+ * @param string $totalAmount
+ * @param string $currency
+ * @param string $trxn_date
*
- * @throws CRM_Core_Exception
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- public static function addActivityForPayment($targetCid, $trxnObj, $activityType, $title, $contributionId) {
- $paymentAmount = CRM_Utils_Money::format($trxnObj->total_amount, $trxnObj->currency);
+ public static function addActivityForPayment($targetCid, $activityType, $title, $contributionId, $totalAmount, $currency, $trxn_date) {
+ $paymentAmount = CRM_Utils_Money::format($totalAmount, $currency);
$subject = "{$paymentAmount} - Offline {$activityType} for {$title}";
- $date = CRM_Utils_Date::isoToMysql($trxnObj->trxn_date);
+ $date = CRM_Utils_Date::isoToMysql($trxn_date);
// source record id would be the contribution id
$srcRecId = $contributionId;
$activityParams['source_contact_id'] = $id;
$activityParams['target_contact_id'][] = $targetCid;
}
- // @todo use api.
- CRM_Activity_BAO_Activity::create($activityParams);
+ civicrm_api3('Activity', 'create', $activityParams);
}
/**
/**
* Test the submit function that completes the partially paid Contribution with multiple payments.
*/
- public function testMultiplePaymentForPartialyPaidContribution() {
+ public function testMultiplePaymentForPartiallyPaidContribution() {
$this->createContribution('Partially paid');
// pay additional amount
'activity_type_id' => 'Payment',
'options' => ['sort' => 'id'],
'sequential' => 1,
+ 'return' => ['target_contact_id', 'assignee_contact_id', 'subject'],
])['values'];
$this->assertEquals(2, count($activities));
$this->assertEquals('$ 50.00 - Offline Payment for Contribution', $activities[0]['subject']);
$this->assertEquals('$ 20.00 - Offline Payment for Contribution', $activities[1]['subject']);
+ $this->assertEquals(CRM_Core_Session::singleton()->getLoggedInContactID(), $activities[0]['source_contact_id']);
+ $this->assertEquals([$this->_individualId], $activities[0]['target_contact_id']);
+ $this->assertEquals([], $activities[0]['assignee_contact_id']);
}
/**