Skip to content

Commit

Permalink
Merge pull request #13609 from eileenmcnaughton/payment_conf
Browse files Browse the repository at this point in the history
Payment.sendconfirmation api - add further tpl variables.
  • Loading branch information
monishdeb authored Feb 19, 2019
2 parents e9a6669 + 0fad34a commit 0ca9d49
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4806,7 +4806,7 @@ public static function recordPartialPayment($contribution, $params) {
$balanceTrxnParams['from_financial_account_id'] = $fromFinancialAccountId;
$balanceTrxnParams['total_amount'] = $params['total_amount'];
$balanceTrxnParams['contribution_id'] = $params['contribution_id'];
$balanceTrxnParams['trxn_date'] = !empty($params['contribution_receive_date']) ? $params['contribution_receive_date'] : date('YmdHis');
$balanceTrxnParams['trxn_date'] = CRM_Utils_Array::value('trxn_date', $params, CRM_Utils_Array::value('contribution_receive_date', $params, date('YmdHis')));
$balanceTrxnParams['fee_amount'] = CRM_Utils_Array::value('fee_amount', $params);
$balanceTrxnParams['net_amount'] = CRM_Utils_Array::value('total_amount', $params);
$balanceTrxnParams['currency'] = $contribution['currency'];
Expand Down
30 changes: 19 additions & 11 deletions CRM/Financial/BAO/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ protected static function loadRelatedEntities($id) {
])['values'];
if (!empty($participantRecords)) {
$entities['event'] = civicrm_api3('Event', 'getsingle', ['id' => $participantRecords[0]['api.Participant.get']['values'][0]['event_id']]);
if (!empty($entities['event']['is_show_location'])) {
$locationParams = [
'entity_id' => $entities['event']['id'],
'entity_table' => 'civicrm_event',
];
$entities['location'] = CRM_Core_BAO_Location::getValues($locationParams, TRUE);
}
}

return $entities;
Expand Down Expand Up @@ -210,13 +217,14 @@ public static function getConfirmationTemplateParameters($entities) {
'totalAmount' => $entities['payment']['total'],
'amountOwed' => $entities['payment']['balance'],
'paymentAmount' => $entities['payment']['total_amount'],
'event' => NULL,
'component' => 'contribution',
'checkNumber' => CRM_Utils_Array::value('check_number', $entities['payment']),
'receive_date' => $entities['payment']['trxn_date'],
'paidBy' => CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_FinancialTrxn', 'payment_instrument_id', $entities['payment']['payment_instrument_id']),
'isShowLocation' => (!empty($entities['event']) ? $entities['event']['is_show_location'] : FALSE),
'location' => CRM_Utils_Array::value('location', $entities),
'event' => CRM_Utils_Array::value('event', $entities),
'component' => (!empty($entities['event']) ? 'event' : 'contribution'),
];
if (!empty($entities['event'])) {
$templateVariables['component'] = 'event';
$templateVariables['event'] = $entities['event'];
}

return self::filterUntestedTemplateVariables($templateVariables);
}
Expand All @@ -240,25 +248,25 @@ public static function filterUntestedTemplateVariables($params) {
'paymentAmount',
'event',
'component',
'checkNumber',
'receive_date',
'paidBy',
'isShowLocation',
'location',
];
// Need to do these before switching the form over...
$todoParams = [
'isRefund',
'totalPaid',
'refundAmount',
'paymentsComplete',
'receive_date',
'paidBy',
'checkNumber',
'contributeMode',
'isAmountzero',
'billingName',
'address',
'credit_card_type',
'credit_card_number',
'credit_card_exp_date',
'isShowLocation',
'location',
'eventEmail',
'$event.participant_role',
];
Expand Down
32 changes: 32 additions & 0 deletions tests/phpunit/api/v3/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,13 @@ public function testGetPayment() {
public function testPaymentEmailReceipt() {
$mut = new CiviMailUtils($this);
list($lineItems, $contribution) = $this->createParticipantWithContribution();
$event = $this->callAPISuccess('Event', 'get', []);
$this->addLocationToEvent($event['id']);
$params = array(
'contribution_id' => $contribution['id'],
'total_amount' => 50,
'check_number' => '345',
'trxn_date' => '2018-08-13 17:57:56',
);
$payment = $this->callAPISuccess('payment', 'create', $params);
$this->checkPaymentResult($payment, [
Expand All @@ -133,6 +137,11 @@ public function testPaymentEmailReceipt() {
'This Payment Amount: $ 50.00',
'Balance Owed: $ 100.00', //150 was paid in the 1st payment.
'Event Information and Location',
'Paid By: Check',
'Check Number: 345',
'Transaction Date: August 13th, 2018 5:57 PM',
'event place',
'streety street',
));
$mut->stop();
}
Expand Down Expand Up @@ -625,4 +634,27 @@ public function testCreatePaymentPayLaterPartialPayment() {
));
}

/**
* Add a location to our event.
*
* @param int $eventID
*/
protected function addLocationToEvent($eventID) {
$addressParams = [
'name' => 'event place',
'street_address' => 'streety street',
'location_type_id' => 1,
'is_primary' => 1,
];
// api requires contact_id - perhaps incorrectly but use add to get past that.
$address = CRM_Core_BAO_Address::add($addressParams);

$location = $this->callAPISuccess('LocBlock', 'create', ['address_id' => $address->id]);
$this->callAPISuccess('Event', 'create', [
'id' => $eventID,
'loc_block_id' => $location['id'],
'is_show_location' => TRUE,
]);
}

}

0 comments on commit 0ca9d49

Please sign in to comment.