Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payment.sendconfirmation api - add further tpl variables. #13610

Merged
merged 4 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions CRM/Financial/BAO/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public static function getConfirmationTemplateParameters($entities) {
'contactDisplayName' => $entities['contact']['display_name'],
'totalAmount' => $entities['payment']['total'],
'amountOwed' => $entities['payment']['balance'],
'totalPaid' => $entities['payment']['paid'],
'paymentAmount' => $entities['payment']['total_amount'],
'checkNumber' => CRM_Utils_Array::value('check_number', $entities['payment']),
'receive_date' => $entities['payment']['trxn_date'],
Expand All @@ -224,6 +225,10 @@ public static function getConfirmationTemplateParameters($entities) {
'location' => CRM_Utils_Array::value('location', $entities),
'event' => CRM_Utils_Array::value('event', $entities),
'component' => (!empty($entities['event']) ? 'event' : 'contribution'),
'isRefund' => $entities['payment']['total_amount'] < 0,
'isAmountzero' => $entities['payment']['total_amount'] === 0,
'refundAmount' => ($entities['payment']['total_amount'] < 0 ? $entities['payment']['total_amount'] : NULL),
'paymentsComplete' => ($entities['payment']['balance'] == 0),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-)

];

return self::filterUntestedTemplateVariables($templateVariables);
Expand Down Expand Up @@ -253,22 +258,23 @@ public static function filterUntestedTemplateVariables($params) {
'paidBy',
'isShowLocation',
'location',
];
// Need to do these before switching the form over...
$todoParams = [
'isRefund',
'totalPaid',
'isAmountzero',
'refundAmount',
'totalPaid',
'paymentsComplete',
];
// These are assigned by the payment form - they still 'get through' from the
// form for now without being in here but we should ideally load
// and assign. Note we should update the tpl to use {if $billingName}
// and ditch contributeMode - although it might need to be deprecated rather than removed.
$todoParams = [
'contributeMode',
'isAmountzero',
'billingName',
'address',
'credit_card_type',
'credit_card_number',
'credit_card_exp_date',
'eventEmail',
'$event.participant_role',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton should we remove these two event parameters (as an indicator)? I didn't found any occurrence in form where its been assigned

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@monishdeb so that was my list of things to add to meet the tpl's requirements but when I reviewed the tpl I decided they were derived parameters (with the tpl) not assigned parameters

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I see

];
$filteredParams = [];
foreach ($testedTemplateVariables as $templateVariable) {
Expand Down
83 changes: 81 additions & 2 deletions tests/phpunit/api/v3/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ public function testPaymentEmailReceipt() {
list($lineItems, $contribution) = $this->createParticipantWithContribution();
$event = $this->callAPISuccess('Event', 'get', []);
$this->addLocationToEvent($event['id']);
$params = array(
$params = [
'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, [
$payment['id'] => [
Expand All @@ -144,6 +144,85 @@ public function testPaymentEmailReceipt() {
'streety street',
));
$mut->stop();
$mut->clearMessages();
}

/**
* Test email receipt for partial payment.
*/
public function testPaymentEmailReceiptFullyPaid() {
$mut = new CiviMailUtils($this);
list($lineItems, $contribution) = $this->createParticipantWithContribution();

$params = [
'contribution_id' => $contribution['id'],
'total_amount' => 150,
];
$payment = $this->callAPISuccess('payment', 'create', $params);

$this->callAPISuccess('Payment', 'sendconfirmation', ['id' => $payment['id']]);
$mut->assertSubjects(['Payment Receipt - Annual CiviCRM meet']);
$mut->checkMailLog(array(
'Dear Mr. Anthony Anderson II',
'A payment has been received.',
'Total Fees: $ 300.00',
'This Payment Amount: $ 150.00',
'Balance Owed: $ 0.00',
'Thank you for completing payment.',
));
$mut->stop();
$mut->clearMessages();
}

/**
* Test email receipt for partial payment.
*
* @dataProvider getThousandSeparators
*
* @param string $thousandSeparator
*/
public function testRefundEmailReceipt($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
$decimalSeparator = ($thousandSeparator === ',' ? '.' : ',');
$mut = new CiviMailUtils($this);
list($lineItems, $contribution) = $this->createParticipantWithContribution();
$this->callAPISuccess('payment', 'create', [
'contribution_id' => $contribution['id'],
'total_amount' => 50,
'check_number' => '345',
'trxn_date' => '2018-08-13 17:57:56',
]);

$payment = $this->callAPISuccess('payment', 'create', [
'contribution_id' => $contribution['id'],
'total_amount' => -30,
'trxn_date' => '2018-11-13 12:01:56',
]);

$this->checkPaymentResult($payment, [
$payment['id'] => [
'from_financial_account_id' => 7,
'to_financial_account_id' => 6,
'total_amount' => -30,
'status_id' => 1,
'is_payment' => 1,
],
]);

$this->callAPISuccess('Payment', 'sendconfirmation', ['id' => $payment['id']]);
$mut->assertSubjects(['Refund Notification - Annual CiviCRM meet']);
$mut->checkMailLog(array(
'Dear Mr. Anthony Anderson II',
'A refund has been issued based on changes in your registration selections.',
'Total Fees: $ 300' . $decimalSeparator . '00',
'Refund Amount: $ -30' . $decimalSeparator . '00',
'Event Information and Location',
'Paid By: Check',
'Transaction Date: November 13th, 2018 12:01 PM',
'You Paid: $ 170' . $decimalSeparator . '00',
));
$mut->stop();
$mut->clearMessages();
}

/**
Expand Down