3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
37 * This form records additional payments needed when event/contribution is partially paid.
39 class CRM_Contribute_Form_AdditionalPayment
extends CRM_Contribute_Form_AbstractEditPayment
{
40 public $_contributeMode = 'direct';
43 * Related component whose financial payment is being processed
47 protected $_component = NULL;
50 * Id of the component entity
54 protected $_owed = NULL;
56 protected $_refund = NULL;
58 protected $_contactId = NULL;
60 protected $_contributorDisplayName = NULL;
62 protected $_contributorEmail = NULL;
64 protected $_toDoNotEmail = NULL;
66 protected $_paymentType = NULL;
68 protected $_contributionId = NULL;
70 protected $fromEmailId = NULL;
72 protected $_fromEmails = NULL;
74 protected $_view = NULL;
76 public $_action = NULL;
78 public function preProcess() {
79 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
80 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
81 $this->_component
= CRM_Utils_Request
::retrieve('component', 'String', $this, TRUE);
82 $this->_view
= CRM_Utils_Request
::retrieve('view', 'String', $this, FALSE);
83 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE);
84 $this->assign('component', $this->_component
);
85 $this->assign('id', $this->_id
);
87 if ($this->_view
== 'transaction' && ($this->_action
& CRM_Core_Action
::BROWSE
)) {
88 $paymentInfo = CRM_Contribute_BAO_Contribution
::getPaymentInfo($this->_id
, $this->_component
, TRUE);
89 $transactionRows = $paymentInfo['transaction'];
90 $title = ts('View Payment');
91 if ($this->_component
== 'event') {
92 $info = CRM_Event_BAO_Participant
::participantDetails($this->_id
);
93 $title .= " - {$info['title']}";
95 CRM_Utils_System
::setTitle($title);
96 $this->assign('transaction', TRUE);
97 $this->assign('rows', $transactionRows);
100 $this->_fromEmails
= CRM_Core_BAO_Email
::getFromEmail();
101 $this->_formType
= CRM_Utils_Array
::value('formType', $_GET);
104 if ($this->_component
== 'event') {
105 $enitityType = 'participant';
106 $this->_contributionId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id
, 'contribution_id', 'participant_id');
108 $eventId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'event_id', 'id');
109 $this->_fromEmails
= CRM_Event_BAO_Event
::getFromEmailIds($eventId);
111 $paymentInfo = CRM_Core_BAO_FinancialTrxn
::getPartialPaymentWithType($this->_id
, $enitityType);
112 $paymentDetails = CRM_Contribute_BAO_Contribution
::getPaymentInfo($this->_id
, $this->_component
, FALSE, TRUE);
114 $this->_amtPaid
= $paymentDetails['paid'];
115 $this->_amtTotal
= $paymentDetails['total'];
117 if (!empty($paymentInfo['refund_due'])) {
118 $paymentAmt = $this->_refund
= $paymentInfo['refund_due'];
119 $this->_paymentType
= 'refund';
121 elseif (!empty($paymentInfo['amount_owed'])) {
122 $paymentAmt = $this->_owed
= $paymentInfo['amount_owed'];
123 $this->_paymentType
= 'owed';
126 CRM_Core_Error
::fatal(ts('No payment information found for this record'));
129 //set the payment mode - _mode property is defined in parent class
130 $this->_mode
= CRM_Utils_Request
::retrieve('mode', 'String', $this);
132 if (!empty($this->_mode
) && $this->_paymentType
== 'refund') {
133 CRM_Core_Error
::fatal(ts('Credit card payment is not for Refund payments use'));
136 list($this->_contributorDisplayName
, $this->_contributorEmail
) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($this->_contactId
);
138 $this->assignPaymentRelatedVariables();
140 $this->assign('contributionMode', $this->_mode
);
141 $this->assign('contactId', $this->_contactId
);
142 $this->assign('paymentType', $this->_paymentType
);
143 $this->assign('paymentAmt', abs($paymentAmt));
145 $this->setPageTitle($this->_refund ?
ts('Refund') : ts('Payment'));
149 * This virtual function is used to set the default values of
150 * various form elements
155 * reference to the array of default values
160 public function setDefaultValues() {
161 if ($this->_view
== 'transaction' && ($this->_action
& CRM_Core_Action
::BROWSE
)) {
166 $defaults = $this->_values
;
168 $config = CRM_Core_Config
::singleton();
169 // set default country from config if no country set
170 if (empty($defaults["billing_country_id-{$this->_bltID}"])) {
171 $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry
;
174 if (empty($defaults["billing_state_province_id-{$this->_bltID}"])) {
175 $defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince
;
178 $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactId
);
179 $defaults = array_merge($defaults, $billingDefaults);
182 if (empty($defaults['trxn_date']) && empty($defaults['trxn_date_time'])) {
183 list($defaults['trxn_date'], $defaults['trxn_date_time'])
184 = CRM_Utils_Date
::setDateDefaults(
185 CRM_Utils_Array
::value('register_date', $defaults),
190 if ($this->_refund
) {
191 $defaults['total_amount'] = abs($this->_refund
);
194 // Set $newCredit variable in template to control whether link to credit card mode is included
195 $this->assign('newCredit', CRM_Core_Config
::isEnabledBackOfficeCreditCardPayments());
199 public function buildQuickForm() {
200 if ($this->_view
== 'transaction' && ($this->_action
& CRM_Core_Action
::BROWSE
)) {
201 $this->addButtons(array(
204 'name' => ts('Done'),
205 'spacing' => ' ',
214 if (CRM_Utils_Array
::value('payment_type', $this->_processors
) & CRM_Core_Payment
::PAYMENT_TYPE_DIRECT_DEBIT
216 $ccPane = array(ts('Direct Debit Information') => 'DirectDebit');
219 $ccPane = array(ts('Credit Card Information') => 'CreditCard');
221 $defaults = $this->_values
;
222 $showAdditionalInfo = FALSE;
224 foreach ($ccPane as $name => $type) {
225 if ($this->_formType
== $type ||
!empty($_POST["hidden_{$type}"]) ||
226 CRM_Utils_Array
::value("hidden_{$type}", $defaults)
228 $showAdditionalInfo = TRUE;
229 $allPanes[$name]['open'] = 'true';
232 $urlParams = "snippet=4&formType={$type}";
234 $urlParams .= "&mode={$this->_mode}";
237 if ($type == 'CreditCard' ||
238 $type == 'DirectDebit'
243 $allPanes[$name] = array(
244 'url' => CRM_Utils_System
::url('civicrm/payment/add', $urlParams),
249 CRM_Core_Payment_Form
::buildPaymentForm($this, $this->_paymentProcessor
, FALSE, TRUE);
251 $qfKey = $this->controller
->_key
;
252 $this->assign('qfKey', $qfKey);
253 $this->assign('allPanes', $allPanes);
254 $this->assign('showAdditionalInfo', $showAdditionalInfo);
256 if ($this->_formType
) {
257 $this->assign('formType', $this->_formType
);
262 $attributes = CRM_Core_DAO
::getAttribute('CRM_Financial_DAO_FinancialTrxn');
264 $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors
, NULL);
265 $label = ($this->_refund
) ?
ts('Refund Amount') : ts('Payment Amount');
266 $this->addMoney('total_amount',
269 $attributes['total_amount'],
270 TRUE, 'currency', NULL
273 $this->add('select', 'payment_instrument_id',
275 array('' => ts('- select -')) + CRM_Contribute_PseudoConstant
::paymentInstrument(),
276 TRUE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);")
279 $this->add('text', 'check_number', ts('Check Number'), $attributes['financial_trxn_check_number']);
280 $this->add('text', 'trxn_id', ts('Transaction ID'), array('class' => 'twelve') +
$attributes['trxn_id']);
282 //add receipt for offline contribution
283 $this->addElement('checkbox', 'is_email_receipt', ts('Send Receipt?'));
285 $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails
['from_email_id']);
287 $this->add('textarea', 'receipt_text', ts('Confirmation Message'));
290 $dateLabel = ($this->_refund
) ?
ts('Refund Date') : ts('Received Date');
291 $this->addDateTime('trxn_date', $dateLabel, FALSE, array('formatType' => 'activityDateTime'));
293 if ($this->_contactId
&& $this->_id
) {
294 if ($this->_component
== 'event') {
295 $eventId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'event_id', 'id');
296 $event = CRM_Event_BAO_Event
::getEvents(0, $eventId);
297 $this->assign('eventName', $event[$eventId]);
301 $this->assign('displayName', $this->_contributorDisplayName
);
302 $this->assign('component', $this->_component
);
303 $this->assign('email', $this->_contributorEmail
);
305 $this->add('text', 'fee_amount', ts('Fee Amount'),
306 $attributes['fee_amount']
308 $this->addRule('fee_amount', ts('Please enter a valid monetary value for Fee Amount.'), 'money');
310 $this->add('text', 'net_amount', ts('Net Amount'),
311 $attributes['net_amount']
313 $this->addRule('net_amount', ts('Please enter a valid monetary value for Net Amount.'), 'money');
317 $js = array('onclick' => "return verify( );");
320 $buttonName = $this->_refund ?
'Record Refund' : 'Record Payment';
321 $this->addButtons(array(
324 'name' => ts('%1', array(1 => $buttonName)),
330 'name' => ts('Cancel'),
334 $mailingInfo = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::MAILING_PREFERENCES_NAME
,
337 $this->assign('outBound_option', $mailingInfo['outBound_option']);
339 $this->addFormRule(array('CRM_Contribute_Form_AdditionalPayment', 'formRule'), $this);
349 public static function formRule($fields, $files, $self) {
351 if ($self->_paymentType
== 'owed' && $fields['total_amount'] > $self->_owed
) {
352 $errors['total_amount'] = ts('Payment amount cannot be greater than owed amount');
354 if ($self->_paymentType
== 'refund' && $fields['total_amount'] != abs($self->_refund
)) {
355 $errors['total_amount'] = ts('Refund amount must equal refund due amount.');
357 $netAmt = $fields['total_amount'] - $fields['fee_amount'];
358 if (!empty($fields['net_amount']) && $netAmt != $fields['net_amount']) {
359 $errors['net_amount'] = ts('Net amount should be equal to the difference between payment amount and fee amount.');
364 public function postProcess() {
365 $participantId = NULL;
366 if ($this->_component
== 'event') {
367 $participantId = $this->_id
;
369 $submittedValues = $this->controller
->exportValues($this->_name
);
370 $submittedValues['confirm_email_text'] = CRM_Utils_Array
::value('receipt_text', $submittedValues);
372 $submittedValues['trxn_date'] = CRM_Utils_Date
::processDate($submittedValues['trxn_date'], $submittedValues['trxn_date_time']);
374 // process credit card
375 $this->assign('contributeMode', 'direct');
376 $this->processCreditCard($submittedValues);
379 $result = CRM_Contribute_BAO_Contribution
::recordAdditionalPayment($this->_contributionId
, $submittedValues, $this->_paymentType
, $participantId);
382 if (!empty($result) && !empty($submittedValues['is_email_receipt'])) {
383 $submittedValues['contact_id'] = $this->_contactId
;
384 $submittedValues['contribution_id'] = $this->_contributionId
;
386 // to get 'from email id' for send receipt
387 $this->fromEmailId
= $submittedValues['from_email_address'];
388 $sendReceipt = $this->emailReceipt($submittedValues);
391 $statusMsg = ts('The payment record has been processed.');
392 if (!empty($submittedValues['is_email_receipt']) && $sendReceipt) {
393 $statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.');
396 CRM_Core_Session
::setStatus($statusMsg, ts('Saved'), 'success');
398 $session = CRM_Core_Session
::singleton();
399 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view',
400 "reset=1&cid={$this->_contactId}&selectedChild=participant"
406 * @param $submittedValues
408 public function processCreditCard($submittedValues) {
409 $config = CRM_Core_Config
::singleton();
410 $session = CRM_Core_Session
::singleton();
412 $unsetParams = array(
414 'payment_instrument_id',
415 'contribution_status_id',
417 foreach ($unsetParams as $key) {
418 if (isset($submittedValues[$key])) {
419 unset($submittedValues[$key]);
423 // Get the required fields value only.
424 $params = $this->_params
= $submittedValues;
426 //get the payment processor id as per mode.
427 //@todo unclear relevance of mode - seems like a lot of duplicated params here!
428 $this->_params
['payment_processor'] = $params['payment_processor_id']
429 = $this->_params
['payment_processor_id'] = $submittedValues['payment_processor_id'] = $this->_paymentProcessor
['id'];
431 $now = date('YmdHis');
434 // we need to retrieve email address
435 if ($this->_context
== 'standalone' && !empty($submittedValues['is_email_receipt'])) {
436 list($this->userDisplayName
,
438 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($this->_contactId
);
439 $this->assign('displayName', $this->userDisplayName
);
442 //set email for primary location.
443 $fields['email-Primary'] = 1;
444 $params['email-Primary'] = $this->_contributorEmail
;
446 // now set the values for the billing location.
447 foreach ($this->_fields
as $name => $dontCare) {
451 // also add location name to the array
452 $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);
453 $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
454 $fields["address_name-{$this->_bltID}"] = 1;
456 $ctype = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
461 $nameFields = array('first_name', 'middle_name', 'last_name');
462 foreach ($nameFields as $name) {
464 if (array_key_exists("billing_$name", $params)) {
465 $params[$name] = $params["billing_{$name}"];
466 $params['preserveDBName'] = TRUE;
470 if (!empty($params['source'])) {
471 unset($params['source']);
473 $contactID = CRM_Contact_BAO_Contact
::createProfileContact($params, $fields,
479 // Add all the additional payment params we need.
480 $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}"]);
481 $this->_params
["country-{$this->_bltID}"] = $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
483 if ($this->_paymentProcessor
['payment_type'] & CRM_Core_Payment
::PAYMENT_TYPE_CREDIT_CARD
) {
484 $this->_params
['year'] = CRM_Core_Payment_Form
::getCreditCardExpirationYear($this->_params
);
485 $this->_params
['month'] = CRM_Core_Payment_Form
::getCreditCardExpirationMonth($this->_params
);
487 $this->_params
['ip_address'] = CRM_Utils_System
::ipAddress();
488 $this->_params
['amount'] = $this->_params
['total_amount'];
489 $this->_params
['amount_level'] = 0;
490 $this->_params
['currencyID'] = CRM_Utils_Array
::value('currency',
492 $config->defaultCurrency
495 if (!empty($this->_params
['trxn_date'])) {
496 $this->_params
['receive_date'] = CRM_Utils_Date
::processDate($this->_params
['trxn_date'], $this->_params
['trxn_date_time']);
499 if (empty($this->_params
['invoice_id'])) {
500 $this->_params
['invoiceID'] = md5(uniqid(rand(), TRUE));
503 $this->_params
['invoiceID'] = $this->_params
['invoice_id'];
506 // billing name and Address
507 $name = CRM_Utils_Array
::value('billing_first_name', $params);
508 if (!empty($params['billing_middle_name'])) {
509 $name .= " {$params['billing_middle_name']}";
511 $name .= ' ' . CRM_Utils_Array
::value('billing_last_name', $params);
513 $this->assign('billingName', $name);
515 //assign the address formatted up for display
516 $addressParts = array(
517 "street_address" => "billing_street_address-{$this->_bltID}",
518 "city" => "billing_city-{$this->_bltID}",
519 "postal_code" => "billing_postal_code-{$this->_bltID}",
520 "state_province" => "state_province-{$this->_bltID}",
521 "country" => "country-{$this->_bltID}",
523 $addressFields = array();
524 foreach ($addressParts as $name => $field) {
525 $addressFields[$name] = CRM_Utils_Array
::value($field, $params);
527 $this->assign('address', CRM_Utils_Address
::format($addressFields));
528 $date = CRM_Utils_Date
::format($params['credit_card_exp_date']);
529 $date = CRM_Utils_Date
::mysqlToIso($date);
530 $this->assign('credit_card_type', CRM_Utils_Array
::value('credit_card_type', $params));
531 $this->assign('credit_card_exp_date', $date);
532 $this->assign('credit_card_number',
533 CRM_Utils_System
::mungeCreditCard($params['credit_card_number'])
536 //Add common data to formatted params
537 CRM_Contribute_Form_AdditionalInfo
::postProcessCommon($params, $this->_params
, $this);
538 // at this point we've created a contact and stored its address etc
539 // all the payment processors expect the name and address to be in the
540 // so we copy stuff over to first_name etc.
541 $paymentParams = $this->_params
;
542 $paymentParams['contactID'] = $this->_contactId
;
543 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $this->_params
, $paymentParams, TRUE);
545 // add some financial type details to the params list
546 // if folks need to use it
547 $paymentParams['contributionType_name'] = $this->_params
['contributionType_name'] = $contributionType->name
;
548 $paymentParams['contributionPageID'] = NULL;
549 if (!empty($this->_params
['is_email_receipt'])) {
550 $paymentParams['email'] = $this->_contributorEmail
;
551 $paymentParams['is_email_receipt'] = 1;
554 $paymentParams['is_email_receipt'] = 0;
555 $this->_params
['is_email_receipt'] = 0;
557 if (!empty($this->_params
['receive_date'])) {
558 $paymentParams['receive_date'] = $this->_params
['receive_date'];
560 if (!empty($this->_params
['receive_date'])) {
561 $paymentParams['receive_date'] = $this->_params
['receive_date'];
566 if ($paymentParams['amount'] > 0.0) {
568 // force a reget of the payment processor in case the form changed it, CRM-7179
569 $payment = Civi\Payment\System
::singleton()->getByProcessor($this->_paymentProcessor
);
570 $result = $payment->doPayment($paymentParams);
572 catch (\Civi\Payment\Exception\PaymentProcessorException
$e) {
573 //set the contribution mode.
574 $urlParams = "action=add&cid={$this->_contactId}&id={$this->_id}&component={$this->_component}";
576 $urlParams .= "&mode={$this->_mode}";
578 CRM_Core_Error
::displaySessionError($result);
579 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/payment/add', $urlParams));
584 $this->_params
= array_merge($this->_params
, $result);
587 if (empty($this->_params
['receive_date'])) {
588 $this->_params
['receive_date'] = $now;
591 $this->set('params', $this->_params
);
593 // set source if not set
594 if (empty($this->_params
['source'])) {
595 $userID = $session->get('userID');
596 $userSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $userID,
599 $this->_params
['source'] = ts('Submit Credit Card Payment by: %1', array(1 => $userSortName));
602 // process the additional payment
603 $participantId = NULL;
604 if ($this->_component
== 'event') {
605 $participantId = $this->_id
;
607 $trxnRecord = CRM_Contribute_BAO_Contribution
::recordAdditionalPayment($this->_contributionId
, $submittedValues, $this->_paymentType
, $participantId);
609 if ($trxnRecord->id
&& !empty($this->_params
['is_email_receipt'])) {
610 $sendReceipt = $this->emailReceipt($this->_params
);
613 if ($trxnRecord->id
) {
614 $statusMsg = ts('The payment record has been processed.');
615 if (!empty($this->_params
['is_email_receipt']) && $sendReceipt) {
616 $statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.');
619 CRM_Core_Session
::setStatus($statusMsg, ts('Complete'), 'success');
620 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view',
621 "reset=1&cid={$this->_contactId}&selectedChild=participant"
627 * @param array $params
631 public function emailReceipt(&$params) {
632 // email receipt sending
633 // send message template
634 if ($this->_component
== 'event') {
635 $eventId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'event_id', 'id');
637 $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
638 CRM_Core_DAO
::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $eventId, $events, $returnProperties);
639 $event = $events[$eventId];
640 unset($event['start_date']);
641 unset($event['end_date']);
643 $this->assign('event', $event);
644 $this->assign('isShowLocation', $event['is_show_location']);
645 if (CRM_Utils_Array
::value('is_show_location', $event) == 1) {
646 $locationParams = array(
647 'entity_id' => $eventId,
648 'entity_table' => 'civicrm_event',
650 $location = CRM_Core_BAO_Location
::getValues($locationParams, TRUE);
651 $this->assign('location', $location);
655 // assign payment info here
656 $paymentConfig['confirm_email_text'] = CRM_Utils_Array
::value('confirm_email_text', $params);
657 $this->assign('paymentConfig', $paymentConfig);
658 $isRefund = ($this->_paymentType
== 'refund') ?
TRUE : FALSE;
659 $this->assign('isRefund', $isRefund);
661 $this->assign('totalPaid', $this->_amtPaid
);
662 $this->assign('totalAmount', $this->_amtTotal
);
663 $this->assign('refundAmount', $params['total_amount']);
666 $balance = $this->_amtTotal
- ($this->_amtPaid +
$params['total_amount']);
667 $paymentsComplete = ($balance == 0) ?
1 : 0;
668 $this->assign('amountOwed', $balance);
669 $this->assign('totalAmount', $this->_amtTotal
);
670 $this->assign('paymentAmount', $params['total_amount']);
671 $this->assign('paymentsComplete', $paymentsComplete);
673 $this->assign('contactDisplayName', $this->_contributorDisplayName
);
675 // assign trxn details
676 $this->assign('trxn_id', CRM_Utils_Array
::value('trxn_id', $params));
677 $this->assign('receive_date', CRM_Utils_Array
::value('trxn_date', $params));
678 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
679 if (array_key_exists('payment_instrument_id', $params)) {
680 $this->assign('paidBy',
681 CRM_Utils_Array
::value($params['payment_instrument_id'],
686 $this->assign('checkNumber', CRM_Utils_Array
::value('check_number', $params));
688 $sendTemplateParams = array(
689 'groupName' => 'msg_tpl_workflow_contribution',
690 'valueName' => 'payment_or_refund_notification',
691 'contactId' => $this->_contactId
,
692 'PDFFilename' => ts('notification') . '.pdf',
695 // try to send emails only if email id is present
696 // and the do-not-email option is not checked for that contact
697 if ($this->_contributorEmail
&& !$this->_toDoNotEmail
) {
698 if (array_key_exists($params['from_email_address'], $this->_fromEmails
['from_email_id'])) {
699 $receiptFrom = $params['from_email_address'];
702 $sendTemplateParams['from'] = $receiptFrom;
703 $sendTemplateParams['toName'] = $this->_contributorDisplayName
;
704 $sendTemplateParams['toEmail'] = $this->_contributorEmail
;
705 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc', $this->_fromEmails
);
706 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc', $this->_fromEmails
);
708 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);