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