// change status to refunded.
self::updateContributionStatus($contribution['id'], 'Refunded');
}
+ self::updateRelatedContribution($params, $params['contribution_id']);
CRM_Contribute_BAO_Contribution::recordPaymentActivity($params['contribution_id'], CRM_Utils_Array::value('participant_id', $params), $params['total_amount'], $trxn->currency, $trxn->trxn_date);
return $trxn;
}
+ /**
+ * Function to update contribution's check_number and trxn_id by
+ * concatenating values from financial trxn's check_number and trxn_id respectively
+ *
+ * @param array $params
+ * @param int $contributionID
+ */
+ public static function updateRelatedContribution($params, $contributionID) {
+ $contributionDAO = new CRM_Contribute_DAO_Contribution();
+ $contributionDAO->id = $contributionID;
+ $contributionDAO->find(TRUE);
+
+ foreach (['trxn_id', 'check_number'] as $fieldName) {
+ if (!empty($params[$fieldName])) {
+ $values = [];
+ if (!empty($contributionDAO->$fieldName)) {
+ $values = explode(',', $contributionDAO->$fieldName);
+ }
+ // if submitted check_number or trxn_id value is
+ // already present then ignore else add to $values array
+ if (!in_array($params[$fieldName], $values)) {
+ $values[] = $params[$fieldName];
+ }
+ $contributionDAO->$fieldName = implode(',', $values);
+ }
+ }
+
+ $contributionDAO->save();
+ }
+
/**
* Send an email confirming a payment that has been received.
*
civicrm_api3('FinancialTrxn', 'create', $submittedValues);
}
- self::updateRelatedContribution($submittedValues, $this->_contributionID);
+ CRM_Financial_BAO_Payment::updateRelatedContribution($submittedValues, $this->_contributionID);
}
/**
$this->submit($params);
}
- /**
- * Function to update contribution's check_number and trxn_id by
- * concatenating values from financial trxn's check_number and trxn_id respectively
- *
- * @param array $params
- * @param int $contributionID
- */
- public static function updateRelatedContribution($params, $contributionID) {
- $contributionDAO = new CRM_Contribute_DAO_Contribution();
- $contributionDAO->id = $contributionID;
- $contributionDAO->find(TRUE);
-
- foreach (['trxn_id', 'check_number'] as $fieldName) {
- if (!empty($params[$fieldName])) {
- if (!empty($contributionDAO->$fieldName)) {
- $values = explode(',', $contributionDAO->$fieldName);
- // if submitted check_number or trxn_id value is
- // already present then ignore else add to $values array
- if (!in_array($params[$fieldName], $values)) {
- $values[] = $params[$fieldName];
- }
- $contributionDAO->$fieldName = implode(',', $values);
- }
- }
- }
-
- $contributionDAO->save();
- }
-
/**
* Get payment fields
*/
'contribution_status_id' => 2,
];
$contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
+ $checkNumber1 = 'C111';
$this->callAPISuccess('Payment', 'create', [
'contribution_id' => $contribution['id'],
'total_amount' => 50,
- 'payment_instrument_id' => 'Cash',
+ 'payment_instrument_id' => 'Check',
+ 'check_number' => $checkNumber1,
]);
$payments = $this->callAPISuccess('Payment', 'get', ['contribution_id' => $contribution['id']])['values'];
$this->assertCount(1, $payments);
$this->validateAllPayments();
+
+ $checkNumber2 = 'C222';
+ $this->callAPISuccess('Payment', 'create', [
+ 'contribution_id' => $contribution['id'],
+ 'total_amount' => 20,
+ 'payment_instrument_id' => 'Check',
+ 'check_number' => $checkNumber2,
+ ]);
+ $expectedConcatanatedCheckNumbers = implode(',', [$checkNumber1, $checkNumber2]);
+ //Assert check number is concatenated on the main contribution.
+ $contributionValues = $this->callAPISuccess('Contribution', 'getsingle', ['id' => $contribution['id']]);
+ $this->assertEquals($expectedConcatanatedCheckNumbers, $contributionValues['check_number']);
}
/**