3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2016
35 * This form records additional payments needed when event/contribution is partially paid.
37 class CRM_Contribute_Form_AdditionalPayment
extends CRM_Contribute_Form_AbstractEditPayment
{
38 public $_contributeMode = 'direct';
41 * Related component whose financial payment is being processed.
45 protected $_component = NULL;
48 * Id of the component entity
52 protected $_owed = NULL;
54 protected $_refund = NULL;
56 protected $_contactId = NULL;
58 protected $_contributorDisplayName = NULL;
60 protected $_contributorEmail = NULL;
62 protected $_toDoNotEmail = NULL;
64 protected $_paymentType = NULL;
66 protected $_contributionId = NULL;
68 protected $fromEmailId = NULL;
70 protected $_fromEmails = NULL;
72 protected $_view = NULL;
74 public $_action = NULL;
76 public function preProcess() {
77 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
78 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
79 $this->_component
= CRM_Utils_Request
::retrieve('component', 'String', $this, TRUE);
80 $this->_view
= CRM_Utils_Request
::retrieve('view', 'String', $this, FALSE);
81 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE);
82 $this->assign('component', $this->_component
);
83 $this->assign('id', $this->_id
);
84 $this->assign('suppressPaymentFormButtons', $this->isBeingCalledFromSelectorContext());
86 if ($this->_view
== 'transaction' && ($this->_action
& CRM_Core_Action
::BROWSE
)) {
87 $paymentInfo = CRM_Contribute_BAO_Contribution
::getPaymentInfo($this->_id
, $this->_component
, TRUE);
88 $transactionRows = $paymentInfo['transaction'];
89 $title = ts('View Payment');
90 if ($this->_component
== 'event') {
91 $info = CRM_Event_BAO_Participant
::participantDetails($this->_id
);
92 $title .= " - {$info['title']}";
94 CRM_Utils_System
::setTitle($title);
95 $this->assign('transaction', TRUE);
96 $this->assign('rows', $transactionRows);
99 $this->_fromEmails
= CRM_Core_BAO_Email
::getFromEmail();
100 $this->_formType
= CRM_Utils_Array
::value('formType', $_GET);
103 if ($this->_component
== 'event') {
104 $enitityType = 'participant';
105 $this->_contributionId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id
, 'contribution_id', 'participant_id');
107 $eventId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'event_id', 'id');
108 $this->_fromEmails
= CRM_Event_BAO_Event
::getFromEmailIds($eventId);
110 $paymentInfo = CRM_Core_BAO_FinancialTrxn
::getPartialPaymentWithType($this->_id
, $enitityType);
111 $paymentDetails = CRM_Contribute_BAO_Contribution
::getPaymentInfo($this->_id
, $this->_component
, FALSE, TRUE);
113 $this->_amtPaid
= $paymentDetails['paid'];
114 $this->_amtTotal
= $paymentDetails['total'];
116 if (!empty($paymentInfo['refund_due'])) {
117 $paymentAmt = $this->_refund
= $paymentInfo['refund_due'];
118 $this->_paymentType
= 'refund';
120 elseif (!empty($paymentInfo['amount_owed'])) {
121 $paymentAmt = $this->_owed
= $paymentInfo['amount_owed'];
122 $this->_paymentType
= 'owed';
125 CRM_Core_Error
::fatal(ts('No payment information found for this record'));
128 //set the payment mode - _mode property is defined in parent class
129 $this->_mode
= CRM_Utils_Request
::retrieve('mode', 'String', $this);
131 if (!empty($this->_mode
) && $this->_paymentType
== 'refund') {
132 CRM_Core_Error
::fatal(ts('Credit card payment is not for Refund payments use'));
135 list($this->_contributorDisplayName
, $this->_contributorEmail
) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($this->_contactId
);
137 $this->assignPaymentRelatedVariables();
139 $this->assign('contributionMode', $this->_mode
);
140 $this->assign('contactId', $this->_contactId
);
141 $this->assign('paymentType', $this->_paymentType
);
142 $this->assign('paymentAmt', abs($paymentAmt));
144 $this->setPageTitle($this->_refund ?
ts('Refund') : ts('Payment'));
148 * Is this function being called from a datatable selector.
150 * If so we don't want to show the buttons.
152 protected function isBeingCalledFromSelectorContext() {
153 return CRM_Utils_Request
::retrieve('selector', 'Positive');
157 * This virtual function is used to set the default values of
158 * various form elements
163 * reference to the array of default values
168 public function setDefaultValues() {
169 if ($this->_view
== 'transaction' && ($this->_action
& CRM_Core_Action
::BROWSE
)) {
174 $defaults = $this->_values
;
176 $config = CRM_Core_Config
::singleton();
177 // set default country from config if no country set
178 if (empty($defaults["billing_country_id-{$this->_bltID}"])) {
179 $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry
;
182 if (empty($defaults["billing_state_province_id-{$this->_bltID}"])) {
183 $defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince
;
186 $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactId
);
187 $defaults = array_merge($defaults, $billingDefaults);
190 if (empty($defaults['trxn_date']) && empty($defaults['trxn_date_time'])) {
191 list($defaults['trxn_date'], $defaults['trxn_date_time'])
192 = CRM_Utils_Date
::setDateDefaults(
193 CRM_Utils_Array
::value('register_date', $defaults),
198 if ($this->_refund
) {
199 $defaults['total_amount'] = abs($this->_refund
);
202 // Set $newCredit variable in template to control whether link to credit card mode is included
203 $this->assign('newCredit', CRM_Core_Config
::isEnabledBackOfficeCreditCardPayments());
207 public function buildQuickForm() {
208 if ($this->_view
== 'transaction' && ($this->_action
& CRM_Core_Action
::BROWSE
)) {
209 $this->addButtons(array(
212 'name' => ts('Done'),
213 'spacing' => ' ',
222 if (CRM_Utils_Array
::value('payment_type', $this->_processors
) & CRM_Core_Payment
::PAYMENT_TYPE_DIRECT_DEBIT
224 $ccPane = array(ts('Direct Debit Information') => 'DirectDebit');
227 $ccPane = array(ts('Credit Card Information') => 'CreditCard');
229 $defaults = $this->_values
;
230 $showAdditionalInfo = FALSE;
232 foreach ($ccPane as $name => $type) {
233 if ($this->_formType
== $type ||
!empty($_POST["hidden_{$type}"]) ||
234 CRM_Utils_Array
::value("hidden_{$type}", $defaults)
236 $showAdditionalInfo = TRUE;
237 $allPanes[$name]['open'] = 'true';
240 $urlParams = "snippet=4&formType={$type}";
242 $urlParams .= "&mode={$this->_mode}";
245 if ($type == 'CreditCard' ||
246 $type == 'DirectDebit'
251 $allPanes[$name] = array(
252 'url' => CRM_Utils_System
::url('civicrm/payment/add', $urlParams),
257 CRM_Core_Payment_Form
::buildPaymentForm($this, $this->_paymentProcessor
, FALSE, TRUE);
259 $qfKey = $this->controller
->_key
;
260 $this->assign('qfKey', $qfKey);
261 $this->assign('allPanes', $allPanes);
262 $this->assign('showAdditionalInfo', $showAdditionalInfo);
264 if ($this->_formType
) {
265 $this->assign('formType', $this->_formType
);
270 $attributes = CRM_Core_DAO
::getAttribute('CRM_Financial_DAO_FinancialTrxn');
272 $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors
, NULL);
273 $label = ($this->_refund
) ?
ts('Refund Amount') : ts('Payment Amount');
274 $this->addMoney('total_amount',
277 $attributes['total_amount'],
278 TRUE, 'currency', NULL
281 $this->add('select', 'payment_instrument_id',
282 ts('Payment Method'),
283 array('' => ts('- select -')) + CRM_Contribute_PseudoConstant
::paymentInstrument(),
284 TRUE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);")
287 $this->add('text', 'check_number', ts('Check Number'), $attributes['financial_trxn_check_number']);
288 $this->add('text', 'trxn_id', ts('Transaction ID'), array('class' => 'twelve') +
$attributes['trxn_id']);
290 //add receipt for offline contribution
291 $this->addElement('checkbox', 'is_email_receipt', ts('Send Receipt?'));
293 $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails
['from_email_id']);
295 $this->add('textarea', 'receipt_text', ts('Confirmation Message'));
298 $dateLabel = ($this->_refund
) ?
ts('Refund Date') : ts('Date Received');
299 $this->addDateTime('trxn_date', $dateLabel, FALSE, array('formatType' => 'activityDateTime'));
301 if ($this->_contactId
&& $this->_id
) {
302 if ($this->_component
== 'event') {
303 $eventId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'event_id', 'id');
304 $event = CRM_Event_BAO_Event
::getEvents(0, $eventId);
305 $this->assign('eventName', $event[$eventId]);
309 $this->assign('displayName', $this->_contributorDisplayName
);
310 $this->assign('component', $this->_component
);
311 $this->assign('email', $this->_contributorEmail
);
313 $this->add('text', 'fee_amount', ts('Fee Amount'),
314 $attributes['fee_amount']
316 $this->addRule('fee_amount', ts('Please enter a valid monetary value for Fee Amount.'), 'money');
318 $this->add('text', 'net_amount', ts('Net Amount'),
319 $attributes['net_amount']
321 $this->addRule('net_amount', ts('Please enter a valid monetary value for Net Amount.'), 'money');
325 $js = array('onclick' => "return verify( );");
328 $buttonName = $this->_refund ?
'Record Refund' : 'Record Payment';
329 $this->addButtons(array(
332 'name' => ts('%1', array(1 => $buttonName)),
338 'name' => ts('Cancel'),
342 $mailingInfo = Civi
::settings()->get('mailing_backend');
343 $this->assign('outBound_option', $mailingInfo['outBound_option']);
345 $this->addFormRule(array('CRM_Contribute_Form_AdditionalPayment', 'formRule'), $this);
355 public static function formRule($fields, $files, $self) {
357 if ($self->_paymentType
== 'owed' && $fields['total_amount'] > $self->_owed
) {
358 $errors['total_amount'] = ts('Payment amount cannot be greater than owed amount');
360 if ($self->_paymentType
== 'refund' && $fields['total_amount'] != abs($self->_refund
)) {
361 $errors['total_amount'] = ts('Refund amount must equal refund due amount.');
363 $netAmt = $fields['total_amount'] - $fields['fee_amount'];
364 if (!empty($fields['net_amount']) && $netAmt != $fields['net_amount']) {
365 $errors['net_amount'] = ts('Net amount should be equal to the difference between payment amount and fee amount.');
370 public function postProcess() {
371 $participantId = NULL;
372 if ($this->_component
== 'event') {
373 $participantId = $this->_id
;
375 $submittedValues = $this->controller
->exportValues($this->_name
);
376 $submittedValues['confirm_email_text'] = CRM_Utils_Array
::value('receipt_text', $submittedValues);
378 $submittedValues['trxn_date'] = CRM_Utils_Date
::processDate($submittedValues['trxn_date'], $submittedValues['trxn_date_time']);
380 // process credit card
381 $this->assign('contributeMode', 'direct');
382 $this->processCreditCard($submittedValues);
386 $contribution = civicrm_api3('Contribution', 'getsingle', array(
387 'return' => array("contribution_status_id"),
388 'id' => $this->_contributionId
,
390 $contributionStatusId = CRM_Utils_Array
::value('contribution_status_id', $contribution);
391 $result = CRM_Contribute_BAO_Contribution
::recordAdditionalPayment($this->_contributionId
, $submittedValues, $this->_paymentType
, $participantId);
392 // Fetch the contribution & do proportional line item assignment
393 $params = array('id' => $this->_contributionId
);
394 $contribution = CRM_Contribute_BAO_Contribution
::retrieve($params, $defaults, $params);
395 $lineItems = CRM_Price_BAO_LineItem
::getLineItemsByContributionID($this->_contributionId
);
396 if (!empty($lineItems)) {
397 CRM_Contribute_BAO_Contribution
::addPayments($lineItems, array($contribution), $contributionStatusId);
401 if (!empty($result) && !empty($submittedValues['is_email_receipt'])) {
402 $submittedValues['contact_id'] = $this->_contactId
;
403 $submittedValues['contribution_id'] = $this->_contributionId
;
405 // to get 'from email id' for send receipt
406 $this->fromEmailId
= $submittedValues['from_email_address'];
407 $sendReceipt = $this->emailReceipt($submittedValues);
410 $statusMsg = ts('The payment record has been processed.');
411 if (!empty($submittedValues['is_email_receipt']) && $sendReceipt) {
412 $statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.');
415 CRM_Core_Session
::setStatus($statusMsg, ts('Saved'), 'success');
417 $session = CRM_Core_Session
::singleton();
418 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view',
419 "reset=1&cid={$this->_contactId}&selectedChild=participant"
425 * @param $submittedValues
427 public function processCreditCard($submittedValues) {
428 $config = CRM_Core_Config
::singleton();
429 $session = CRM_Core_Session
::singleton();
431 $unsetParams = array(
433 'payment_instrument_id',
434 'contribution_status_id',
436 foreach ($unsetParams as $key) {
437 if (isset($submittedValues[$key])) {
438 unset($submittedValues[$key]);
442 // Get the required fields value only.
443 $params = $this->_params
= $submittedValues;
445 //get the payment processor id as per mode.
446 //@todo unclear relevance of mode - seems like a lot of duplicated params here!
447 $this->_params
['payment_processor'] = $params['payment_processor_id']
448 = $this->_params
['payment_processor_id'] = $submittedValues['payment_processor_id'] = $this->_paymentProcessor
['id'];
450 $now = date('YmdHis');
453 // we need to retrieve email address
454 if ($this->_context
== 'standalone' && !empty($submittedValues['is_email_receipt'])) {
455 list($this->userDisplayName
,
457 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($this->_contactId
);
458 $this->assign('displayName', $this->userDisplayName
);
461 //set email for primary location.
462 $fields['email-Primary'] = 1;
463 $params['email-Primary'] = $this->_contributorEmail
;
465 // now set the values for the billing location.
466 foreach ($this->_fields
as $name => $dontCare) {
470 // also add location name to the array
471 $params["address_name-{$this->_bltID}"] = CRM_Utils_Array
::value('billing_first_name', $params) . ' ' . CRM_Utils_Array
::value('billing_middle_name', $params) . ' ' . CRM_Utils_Array
::value('billing_last_name', $params);
472 $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
473 $fields["address_name-{$this->_bltID}"] = 1;
475 $ctype = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
480 $nameFields = array('first_name', 'middle_name', 'last_name');
481 foreach ($nameFields as $name) {
483 if (array_key_exists("billing_$name", $params)) {
484 $params[$name] = $params["billing_{$name}"];
485 $params['preserveDBName'] = TRUE;
489 if (!empty($params['source'])) {
490 unset($params['source']);
492 $contactID = CRM_Contact_BAO_Contact
::createProfileContact($params, $fields,
498 // Add all the additional payment params we need.
499 $this->_params
["state_province-{$this->_bltID}"] = $this->_params
["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($this->_params
["billing_state_province_id-{$this->_bltID}"]);
500 $this->_params
["country-{$this->_bltID}"] = $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
502 if ($this->_paymentProcessor
['payment_type'] & CRM_Core_Payment
::PAYMENT_TYPE_CREDIT_CARD
) {
503 $this->_params
['year'] = CRM_Core_Payment_Form
::getCreditCardExpirationYear($this->_params
);
504 $this->_params
['month'] = CRM_Core_Payment_Form
::getCreditCardExpirationMonth($this->_params
);
506 $this->_params
['ip_address'] = CRM_Utils_System
::ipAddress();
507 $this->_params
['amount'] = $this->_params
['total_amount'];
508 // @todo - stop setting amount level in this function & call the CRM_Price_BAO_PriceSet::getAmountLevel
509 // function to get correct amount level consistently. Remove setting of the amount level in
510 // CRM_Price_BAO_PriceSet::processAmount. Extend the unit tests in CRM_Price_BAO_PriceSetTest
511 // to cover all variants.
512 $this->_params
['amount_level'] = 0;
513 $this->_params
['currencyID'] = CRM_Utils_Array
::value('currency',
515 $config->defaultCurrency
518 if (!empty($this->_params
['trxn_date'])) {
519 $this->_params
['receive_date'] = CRM_Utils_Date
::processDate($this->_params
['trxn_date'], $this->_params
['trxn_date_time']);
522 if (empty($this->_params
['invoice_id'])) {
523 $this->_params
['invoiceID'] = md5(uniqid(rand(), TRUE));
526 $this->_params
['invoiceID'] = $this->_params
['invoice_id'];
529 $this->assignBillingName($params);
530 $this->assign('address', CRM_Utils_Address
::getFormattedBillingAddressFieldsFromParameters(
535 $date = CRM_Utils_Date
::format($params['credit_card_exp_date']);
536 $date = CRM_Utils_Date
::mysqlToIso($date);
537 $this->assign('credit_card_type', CRM_Utils_Array
::value('credit_card_type', $params));
538 $this->assign('credit_card_exp_date', $date);
539 $this->assign('credit_card_number',
540 CRM_Utils_System
::mungeCreditCard($params['credit_card_number'])
543 //Add common data to formatted params
544 CRM_Contribute_Form_AdditionalInfo
::postProcessCommon($params, $this->_params
, $this);
545 // at this point we've created a contact and stored its address etc
546 // all the payment processors expect the name and address to be in the
547 // so we copy stuff over to first_name etc.
548 $paymentParams = $this->_params
;
549 $paymentParams['contactID'] = $this->_contactId
;
550 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $this->_params
, $paymentParams, TRUE);
552 // add some financial type details to the params list
553 // if folks need to use it
554 $paymentParams['contributionType_name'] = $this->_params
['contributionType_name'] = $contributionType->name
;
555 $paymentParams['contributionPageID'] = NULL;
556 if (!empty($this->_params
['is_email_receipt'])) {
557 $paymentParams['email'] = $this->_contributorEmail
;
558 $paymentParams['is_email_receipt'] = 1;
561 $paymentParams['is_email_receipt'] = 0;
562 $this->_params
['is_email_receipt'] = 0;
564 if (!empty($this->_params
['receive_date'])) {
565 $paymentParams['receive_date'] = $this->_params
['receive_date'];
567 if (!empty($this->_params
['receive_date'])) {
568 $paymentParams['receive_date'] = $this->_params
['receive_date'];
573 if ($paymentParams['amount'] > 0.0) {
575 // force a reget of the payment processor in case the form changed it, CRM-7179
576 $payment = Civi\Payment\System
::singleton()->getByProcessor($this->_paymentProcessor
);
577 $result = $payment->doPayment($paymentParams);
579 catch (\Civi\Payment\Exception\PaymentProcessorException
$e) {
580 //set the contribution mode.
581 $urlParams = "action=add&cid={$this->_contactId}&id={$this->_id}&component={$this->_component}";
583 $urlParams .= "&mode={$this->_mode}";
585 CRM_Core_Error
::displaySessionError($result);
586 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/payment/add', $urlParams));
591 $this->_params
= array_merge($this->_params
, $result);
594 if (empty($this->_params
['receive_date'])) {
595 $this->_params
['receive_date'] = $now;
598 $this->set('params', $this->_params
);
600 // set source if not set
601 if (empty($this->_params
['source'])) {
602 $userID = $session->get('userID');
603 $userSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $userID,
606 $this->_params
['source'] = ts('Submit Credit Card Payment by: %1', array(1 => $userSortName));
609 // process the additional payment
610 $participantId = NULL;
611 if ($this->_component
== 'event') {
612 $participantId = $this->_id
;
614 $trxnRecord = CRM_Contribute_BAO_Contribution
::recordAdditionalPayment($this->_contributionId
, $submittedValues, $this->_paymentType
, $participantId);
616 if ($trxnRecord->id
&& !empty($this->_params
['is_email_receipt'])) {
617 $sendReceipt = $this->emailReceipt($this->_params
);
620 if ($trxnRecord->id
) {
621 $statusMsg = ts('The payment record has been processed.');
622 if (!empty($this->_params
['is_email_receipt']) && $sendReceipt) {
623 $statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.');
626 CRM_Core_Session
::setStatus($statusMsg, ts('Complete'), 'success');
627 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view',
628 "reset=1&cid={$this->_contactId}&selectedChild=participant"
634 * @param array $params
638 public function emailReceipt(&$params) {
639 // email receipt sending
640 // send message template
641 if ($this->_component
== 'event') {
642 $eventId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'event_id', 'id');
644 $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
645 CRM_Core_DAO
::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $eventId, $events, $returnProperties);
646 $event = $events[$eventId];
647 unset($event['start_date']);
648 unset($event['end_date']);
650 $this->assign('event', $event);
651 $this->assign('isShowLocation', $event['is_show_location']);
652 if (CRM_Utils_Array
::value('is_show_location', $event) == 1) {
653 $locationParams = array(
654 'entity_id' => $eventId,
655 'entity_table' => 'civicrm_event',
657 $location = CRM_Core_BAO_Location
::getValues($locationParams, TRUE);
658 $this->assign('location', $location);
662 // assign payment info here
663 $paymentConfig['confirm_email_text'] = CRM_Utils_Array
::value('confirm_email_text', $params);
664 $this->assign('paymentConfig', $paymentConfig);
665 $isRefund = ($this->_paymentType
== 'refund') ?
TRUE : FALSE;
666 $this->assign('isRefund', $isRefund);
668 $this->assign('totalPaid', $this->_amtPaid
);
669 $this->assign('totalAmount', $this->_amtTotal
);
670 $this->assign('refundAmount', $params['total_amount']);
673 $balance = $this->_amtTotal
- ($this->_amtPaid +
$params['total_amount']);
674 $paymentsComplete = ($balance == 0) ?
1 : 0;
675 $this->assign('amountOwed', $balance);
676 $this->assign('totalAmount', $this->_amtTotal
);
677 $this->assign('paymentAmount', $params['total_amount']);
678 $this->assign('paymentsComplete', $paymentsComplete);
680 $this->assign('contactDisplayName', $this->_contributorDisplayName
);
682 // assign trxn details
683 $this->assign('trxn_id', CRM_Utils_Array
::value('trxn_id', $params));
684 $this->assign('receive_date', CRM_Utils_Array
::value('trxn_date', $params));
685 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
686 if (array_key_exists('payment_instrument_id', $params)) {
687 $this->assign('paidBy',
688 CRM_Utils_Array
::value($params['payment_instrument_id'],
693 $this->assign('checkNumber', CRM_Utils_Array
::value('check_number', $params));
695 $sendTemplateParams = array(
696 'groupName' => 'msg_tpl_workflow_contribution',
697 'valueName' => 'payment_or_refund_notification',
698 'contactId' => $this->_contactId
,
699 'PDFFilename' => ts('notification') . '.pdf',
702 // try to send emails only if email id is present
703 // and the do-not-email option is not checked for that contact
704 if ($this->_contributorEmail
&& !$this->_toDoNotEmail
) {
705 if (array_key_exists($params['from_email_address'], $this->_fromEmails
['from_email_id'])) {
706 $receiptFrom = $params['from_email_address'];
709 $sendTemplateParams['from'] = $receiptFrom;
710 $sendTemplateParams['toName'] = $this->_contributorDisplayName
;
711 $sendTemplateParams['toEmail'] = $this->_contributorEmail
;
712 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc', $this->_fromEmails
);
713 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc', $this->_fromEmails
);
715 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);