230c7e8600d3ee965a22c4ff39690b5a2311667f
[civicrm-core.git] / CRM / Contribute / Form / AdditionalPayment.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2017
32 */
33
34 /**
35 * This form records additional payments needed when event/contribution is partially paid.
36 */
37 class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_AbstractEditPayment {
38 public $_contributeMode = 'direct';
39
40 /**
41 * Related component whose financial payment is being processed.
42 *
43 * @var string
44 */
45 protected $_component = NULL;
46
47 /**
48 * Id of the component entity
49 */
50 public $_id = NULL;
51
52 protected $_owed = NULL;
53
54 protected $_refund = NULL;
55
56 /**
57 * @deprecated - use parent $this->contactID
58 *
59 * @var int
60 */
61 protected $_contactId = NULL;
62
63 protected $_contributorDisplayName = NULL;
64
65 protected $_contributorEmail = NULL;
66
67 protected $_toDoNotEmail = NULL;
68
69 protected $_paymentType = NULL;
70
71 protected $_contributionId = NULL;
72
73 protected $fromEmailId = NULL;
74
75 protected $_fromEmails = NULL;
76
77 protected $_view = NULL;
78
79 public $_action = NULL;
80
81 public function preProcess() {
82
83 parent::preProcess();
84 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
85 // @todo don't set this - rely on parent $this->contactID
86 $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
87 $this->_component = CRM_Utils_Request::retrieve('component', 'String', $this, TRUE);
88 $this->_view = CRM_Utils_Request::retrieve('view', 'String', $this, FALSE);
89 $this->assign('component', $this->_component);
90 $this->assign('id', $this->_id);
91 $this->assign('suppressPaymentFormButtons', $this->isBeingCalledFromSelectorContext());
92
93 if ($this->_view == 'transaction' && ($this->_action & CRM_Core_Action::BROWSE)) {
94 $paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_id, $this->_component, TRUE);
95 $title = ts('View Payment');
96 if ($this->_component == 'event') {
97 $info = CRM_Event_BAO_Participant::participantDetails($this->_id);
98 $title .= " - {$info['title']}";
99 }
100 CRM_Utils_System::setTitle($title);
101 $this->assign('transaction', TRUE);
102 $this->assign('payments', $paymentInfo['transaction']);
103 return;
104 }
105 $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
106
107 $entityType = 'contribution';
108 if ($this->_component == 'event') {
109 $entityType = 'participant';
110 $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);
113 }
114 else {
115 $this->_contributionId = $this->_id;
116 $this->_fromEmails['from_email_id'] = CRM_Core_BAO_Email::getFromEmail();
117 }
118
119 $paymentInfo = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($this->_id, $entityType);
120 $paymentDetails = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_id, $this->_component, FALSE, TRUE);
121
122 $this->_amtPaid = $paymentDetails['paid'];
123 $this->_amtTotal = $paymentDetails['total'];
124
125 if (!empty($paymentInfo['refund_due'])) {
126 $paymentAmt = $this->_refund = $paymentInfo['refund_due'];
127 $this->_paymentType = 'refund';
128 }
129 elseif (!empty($paymentInfo['amount_owed'])) {
130 $paymentAmt = $this->_owed = $paymentInfo['amount_owed'];
131 $this->_paymentType = 'owed';
132 }
133 else {
134 CRM_Core_Error::fatal(ts('No payment information found for this record'));
135 }
136
137 if (!empty($this->_mode) && $this->_paymentType == 'refund') {
138 CRM_Core_Error::fatal(ts('Credit card payment is not for Refund payments use'));
139 }
140
141 list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactId);
142
143 $this->assign('contributionMode', $this->_mode);
144 $this->assign('contactId', $this->_contactId);
145 $this->assign('paymentType', $this->_paymentType);
146 $this->assign('paymentAmt', abs($paymentAmt));
147
148 $this->setPageTitle($this->_refund ? ts('Refund') : ts('Payment'));
149 }
150
151 /**
152 * Is this function being called from a datatable selector.
153 *
154 * If so we don't want to show the buttons.
155 */
156 protected function isBeingCalledFromSelectorContext() {
157 return CRM_Utils_Request::retrieve('selector', 'Positive');
158 }
159
160 /**
161 * This virtual function is used to set the default values of
162 * various form elements
163 *
164 * access public
165 *
166 * @return array
167 * reference to the array of default values
168 */
169 /**
170 * @return array
171 */
172 public function setDefaultValues() {
173 if ($this->_view == 'transaction' && ($this->_action & CRM_Core_Action::BROWSE)) {
174 return NULL;
175 }
176 $defaults = array();
177 if ($this->_mode) {
178 CRM_Core_Payment_Form::setDefaultValues($this, $this->_contactId);
179 $defaults = array_merge($defaults, $this->_defaults);
180 }
181
182 if (empty($defaults['trxn_date'])) {
183 $defaults['trxn_date'] = date('Y-m-d H:i:s');
184 }
185
186 if ($this->_refund) {
187 $defaults['total_amount'] = abs($this->_refund);
188 }
189 elseif ($this->_owed) {
190 $defaults['total_amount'] = number_format($this->_owed, 2);
191 }
192
193 // Set $newCredit variable in template to control whether link to credit card mode is included
194 $this->assign('newCredit', CRM_Core_Config::isEnabledBackOfficeCreditCardPayments());
195 return $defaults;
196 }
197
198 /**
199 * Build the form object.
200 */
201 public function buildQuickForm() {
202 if ($this->_view == 'transaction' && ($this->_action & CRM_Core_Action::BROWSE)) {
203 $this->addButtons(array(
204 array(
205 'type' => 'cancel',
206 'name' => ts('Done'),
207 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
208 'isDefault' => TRUE,
209 ),
210 )
211 );
212 return;
213 }
214
215 CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE, TRUE, CRM_Utils_Request::retrieve('payment_instrument_id', 'Integer'));
216 $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, NULL);
217
218 $attributes = CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialTrxn');
219
220 $label = ($this->_refund) ? ts('Refund Amount') : ts('Payment Amount');
221 $this->addMoney('total_amount',
222 $label,
223 TRUE,
224 $attributes['total_amount'],
225 TRUE, 'currency', NULL
226 );
227
228 //add receipt for offline contribution
229 $this->addElement('checkbox', 'is_email_receipt', ts('Send Receipt?'));
230
231 $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails['from_email_id']);
232
233 $this->add('textarea', 'receipt_text', ts('Confirmation Message'));
234
235 $dateLabel = ($this->_refund) ? ts('Refund Date') : ts('Date Received');
236 $this->addField('trxn_date', array('entity' => 'FinancialTrxn', 'label' => $dateLabel, 'context' => 'Contribution'), FALSE, FALSE);
237
238 if ($this->_contactId && $this->_id) {
239 if ($this->_component == 'event') {
240 $eventId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'event_id', 'id');
241 $event = CRM_Event_BAO_Event::getEvents(0, $eventId);
242 $this->assign('eventName', $event[$eventId]);
243 }
244 }
245
246 $this->assign('displayName', $this->_contributorDisplayName);
247 $this->assign('component', $this->_component);
248 $this->assign('email', $this->_contributorEmail);
249
250 $js = NULL;
251 // render backoffice payment fields only on offline mode
252 if (!$this->_mode) {
253 $js = array('onclick' => "return verify( );");
254
255 $this->add('select', 'payment_instrument_id',
256 ts('Payment Method'),
257 array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(),
258 TRUE,
259 array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);")
260 );
261
262 $this->add('text', 'check_number', ts('Check Number'), $attributes['financial_trxn_check_number']);
263 $this->add('text', 'trxn_id', ts('Transaction ID'), array('class' => 'twelve') + $attributes['trxn_id']);
264
265 $this->add('text', 'fee_amount', ts('Fee Amount'),
266 $attributes['fee_amount']
267 );
268 $this->addRule('fee_amount', ts('Please enter a valid monetary value for Fee Amount.'), 'money');
269
270 $this->add('text', 'net_amount', ts('Net Amount'),
271 $attributes['net_amount']
272 );
273 $this->addRule('net_amount', ts('Please enter a valid monetary value for Net Amount.'), 'money');
274 }
275
276 $buttonName = $this->_refund ? 'Record Refund' : 'Record Payment';
277 $this->addButtons(array(
278 array(
279 'type' => 'upload',
280 'name' => ts('%1', array(1 => $buttonName)),
281 'js' => $js,
282 'isDefault' => TRUE,
283 ),
284 array(
285 'type' => 'cancel',
286 'name' => ts('Cancel'),
287 ),
288 )
289 );
290 $mailingInfo = Civi::settings()->get('mailing_backend');
291 $this->assign('outBound_option', $mailingInfo['outBound_option']);
292
293 $this->addFormRule(array('CRM_Contribute_Form_AdditionalPayment', 'formRule'), $this);
294 }
295
296 /**
297 * @param $fields
298 * @param $files
299 * @param $self
300 *
301 * @return array
302 */
303 public static function formRule($fields, $files, $self) {
304 $errors = array();
305 if ($self->_paymentType == 'owed' && $fields['total_amount'] > $self->_owed) {
306 $errors['total_amount'] = ts('Payment amount cannot be greater than owed amount');
307 }
308 if ($self->_paymentType == 'refund' && $fields['total_amount'] != abs($self->_refund)) {
309 $errors['total_amount'] = ts('Refund amount must equal refund due amount.');
310 }
311 $netAmt = $fields['total_amount'] - CRM_Utils_Array::value('fee_amount', $fields, 0);
312 if (!empty($fields['net_amount']) && $netAmt != $fields['net_amount']) {
313 $errors['net_amount'] = ts('Net amount should be equal to the difference between payment amount and fee amount.');
314 }
315 if ($self->_paymentProcessor['id'] === 0 && empty($fields['payment_instrument_id'])) {
316 $errors['payment_instrument_id'] = ts('Payment method is a required field');
317 }
318
319 return $errors;
320 }
321
322 /**
323 * Process the form submission.
324 */
325 public function postProcess() {
326 $submittedValues = $this->controller->exportValues($this->_name);
327 $this->submit($submittedValues);
328 $childTab = 'contribute';
329 if ($this->_component == 'event') {
330 $childTab = 'participant';
331 }
332 $session = CRM_Core_Session::singleton();
333 $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view',
334 "reset=1&cid={$this->_contactId}&selectedChild={$childTab}"
335 ));
336 }
337
338 /**
339 * Process Payments.
340 * @param array $submittedValues
341 *
342 */
343 public function submit($submittedValues) {
344 $this->_params = $submittedValues;
345 $this->beginPostProcess();
346 $this->_contributorContactID = $this->_contactID;
347 $this->processBillingAddress();
348 $participantId = NULL;
349 if ($this->_component == 'event') {
350 $participantId = $this->_id;
351 }
352 $contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution',
353 'contribution_status_id',
354 array('labelColumn' => 'name')
355 );
356 $contributionStatusID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_contributionId, 'contribution_status_id');
357 if ($contributionStatuses[$contributionStatusID] == 'Pending') {
358 civicrm_api3('Contribution', 'create',
359 array(
360 'id' => $this->_contributionId,
361 'contribution_status_id' => array_search('Partially paid', $contributionStatuses),
362 'is_pay_later' => 0,
363 )
364 );
365 }
366
367 if ($this->_mode) {
368 // process credit card
369 $this->assign('contributeMode', 'direct');
370 $this->processCreditCard();
371 }
372
373 $defaults = array();
374 $contribution = civicrm_api3('Contribution', 'getsingle', array(
375 'return' => array("contribution_status_id"),
376 'id' => $this->_contributionId,
377 ));
378 $contributionStatusId = CRM_Utils_Array::value('contribution_status_id', $contribution);
379 $result = CRM_Contribute_BAO_Contribution::recordAdditionalPayment($this->_contributionId, $this->_params, $this->_paymentType, $participantId);
380 // Fetch the contribution & do proportional line item assignment
381 $params = array('id' => $this->_contributionId);
382 $contribution = CRM_Contribute_BAO_Contribution::retrieve($params, $defaults, $params);
383 CRM_Contribute_BAO_Contribution::addPayments(array($contribution), $contributionStatusId);
384 if ($this->_contributionId && CRM_Core_Permission::access('CiviMember')) {
385 $membershipPaymentCount = civicrm_api3('MembershipPayment', 'getCount', array('contribution_id' => $this->_contributionId));
386 if ($membershipPaymentCount) {
387 $this->ajaxResponse['updateTabs']['#tab_member'] = CRM_Contact_BAO_Contact::getCountComponent('membership', $this->_contactID);
388 }
389 }
390 if ($this->_contributionId && CRM_Core_Permission::access('CiviEvent')) {
391 $participantPaymentCount = civicrm_api3('ParticipantPayment', 'getCount', array('contribution_id' => $this->_contributionId));
392 if ($participantPaymentCount) {
393 $this->ajaxResponse['updateTabs']['#tab_participant'] = CRM_Contact_BAO_Contact::getCountComponent('participant', $this->_contactID);
394 }
395 }
396
397 $statusMsg = ts('The payment record has been processed.');
398 // send email
399 if (!empty($result) && !empty($this->_params['is_email_receipt'])) {
400 $this->_params['contact_id'] = $this->_contactId;
401 $this->_params['contribution_id'] = $this->_contributionId;
402 // to get 'from email id' for send receipt
403 $this->fromEmailId = $this->_params['from_email_address'];
404 $sendReceipt = $this->emailReceipt($this->_params);
405 if ($sendReceipt) {
406 $statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.');
407 }
408 }
409
410 CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success');
411 }
412
413 public function processCreditCard() {
414 $config = CRM_Core_Config::singleton();
415 $session = CRM_Core_Session::singleton();
416
417 $now = date('YmdHis');
418 $fields = array();
419
420 // we need to retrieve email address
421 if ($this->_context == 'standalone' && !empty($this->_params['is_email_receipt'])) {
422 list($this->userDisplayName,
423 $this->userEmail
424 ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactId);
425 $this->assign('displayName', $this->userDisplayName);
426 }
427
428 $this->formatParamsForPaymentProcessor($this->_params);
429
430 $this->_params['amount'] = $this->_params['total_amount'];
431 // @todo - stop setting amount level in this function & call the CRM_Price_BAO_PriceSet::getAmountLevel
432 // function to get correct amount level consistently. Remove setting of the amount level in
433 // CRM_Price_BAO_PriceSet::processAmount. Extend the unit tests in CRM_Price_BAO_PriceSetTest
434 // to cover all variants.
435 $this->_params['amount_level'] = 0;
436 $this->_params['currencyID'] = CRM_Utils_Array::value('currency',
437 $this->_params,
438 $config->defaultCurrency
439 );
440
441 if (!empty($this->_params['trxn_date'])) {
442 $this->_params['receive_date'] = $this->_params['trxn_date'];
443 }
444
445 if (empty($this->_params['receive_date'])) {
446 $this->_params['receive_date'] = date('YmdHis');
447 }
448
449 if (empty($this->_params['invoice_id'])) {
450 $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
451 }
452 else {
453 $this->_params['invoiceID'] = $this->_params['invoice_id'];
454 }
455
456 $this->assign('address', CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters(
457 $this->_params,
458 $this->_bltID
459 ));
460
461 //Add common data to formatted params
462 $params = $this->_params;
463 CRM_Contribute_Form_AdditionalInfo::postProcessCommon($params, $this->_params, $this);
464 // at this point we've created a contact and stored its address etc
465 // all the payment processors expect the name and address to be in the
466 // so we copy stuff over to first_name etc.
467 $paymentParams = $this->_params;
468 $paymentParams['contactID'] = $this->_contactId;
469 CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE);
470
471 $paymentParams['contributionPageID'] = NULL;
472 if (!empty($this->_params['is_email_receipt'])) {
473 $paymentParams['email'] = $this->_contributorEmail;
474 $paymentParams['is_email_receipt'] = TRUE;
475 }
476 else {
477 $paymentParams['is_email_receipt'] = $this->_params['is_email_receipt'] = FALSE;
478 }
479
480 $result = NULL;
481
482 if ($paymentParams['amount'] > 0.0) {
483 try {
484 // force a reget of the payment processor in case the form changed it, CRM-7179
485 $payment = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
486 $result = $payment->doPayment($paymentParams);
487 }
488 catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
489 Civi::log()->error('Payment processor exception: ' . $e->getMessage());
490 $urlParams = "action=add&cid={$this->_contactId}&id={$this->_contributionId}&component={$this->_component}&mode={$this->_mode}";
491 CRM_Core_Error::statusBounce(CRM_Utils_System::url($e->getMessage(), 'civicrm/payment/add', $urlParams));
492 }
493 }
494
495 if (!empty($result)) {
496 $this->_params = array_merge($this->_params, $result);
497 }
498
499 if (empty($this->_params['receive_date'])) {
500 $this->_params['receive_date'] = $now;
501 }
502
503 $this->set('params', $this->_params);
504
505 // set source if not set
506 if (empty($this->_params['source'])) {
507 $userID = $session->get('userID');
508 $userSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $userID,
509 'sort_name'
510 );
511 $this->_params['source'] = ts('Submit Credit Card Payment by: %1', array(1 => $userSortName));
512 }
513 }
514
515 /**
516 * Function to send email receipt.
517 *
518 * @param array $params
519 *
520 * @return bool
521 */
522 public function emailReceipt(&$params) {
523 // email receipt sending
524 // send message template
525 if ($this->_component == 'event') {
526
527 // fetch event information from participant ID using API
528 $eventId = civicrm_api3('Participant', 'getvalue', array(
529 'return' => "event_id",
530 'id' => $this->_id,
531 ));
532 $event = civicrm_api3('Event', 'getsingle', array('id' => $eventId));
533
534 $this->assign('event', $event);
535 $this->assign('isShowLocation', $event['is_show_location']);
536 if (CRM_Utils_Array::value('is_show_location', $event) == 1) {
537 $locationParams = array(
538 'entity_id' => $eventId,
539 'entity_table' => 'civicrm_event',
540 );
541 $location = CRM_Core_BAO_Location::getValues($locationParams, TRUE);
542 $this->assign('location', $location);
543 }
544 }
545
546 // assign payment info here
547 $paymentConfig['confirm_email_text'] = CRM_Utils_Array::value('confirm_email_text', $params);
548 $this->assign('paymentConfig', $paymentConfig);
549
550 $this->assign('totalAmount', $this->_amtTotal);
551
552 $isRefund = ($this->_paymentType == 'refund') ? TRUE : FALSE;
553 $this->assign('isRefund', $isRefund);
554 if ($isRefund) {
555 $this->assign('totalPaid', $this->_amtPaid);
556 $this->assign('refundAmount', $params['total_amount']);
557 }
558 else {
559 $balance = $this->_amtTotal - ($this->_amtPaid + $params['total_amount']);
560 $paymentsComplete = ($balance == 0) ? 1 : 0;
561 $this->assign('amountOwed', $balance);
562 $this->assign('paymentAmount', $params['total_amount']);
563 $this->assign('paymentsComplete', $paymentsComplete);
564 }
565 $this->assign('contactDisplayName', $this->_contributorDisplayName);
566
567 // assign trxn details
568 $this->assign('trxn_id', CRM_Utils_Array::value('trxn_id', $params));
569 $this->assign('receive_date', CRM_Utils_Array::value('trxn_date', $params));
570 $this->assign('paidBy', CRM_Core_PseudoConstant::getLabel(
571 'CRM_Contribute_BAO_Contribution',
572 'payment_instrument_id',
573 $params['payment_instrument_id']
574 ));
575 $this->assign('checkNumber', CRM_Utils_Array::value('check_number', $params));
576
577 $sendTemplateParams = array(
578 'groupName' => 'msg_tpl_workflow_contribution',
579 'valueName' => 'payment_or_refund_notification',
580 'contactId' => $this->_contactId,
581 'PDFFilename' => ts('notification') . '.pdf',
582 );
583
584 // try to send emails only if email id is present
585 // and the do-not-email option is not checked for that contact
586 if ($this->_contributorEmail && !$this->_toDoNotEmail) {
587 if (array_key_exists($params['from_email_address'], $this->_fromEmails['from_email_id'])) {
588 $receiptFrom = $params['from_email_address'];
589 }
590
591 $sendTemplateParams['from'] = $receiptFrom;
592 $sendTemplateParams['toName'] = $this->_contributorDisplayName;
593 $sendTemplateParams['toEmail'] = $this->_contributorEmail;
594 }
595 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
596 return $mailSent;
597 }
598
599 /**
600 * Wrapper for unit testing the post process submit function.
601 *
602 * @param array $params
603 * @param string|null $creditCardMode
604 * @param string $entityType
605 *
606 * @throws \CiviCRM_API3_Exception
607 */
608 public function testSubmit($params, $creditCardMode = NULL, $entityType = 'contribute') {
609 $this->_bltID = 5;
610 // Required because processCreditCard calls set method on this.
611 $_SERVER['REQUEST_METHOD'] = 'GET';
612 $this->controller = new CRM_Core_Controller();
613
614 $this->assignPaymentRelatedVariables();
615
616 if (!empty($params['contribution_id'])) {
617 $this->_contributionId = $params['contribution_id'];
618
619 $paymentInfo = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($this->_contributionId, $entityType);
620 $paymentDetails = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_contributionId, $entityType, FALSE, TRUE);
621
622 $this->_amtPaid = $paymentDetails['paid'];
623 $this->_amtTotal = $paymentDetails['total'];
624
625 if (!empty($paymentInfo['refund_due'])) {
626 $this->_refund = $paymentInfo['refund_due'];
627 $this->_paymentType = 'refund';
628 }
629 elseif (!empty($paymentInfo['amount_owed'])) {
630 $this->_owed = $paymentInfo['amount_owed'];
631 $this->_paymentType = 'owed';
632 }
633 }
634
635 if (!empty($params['contact_id'])) {
636 $this->_contactId = $params['contact_id'];
637 }
638
639 if ($creditCardMode) {
640 $this->_mode = $creditCardMode;
641 }
642
643 $this->_fields = array();
644 $this->set('cid', $this->_contactId);
645 parent::preProcess();
646 $this->submit($params);
647 }
648
649 }