3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 usefusul, 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-2014
37 * This form records additional payments needed when
38 * event/contribution is partially paid
41 class CRM_Contribute_Form_AdditionalPayment
extends CRM_Contribute_Form_AbstractEditPayment
{
42 public $_contributeMode = 'direct';
45 * related component whose financial payment is being processed
50 protected $_component = NULL;
53 * id of the component entity
57 protected $_owed = NULL;
59 protected $_refund = NULL;
61 protected $_contactId = NULL;
63 protected $_contributorDisplayName = NULL;
65 protected $_contributorEmail = NULL;
67 protected $_toDoNotEmail = NULL;
69 protected $_paymentType = NULL;
71 protected $_contributionId = NULL;
73 protected $fromEmailId = NULL;
75 protected $_fromEmails = NULL;
77 protected $_view = NULL;
79 public $_action = NULL;
81 public function preProcess() {
82 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
83 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
84 $this->_component
= CRM_Utils_Request
::retrieve('component', 'String', $this, TRUE);
85 $this->_view
= CRM_Utils_Request
::retrieve('view', 'String', $this, FALSE);
86 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE);
87 $this->assign('component', $this->_component
);
88 $this->assign('id', $this->_id
);
90 if ($this->_view
== 'transaction' && ($this->_action
& CRM_Core_Action
::BROWSE
)) {
91 $paymentInfo = CRM_Contribute_BAO_Contribution
::getPaymentInfo($this->_id
, $this->_component
, TRUE);
92 $transactionRows = $paymentInfo['transaction'];
93 $title = ts('View Payment');
94 if ($this->_component
== 'event') {
95 $info = CRM_Event_BAO_Participant
::participantDetails($this->_id
);
96 $title .= " - {$info['title']}";
98 CRM_Utils_System
::setTitle($title);
99 $this->assign('transaction', TRUE);
100 $this->assign('rows', $transactionRows);
103 $this->_fromEmails
= CRM_Core_BAO_Email
::getFromEmail();
104 $this->_formType
= CRM_Utils_Array
::value('formType', $_GET);
107 if ($this->_component
== 'event') {
108 $enitityType = 'participant';
109 $this->_contributionId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id
, 'contribution_id', 'participant_id');
111 $eventId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'event_id', 'id');
112 $this->_fromEmails
= CRM_Event_BAO_Event
::getFromEmailIds($eventId);
114 $paymentInfo = CRM_Core_BAO_FinancialTrxn
::getPartialPaymentWithType($this->_id
, $enitityType);
115 $paymentDetails = CRM_Contribute_BAO_Contribution
::getPaymentInfo($this->_id
, $this->_component
, FALSE, TRUE);
117 $this->_amtPaid
= $paymentDetails['paid'];
118 $this->_amtTotal
= $paymentDetails['total'];
120 if (!empty($paymentInfo['refund_due'])) {
121 $paymentAmt = $this->_refund
= $paymentInfo['refund_due'];
122 $this->_paymentType
= 'refund';
124 elseif (!empty($paymentInfo['amount_owed'])) {
125 $paymentAmt = $this->_owed
= $paymentInfo['amount_owed'];
126 $this->_paymentType
= 'owed';
129 CRM_Core_Error
::fatal(ts('No payment information found for this record'));
132 //set the payment mode - _mode property is defined in parent class
133 $this->_mode
= CRM_Utils_Request
::retrieve('mode', 'String', $this);
135 if (!empty($this->_mode
) && $this->_paymentType
== 'refund') {
136 CRM_Core_Error
::fatal(ts('Credit card payment is not for Refund payments use'));
139 list($this->_contributorDisplayName
, $this->_contributorEmail
) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($this->_contactId
);
141 if (!$this->_refund
) {
142 $this->assignProcessors();
143 // also check for billing information
144 // get the billing location type
145 $this->assignBillingType();
148 $this->assign('contributionMode', $this->_mode
);
149 $this->assign('contactId', $this->_contactId
);
150 $this->assign('paymentType', $this->_paymentType
);
151 $this->assign('paymentAmt', abs($paymentAmt));
153 $this->setPageTitle($this->_refund ?
ts('Refund') : ts('Payment'));
155 $this->_paymentProcessor
= array('billing_mode' => 1);
159 * This virtual function is used to set the default values of
160 * various form elements
164 * @return array reference to the array of default values
170 public function setDefaultValues() {
171 if ($this->_view
== 'transaction' && ($this->_action
& CRM_Core_Action
::BROWSE
)) {
174 $defaults = array( );
176 $defaults = $this->_values
;
178 $config = CRM_Core_Config
::singleton();
179 // set default country from config if no country set
180 if (empty($defaults["billing_country_id-{$this->_bltID}"])) {
181 $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry
;
184 if (empty($defaults["billing_state_province_id-{$this->_bltID}"])) {
185 $defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince
;
188 $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactId
);
189 $defaults = array_merge($defaults, $billingDefaults);
192 if (empty($defaults['trxn_date']) && empty($defaults['trxn_date_time'])) {
193 list($defaults['trxn_date'],
194 $defaults['trxn_date_time']
195 ) = CRM_Utils_Date
::setDateDefaults(
196 CRM_Utils_Array
::value('register_date', $defaults), 'activityDateTime'
200 if ($this->_refund
) {
201 $defaults['total_amount'] = abs($this->_refund
);
204 // Set $newCredit variable in template to control whether link to credit card mode is included
205 $this->assign('newCredit', CRM_Core_Config
::isEnabledBackOfficeCreditCardPayments());
209 public function buildQuickForm() {
210 if ($this->_view
== 'transaction' && ($this->_action
& CRM_Core_Action
::BROWSE
)) {
211 $this->addButtons(array(
214 'name' => ts('Done'),
215 'spacing' => ' ',
224 if (CRM_Utils_Array
::value('payment_type', $this->_processors
) & CRM_Core_Payment
::PAYMENT_TYPE_DIRECT_DEBIT
226 $ccPane = array(ts('Direct Debit Information') => 'DirectDebit');
229 $ccPane = array(ts('Credit Card Information') => 'CreditCard');
231 $defaults = $this->_values
;
232 $showAdditionalInfo = FALSE;
234 foreach ($ccPane as $name => $type) {
235 if ($this->_formType
== $type ||
!empty($_POST["hidden_{$type}"]) ||
236 CRM_Utils_Array
::value("hidden_{$type}", $defaults)
238 $showAdditionalInfo = TRUE;
239 $allPanes[$name]['open'] = 'true';
242 $urlParams = "snippet=4&formType={$type}";
244 $urlParams .= "&mode={$this->_mode}";
247 if ($type == 'CreditCard' ||
248 $type == 'DirectDebit'
253 $allPanes[$name] = array(
254 'url' => CRM_Utils_System
::url('civicrm/payment/add', $urlParams),
259 if ($type == 'CreditCard') {
260 $this->add('hidden', 'hidden_CreditCard', 1);
261 CRM_Core_Payment_Form
::buildCreditCard($this, TRUE);
263 elseif ($type == 'DirectDebit') {
264 $this->add('hidden', 'hidden_DirectDebit', 1);
265 CRM_Core_Payment_Form
::buildDirectDebit($this, TRUE);
267 $qfKey = $this->controller
->_key
;
268 $this->assign('qfKey', $qfKey);
269 $this->assign('allPanes', $allPanes);
270 $this->assign('showAdditionalInfo', $showAdditionalInfo);
272 if ($this->_formType
) {
273 $this->assign('formType', $this->_formType
);
278 $attributes = CRM_Core_DAO
::getAttribute('CRM_Financial_DAO_FinancialTrxn');
280 $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors
, NULL);
281 $label = ($this->_refund
) ?
'Refund Amount' : 'Payment Amount';
282 $this->addMoney('total_amount',
283 ts('%1', array(1 => $label)),
285 $attributes['total_amount'],
286 TRUE, 'currency', NULL
289 $this->add('select', 'payment_instrument_id',
291 array('' => ts('- select -')) + CRM_Contribute_PseudoConstant
::paymentInstrument(),
292 TRUE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);")
295 $this->add('text', 'check_number', ts('Check Number'), $attributes['financial_trxn_check_number']);
296 $this->add('text', 'trxn_id', ts('Transaction ID'), array('class' => 'twelve') +
$attributes['trxn_id']);
298 //add receipt for offline contribution
299 $this->addElement('checkbox', 'is_email_receipt', ts('Send Receipt?'));
301 $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails
['from_email_id']);
303 $this->add('textarea', 'receipt_text', ts('Confirmation Message'));
306 $dateLabel = ($this->_refund
) ?
'Refund Date' : 'Received Date';
307 $this->addDateTime('trxn_date', ts('%1', array(1 => $dateLabel)), FALSE, array('formatType' => 'activityDateTime'));
309 if ($this->_contactId
&& $this->_id
) {
310 if ($this->_component
== 'event') {
311 $eventId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'event_id', 'id');
312 $event = CRM_Event_BAO_Event
::getEvents(0, $eventId);
313 $this->assign('eventName', $event[$eventId]);
317 $this->assign('displayName', $this->_contributorDisplayName
);
318 $this->assign('component', $this->_component
);
319 $this->assign('email', $this->_contributorEmail
);
321 $this->add('text', 'fee_amount', ts('Fee Amount'),
322 $attributes['fee_amount']
324 $this->addRule('fee_amount', ts('Please enter a valid monetary value for Fee Amount.'), 'money');
326 $this->add('text', 'net_amount', ts('Net Amount'),
327 $attributes['net_amount']
329 $this->addRule('net_amount', ts('Please enter a valid monetary value for Net Amount.'), 'money');
333 $js = array('onclick' => "return verify( );");
336 $buttonName = $this->_refund ?
'Record Refund' : 'Record Payment';
337 $this->addButtons(array(
340 'name' => ts('%1', array(1 => $buttonName)),
346 'name' => ts('Cancel')
352 $mailingInfo = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::MAILING_PREFERENCES_NAME
,
355 $this->assign('outBound_option', $mailingInfo['outBound_option']);
357 $this->addFormRule(array('CRM_Contribute_Form_AdditionalPayment', 'formRule'), $this);
367 static function formRule($fields, $files, $self) {
369 if ($self->_paymentType
== 'owed' && $fields['total_amount'] > $self->_owed
) {
370 $errors['total_amount'] = ts('Payment amount cannot be greater than owed amount');
372 if ($self->_paymentType
== 'refund' && $fields['total_amount'] != abs($self->_refund
)) {
373 $errors['total_amount'] = ts('Refund amount must equal refund due amount.');
375 $netAmt = $fields['total_amount'] - $fields['fee_amount'];
376 if (!empty($fields['net_amount']) && $netAmt != $fields['net_amount']) {
377 $errors['net_amount'] = ts('Net amount should be equal to the difference between payment amount and fee amount.');
382 public function postProcess() {
383 $participantId = NULL;
384 if ($this->_component
== 'event') {
385 $participantId = $this->_id
;
387 $submittedValues = $this->controller
->exportValues($this->_name
);
388 $submittedValues['confirm_email_text'] = CRM_Utils_Array
::value('receipt_text', $submittedValues);
390 $submittedValues['trxn_date'] = CRM_Utils_Date
::processDate($submittedValues['trxn_date'], $submittedValues['trxn_date_time']);
392 // process credit card
393 $this->assign('contributeMode', 'direct');
394 $this->processCreditCard($submittedValues);
397 $result = CRM_Contribute_BAO_Contribution
::recordAdditionalPayment($this->_contributionId
, $submittedValues, $this->_paymentType
, $participantId);
400 if (!empty($result) && !empty($submittedValues['is_email_receipt'])) {
401 $submittedValues['contact_id'] = $this->_contactId
;
402 $submittedValues['contribution_id'] = $this->_contributionId
;
404 // to get 'from email id' for send receipt
405 $this->fromEmailId
= $submittedValues['from_email_address'];
406 $sendReceipt = $this->emailReceipt($submittedValues);
409 $statusMsg = ts('The payment record has been processed.');
410 if (!empty($submittedValues['is_email_receipt']) && $sendReceipt) {
411 $statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.');
414 CRM_Core_Session
::setStatus($statusMsg, ts('Saved'), 'success');
416 $session = CRM_Core_Session
::singleton();
417 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view',
418 "reset=1&cid={$this->_contactId}&selectedChild=participant"
424 * @param $submittedValues
426 public function processCreditCard($submittedValues) {
427 $config = CRM_Core_Config
::singleton();
428 $session = CRM_Core_Session
::singleton();
430 $unsetParams = array(
432 'payment_instrument_id',
433 'contribution_status_id',
435 foreach ($unsetParams as $key) {
436 if (isset($submittedValues[$key])) {
437 unset($submittedValues[$key]);
441 //Get the rquire fields value only.
442 $params = $this->_params
= $submittedValues;
444 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($this->_params
['payment_processor_id'],
448 //get the payment processor id as per mode.
449 $this->_params
['payment_processor'] = $params['payment_processor_id'] =
450 $this->_params
['payment_processor_id'] = $submittedValues['payment_processor_id'] = $this->_paymentProcessor
['id'];
452 $now = date('YmdHis');
455 // we need to retrieve email address
456 if ($this->_context
== 'standalone' && !empty($submittedValues['is_email_receipt'])) {
457 list($this->userDisplayName
,
459 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($this->_contactId
);
460 $this->assign('displayName', $this->userDisplayName
);
463 //set email for primary location.
464 $fields['email-Primary'] = 1;
465 $params['email-Primary'] = $this->_contributorEmail
;
467 // now set the values for the billing location.
468 foreach ($this->_fields
as $name => $dontCare) {
472 // also add location name to the array
473 $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);
474 $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
475 $fields["address_name-{$this->_bltID}"] = 1;
477 $ctype = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
482 $nameFields = array('first_name', 'middle_name', 'last_name');
483 foreach ($nameFields as $name) {
485 if (array_key_exists("billing_$name", $params)) {
486 $params[$name] = $params["billing_{$name}"];
487 $params['preserveDBName'] = TRUE;
491 if (!empty($params['source'])) {
492 unset($params['source']);
494 $contactID = CRM_Contact_BAO_Contact
::createProfileContact($params, $fields,
500 // add all the additioanl payment params we need
501 $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}"]);
502 $this->_params
["country-{$this->_bltID}"] = $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
504 if ($this->_paymentProcessor
['payment_type'] & CRM_Core_Payment
::PAYMENT_TYPE_CREDIT_CARD
) {
505 $this->_params
['year'] = CRM_Core_Payment_Form
::getCreditCardExpirationYear($this->_params
);
506 $this->_params
['month'] = CRM_Core_Payment_Form
::getCreditCardExpirationMonth($this->_params
);
508 $this->_params
['ip_address'] = CRM_Utils_System
::ipAddress();
509 $this->_params
['amount'] = $this->_params
['total_amount'];
510 $this->_params
['amount_level'] = 0;
511 $this->_params
['currencyID'] = CRM_Utils_Array
::value('currency',
513 $config->defaultCurrency
515 $this->_params
['payment_action'] = 'Sale';
516 if (!empty($this->_params
['trxn_date'])) {
517 $this->_params
['receive_date'] = CRM_Utils_Date
::processDate($this->_params
['trxn_date'], $this->_params
['trxn_date_time']);
520 if (empty($this->_params
['invoice_id'])) {
521 $this->_params
['invoiceID'] = md5(uniqid(rand(), TRUE));
524 $this->_params
['invoiceID'] = $this->_params
['invoice_id'];
527 // billing name and Address
528 $name = CRM_Utils_Array
::value('billing_first_name', $params);
529 if (!empty($params['billing_middle_name'])) {
530 $name .= " {$params['billing_middle_name']}";
532 $name .= ' ' . CRM_Utils_Array
::value('billing_last_name', $params);
534 $this->assign('billingName', $name);
536 //assign the address formatted up for display
537 $addressParts = array(
538 "street_address" => "billing_street_address-{$this->_bltID}",
539 "city" => "billing_city-{$this->_bltID}",
540 "postal_code" => "billing_postal_code-{$this->_bltID}",
541 "state_province" => "state_province-{$this->_bltID}",
542 "country" => "country-{$this->_bltID}",
544 $addressFields = array();
545 foreach ($addressParts as $name => $field) {
546 $addressFields[$name] = CRM_Utils_Array
::value($field, $params);
548 $this->assign('address', CRM_Utils_Address
::format($addressFields));
549 $date = CRM_Utils_Date
::format($params['credit_card_exp_date']);
550 $date = CRM_Utils_Date
::mysqlToIso($date);
551 $this->assign('credit_card_type', CRM_Utils_Array
::value('credit_card_type', $params));
552 $this->assign('credit_card_exp_date', $date);
553 $this->assign('credit_card_number',
554 CRM_Utils_System
::mungeCreditCard($params['credit_card_number'])
557 //Add common data to formatted params
558 CRM_Contribute_Form_AdditionalInfo
::postProcessCommon($params, $this->_params
, $this);
559 // at this point we've created a contact and stored its address etc
560 // all the payment processors expect the name and address to be in the
561 // so we copy stuff over to first_name etc.
562 $paymentParams = $this->_params
;
563 $paymentParams['contactID'] = $this->_contactId
;
564 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $this->_params
, $paymentParams, TRUE);
566 // add some financial type details to the params list
567 // if folks need to use it
568 $paymentParams['contributionType_name'] = $this->_params
['contributionType_name'] = $contributionType->name
;
569 $paymentParams['contributionPageID'] = NULL;
570 if (!empty($this->_params
['is_email_receipt'])) {
571 $paymentParams['email'] = $this->_contributorEmail
;
572 $paymentParams['is_email_receipt'] = 1;
575 $paymentParams['is_email_receipt'] = 0;
576 $this->_params
['is_email_receipt'] = 0;
578 if (!empty($this->_params
['receive_date'])) {
579 $paymentParams['receive_date'] = $this->_params
['receive_date'];
581 if (!empty($this->_params
['receive_date'])) {
582 $paymentParams['receive_date'] = $this->_params
['receive_date'];
587 if ($paymentParams['amount'] > 0.0) {
588 // force a reget of the payment processor in case the form changed it, CRM-7179
589 $payment = CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this, TRUE);
590 $result = $payment->doDirectPayment($paymentParams);
593 if (is_a($result, 'CRM_Core_Error')) {
594 //set the contribution mode.
595 $urlParams = "action=add&cid={$this->_contactId}&id={$this->_id}&component={$this->_component}";
597 $urlParams .= "&mode={$this->_mode}";
599 CRM_Core_Error
::displaySessionError($result);
600 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/payment/add', $urlParams));
604 $this->_params
= array_merge($this->_params
, $result);
607 if (empty($this->_params
['receive_date'])) {
608 $this->_params
['receive_date'] = $now;
611 $this->set('params', $this->_params
);
613 // set source if not set
614 if (empty($this->_params
['source'])) {
615 $userID = $session->get('userID');
616 $userSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $userID,
619 $this->_params
['source'] = ts('Submit Credit Card Payment by: %1', array(1 => $userSortName));
622 // process the additional payment
623 $participantId = NULL;
624 if ($this->_component
== 'event') {
625 $participantId = $this->_id
;
627 $trxnRecord = CRM_Contribute_BAO_Contribution
::recordAdditionalPayment($this->_contributionId
, $submittedValues, $this->_paymentType
, $participantId);
629 if ($trxnRecord->id
&& !empty($this->_params
['is_email_receipt'])) {
630 $sendReceipt = $this->emailReceipt($this->_params
);
633 if ($trxnRecord->id
) {
634 $statusMsg = ts('The payment record has been processed.');
635 if (!empty($this->_params
['is_email_receipt']) && $sendReceipt) {
636 $statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.');
639 CRM_Core_Session
::setStatus($statusMsg, ts('Complete'), 'success');
640 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view',
641 "reset=1&cid={$this->_contactId}&selectedChild=participant"
651 function emailReceipt(&$params) {
652 // email receipt sending
653 // send message template
654 if ($this->_component
== 'event') {
655 $eventId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'event_id', 'id');
657 $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
658 CRM_Core_DAO
::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $eventId, $events, $returnProperties);
659 $event = $events[$eventId];
660 unset($event['start_date']);
661 unset($event['end_date']);
663 $this->assign('event', $event);
664 $this->assign('isShowLocation', $event['is_show_location']);
665 if (CRM_Utils_Array
::value('is_show_location', $event) == 1) {
666 $locationParams = array(
667 'entity_id' => $eventId,
668 'entity_table' => 'civicrm_event',
670 $location = CRM_Core_BAO_Location
::getValues($locationParams, TRUE);
671 $this->assign('location', $location);
675 // assign payment info here
676 $paymentConfig['confirm_email_text'] = CRM_Utils_Array
::value('confirm_email_text', $params);
677 $this->assign('paymentConfig', $paymentConfig);
678 $isRefund = ($this->_paymentType
== 'refund') ?
TRUE : FALSE;
679 $this->assign('isRefund', $isRefund);
681 $this->assign('totalPaid', $this->_amtPaid
);
682 $this->assign('totalAmount', $this->_amtTotal
);
683 $this->assign('refundAmount', $params['total_amount']);
686 $balance = $this->_amtTotal
- ($this->_amtPaid +
$params['total_amount']);
687 $paymentsComplete = ($balance == 0) ?
1 : 0;
688 $this->assign('amountOwed', $balance);
689 $this->assign('totalAmount', $this->_amtTotal
);
690 $this->assign('paymentAmount', $params['total_amount']);
691 $this->assign('paymentsComplete', $paymentsComplete);
693 $this->assign('contactDisplayName', $this->_contributorDisplayName
);
695 // assign trxn details
696 $this->assign('trxn_id', CRM_Utils_Array
::value('trxn_id', $params));
697 $this->assign('receive_date', CRM_Utils_Array
::value('trxn_date', $params));
698 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
699 if (array_key_exists('payment_instrument_id', $params)) {
700 $this->assign('paidBy',
701 CRM_Utils_Array
::value($params['payment_instrument_id'],
706 $this->assign('checkNumber', CRM_Utils_Array
::value('check_number', $params));
708 $sendTemplateParams = array(
709 'groupName' => 'msg_tpl_workflow_contribution',
710 'valueName' => 'payment_or_refund_notification',
711 'contactId' => $this->_contactId
,
712 'PDFFilename' => ts('notification').'.pdf',
715 // try to send emails only if email id is present
716 // and the do-not-email option is not checked for that contact
717 if ($this->_contributorEmail
&& !$this->_toDoNotEmail
) {
718 if (array_key_exists($params['from_email_address'], $this->_fromEmails
['from_email_id'])) {
719 $receiptFrom = $params['from_email_address'];
722 $sendTemplateParams['from'] = $receiptFrom;
723 $sendTemplateParams['toName'] = $this->_contributorDisplayName
;
724 $sendTemplateParams['toEmail'] = $this->_contributorEmail
;
725 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc', $this->_fromEmails
);
726 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc', $this->_fromEmails
);
728 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);