Skip to content

Commit

Permalink
Switch recordAdditionalPayment fully over to api
Browse files Browse the repository at this point in the history
Use payment.create api from recordAdditionalPayment form as
part of general consolidation
  • Loading branch information
eileenmcnaughton committed Jul 15, 2019
1 parent b66d058 commit 86ea359
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 50 deletions.
34 changes: 0 additions & 34 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -3985,40 +3985,6 @@ public static function validateFinancialType($financialTypeId, $relationName = '
return FALSE;
}

/**
* Function to record additional payment for partial and refund contributions.
*
* @param int $contributionId
* is the invoice contribution id (got created after processing participant payment).
* @param array $trxnsData
* to take user provided input of transaction details.
* @param string $paymentType
* 'owed' for purpose of recording partial payments, 'refund' for purpose of recording refund payments.
* @param int $participantId
* @param bool $updateStatus
*
* @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'];
$trxnsData['participant_id'] = $participantId;
$trxnsData['contribution_id'] = $contributionId;
return civicrm_api3('Payment', 'create', $trxnsData)['id'];
}
}

/**
* @param int $targetCid
* @param $activityType
Expand Down
23 changes: 10 additions & 13 deletions CRM/Contribute/Form/AdditionalPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,19 +356,16 @@ public function submit($submittedValues) {
$this->processCreditCard();
}

$defaults = [];
$contribution = civicrm_api3('Contribution', 'getsingle', [
'return' => ["contribution_status_id"],
'id' => $this->_contributionId,
]);
$contributionStatusId = CRM_Utils_Array::value('contribution_status_id', $contribution);
$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);
$trxnsData = $this->_params;
if ($this->_paymentType == 'refund') {
$trxnsData['total_amount'] = -$trxnsData['total_amount'];
}
$trxnsData['participant_id'] = $participantId;
$trxnsData['contribution_id'] = $this->_contributionId;
// From the
$trxnsData['is_send_contribution_notification'] = FALSE;
$paymentID = civicrm_api3('Payment', 'create', $trxnsData)['id'];

if ($this->_contributionId && CRM_Core_Permission::access('CiviMember')) {
$membershipPaymentCount = civicrm_api3('MembershipPayment', 'getCount', ['contribution_id' => $this->_contributionId]);
if ($membershipPaymentCount) {
Expand Down
4 changes: 1 addition & 3 deletions CRM/Financial/BAO/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public static function create($params) {
);
}
else {
civicrm_api3('Contribution', 'completetransaction', ['id' => $contribution['id']]);
civicrm_api3('Contribution', 'completetransaction', ['id' => $contribution['id'], 'is_email_receipt' => $params['is_send_contribution_notification']]);
// Get the trxn
$trxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
$ftParams = ['id' => $trxnId['financialTrxnId']];
Expand Down Expand Up @@ -362,8 +362,6 @@ public static function filterUntestedTemplateVariables($params) {
* @param $updateStatus
* - deprecate this param
*
* @todo - make this protected once recordAdditionalPayment no longer calls it.
*
* @return CRM_Financial_DAO_FinancialTrxn
*/
protected static function recordRefundPayment($contributionId, $trxnData, $updateStatus) {
Expand Down
6 changes: 6 additions & 0 deletions api/v3/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ function _civicrm_api3_payment_create_spec(&$params) {
'title' => ts('Cancel Date'),
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
],
'is_send_contribution_notification' => [
'title' => ts('Send out notifications based on contribution status change?'),
'description' => ts('Most commonly this equates to emails relating to the contribution, event, etcwhen a payment completes a contribution'),
'type' => CRM_Utils_Type::T_BOOLEAN,
'api.default' => TRUE,
],
];
}

Expand Down

0 comments on commit 86ea359

Please sign in to comment.