Skip to content

Commit

Permalink
Modify backend Record Payment forms to use payment create API
Browse files Browse the repository at this point in the history
m
  • Loading branch information
monishdeb committed Feb 20, 2019
1 parent c40f8e1 commit 6508fd1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
29 changes: 4 additions & 25 deletions CRM/Contribute/Form/AdditionalPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,38 +336,17 @@ public function submit($submittedValues) {
if ($this->_component == 'event') {
$participantId = $this->_id;
}
$contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution',
'contribution_status_id',
array('labelColumn' => 'name')
);
$contributionStatusID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_contributionId, 'contribution_status_id');
if ($contributionStatuses[$contributionStatusID] == 'Pending') {
civicrm_api3('Contribution', 'create',
array(
'id' => $this->_contributionId,
'contribution_status_id' => array_search('Partially paid', $contributionStatuses),
'is_pay_later' => 0,
)
);
}

if ($this->_mode) {
// process credit card
$this->assign('contributeMode', 'direct');
$this->processCreditCard();
}

$defaults = array();
$contribution = civicrm_api3('Contribution', 'getsingle', array(
'return' => array("contribution_status_id"),
'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);
// Fetch the contribution & do proportional line item assignment
$params = array('id' => $this->_contributionId);
$contribution = CRM_Contribute_BAO_Contribution::retrieve($params, $defaults, $params);
CRM_Contribute_BAO_Contribution::addPayments(array($contribution), $contributionStatusId);
$payment = civicrm_api3('Payment', 'create', array_merge([
'contribution_id' => $this->_contributionId,
'total_amount' => $this->_params['total_amount'],
], $this->_params));
if ($this->_contributionId && CRM_Core_Permission::access('CiviMember')) {
$membershipPaymentCount = civicrm_api3('MembershipPayment', 'getCount', array('contribution_id' => $this->_contributionId));
if ($membershipPaymentCount) {
Expand Down
17 changes: 12 additions & 5 deletions tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,24 @@ public function testTransactionInfo() {
$submittedValues = array(
'total_amount' => 20,
'payment_instrument_id' => 3,
'contribution_id' => $contributionID,
);
CRM_Contribute_BAO_Contribution::recordAdditionalPayment($contributionID, $submittedValues, 'owed', $result['participant']['id']);

$this->callAPISuccess('payment', 'create', $submittedValues);
$priceField = $this->callAPISuccess('PriceField', 'get', [
'sequential' => 1,
'price_set_id' => $result['priceSetId'],
'html_type' => 'Text'
]);

//Change selection to a lower amount.
$params['price_2'] = 50;
CRM_Price_BAO_LineItem::changeFeeSelections($params, $result['participant']['id'], 'participant', $contributionID, $result['feeBlock'], $result['lineItem']);
$params["price_{$priceField['id']}"] = 50;
CRM_Price_BAO_LineItem::changeFeeSelections($params, $result['participant']['id'], 'participant', $contributionID, $feeBlock, $lineItem, $feeAmt);

//Record a refund of the remaining amount.
$submittedValues['total_amount'] = 50;
CRM_Contribute_BAO_Contribution::recordAdditionalPayment($contributionID, $submittedValues, 'refund', $result['participant']['id']);
$paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($result['participant']['id'], 'event', TRUE);
$this->callAPISuccess('payment', 'create', $submittedValues);
$paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($participant['id'], 'event', TRUE);
$transaction = $paymentInfo['transaction'];

//Assert all transaction(owed and refund) are listed on view payments.
Expand Down

0 comments on commit 6508fd1

Please sign in to comment.