This is in conjunction with a series of changes consolidating & adding testing for creating payments with the goal
being that the logic is all in the Payment.create api/BAO & none of the logic remains in the CRM_Contribute_Form_AdditionalPayment form
This change completes switching the refund action over. There is logic in there to update the Participant status to
Registered when a refund is processed - seemingly regardless of what it's original status is or the appropriate status
afterwards.
I tested through the UI and if you create a participant record & then change the line items, thus reducing the cost
and changing the contribution status to 'Pending Refund' the participant status remains 'Completed' so I think
this was not working / not required already & I simply dropped it
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
- protected static function recordPaymentActivity($contributionId, $participantId, $totalAmount, $currency, $trxnDate) {
+ public static function recordPaymentActivity($contributionId, $participantId, $totalAmount, $currency, $trxnDate) {
$activityType = ($totalAmount < 0) ? 'Refund' : 'Payment';
if ($participantId) {
* @param int $participantId
* @param bool $updateStatus
*
- * @return null|object
+ * @return int
+ *
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
public static function recordAdditionalPayment($contributionId, $trxnsData, $paymentType = 'owed', $participantId = NULL, $updateStatus = TRUE) {
if ($paymentType == 'owed') {
$financialTrxn = CRM_Financial_BAO_Payment::recordPayment($contributionId, $trxnsData, $participantId);
+ if (!empty($financialTrxn)) {
+ self::recordPaymentActivity($contributionId, $participantId, $financialTrxn->total_amount, $financialTrxn->currency, $financialTrxn->trxn_date);
+ return $financialTrxn->id;
+ }
}
elseif ($paymentType == 'refund') {
$trxnsData['total_amount'] = -$trxnsData['total_amount'];
- $financialTrxn = CRM_Financial_BAO_Payment::recordRefundPayment($contributionId, $trxnsData, $updateStatus);
- if ($participantId) {
- // update participant status
- // @todo this doesn't make sense...
- $participantStatuses = CRM_Event_PseudoConstant::participantStatus();
- $ids = CRM_Event_BAO_Participant::getParticipantIds($contributionId);
- foreach ($ids as $val) {
- $participantUpdate['id'] = $val;
- $participantUpdate['status_id'] = array_search('Registered', $participantStatuses);
- CRM_Event_BAO_Participant::add($participantUpdate);
- }
- }
+ $trxnsData['participant_id'] = $participantId;
+ return civicrm_api3('Payment', 'create', $trxnsData)['id'];
}
-
- if (!empty($financialTrxn)) {
- self::recordPaymentActivity($contributionId, $participantId, $financialTrxn->total_amount, $financialTrxn->currency, $financialTrxn->trxn_date);
- return $financialTrxn;
- }
-
}
/**
'id' => $this->_contributionId,
]);
$contributionStatusId = CRM_Utils_Array::value('contribution_status_id', $contribution);
- $result = CRM_Contribute_BAO_Contribution::recordAdditionalPayment($this->_contributionId, $this->_params, $this->_paymentType, $participantId);
+ $paymentID = CRM_Contribute_BAO_Contribution::recordAdditionalPayment($this->_contributionId, $this->_params, $this->_paymentType, $participantId);
// Fetch the contribution & do proportional line item assignment
$params = ['id' => $this->_contributionId];
$contribution = CRM_Contribute_BAO_Contribution::retrieve($params, $defaults, $params);
+ // @todo - this line needs to be moved to the Payment.create api - it's not form layer appropriate.
+ // testing required.
CRM_Contribute_BAO_Contribution::addPayments([$contribution], $contributionStatusId);
if ($this->_contributionId && CRM_Core_Permission::access('CiviMember')) {
$membershipPaymentCount = civicrm_api3('MembershipPayment', 'getCount', ['contribution_id' => $this->_contributionId]);
$statusMsg = ts('The payment record has been processed.');
// send email
- if (!empty($result) && !empty($this->_params['is_email_receipt'])) {
- $sendResult = civicrm_api3('Payment', 'sendconfirmation', ['id' => $result->id])['values'][$result->id];
+ if (!empty($paymentID) && !empty($this->_params['is_email_receipt'])) {
+ $sendResult = civicrm_api3('Payment', 'sendconfirmation', ['id' => $paymentID])['values'][$paymentID];
if ($sendResult['is_sent']) {
$statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.');
}
}
elseif ($params['total_amount'] < 0) {
$trxn = self::recordRefundPayment($params['contribution_id'], $params, FALSE);
+ CRM_Contribute_BAO_Contribution::recordPaymentActivity($params['contribution_id'], CRM_Utils_Array::value('participant_id', $params), $params['total_amount'], $trxn->currency, $trxn->trxn_date);
}
if ($isPaymentCompletesContribution) {
*
* @return CRM_Financial_DAO_FinancialTrxn
*/
- public static function recordRefundPayment($contributionId, $trxnData, $updateStatus) {
+ protected static function recordRefundPayment($contributionId, $trxnData, $updateStatus) {
list($contributionDAO, $params) = self::getContributionAndParamsInFormatForRecordFinancialTransaction($contributionId);
$params['payment_instrument_id'] = CRM_Utils_Array::value('payment_instrument_id', $trxnData, CRM_Utils_Array::value('payment_instrument_id', $params));