CRM-16555 move paypal code addition to buildForm
[civicrm-core.git] / CRM / Core / Payment.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 use Civi\Payment\System;
29 use Civi\Payment\Exception\PaymentProcessorException;
30
31 /**
32 * Class CRM_Core_Payment.
33 *
34 * This class is the main class for the payment processor subsystem.
35 *
36 * It is the parent class for payment processors. It also holds some IPN related functions
37 * that need to be moved. In particular handlePaymentMethod should be moved to a factory class.
38 */
39 abstract class CRM_Core_Payment {
40
41 /**
42 * How are we getting billing information?
43 *
44 * FORM - we collect it on the same page
45 * BUTTON - the processor collects it and sends it back to us via some protocol
46 */
47 const
48 BILLING_MODE_FORM = 1,
49 BILLING_MODE_BUTTON = 2,
50 BILLING_MODE_NOTIFY = 4;
51
52 /**
53 * Which payment type(s) are we using?
54 *
55 * credit card
56 * direct debit
57 * or both
58 * @todo create option group - nb omnipay uses a 3rd type - transparent redirect cc
59 */
60 const
61 PAYMENT_TYPE_CREDIT_CARD = 1,
62 PAYMENT_TYPE_DIRECT_DEBIT = 2;
63
64 /**
65 * Subscription / Recurring payment Status
66 * START, END
67 */
68 const
69 RECURRING_PAYMENT_START = 'START',
70 RECURRING_PAYMENT_END = 'END';
71
72 protected $_paymentProcessor;
73
74 /**
75 * Singleton function used to manage this object.
76 *
77 * We will migrate to calling Civi\Payment\System::singleton()->getByProcessor($paymentProcessor)
78 * & Civi\Payment\System::singleton()->getById($paymentProcessor) directly as the main access methods & work
79 * to remove this function all together
80 *
81 * @param string $mode
82 * The mode of operation: live or test.
83 * @param array $paymentProcessor
84 * The details of the payment processor being invoked.
85 * @param object $paymentForm
86 * Deprecated - avoid referring to this if possible. If you have to use it document why as this is scary interaction.
87 * @param bool $force
88 * Should we force a reload of this payment object.
89 *
90 * @return CRM_Core_Payment
91 * @throws \CRM_Core_Exception
92 */
93 public static function singleton($mode = 'test', &$paymentProcessor, &$paymentForm = NULL, $force = FALSE) {
94 // make sure paymentProcessor is not empty
95 // CRM-7424
96 if (empty($paymentProcessor)) {
97 return CRM_Core_DAO::$_nullObject;
98 }
99 //we use two lines because we can't remove the '&singleton' without risking breakage
100 //of extension classes that extend this one
101 $object = Civi\Payment\System::singleton()->getByProcessor($paymentProcessor);
102 return $object;
103 }
104
105 /**
106 * Opportunity for the payment processor to override the entire form build.
107 *
108 * @param CRM_Core_Form $form
109 *
110 * @return bool
111 * Should form building stop at this point?
112 */
113 public function buildForm(&$form) {
114 return FALSE;
115 }
116
117 /**
118 * Log payment notification message to forensic system log.
119 *
120 * @todo move to factory class \Civi\Payment\System (or similar)
121 *
122 * @param array $params
123 *
124 * @return mixed
125 */
126 public static function logPaymentNotification($params) {
127 $message = 'payment_notification ';
128 if (!empty($params['processor_name'])) {
129 $message .= 'processor_name=' . $params['processor_name'];
130 }
131 if (!empty($params['processor_id'])) {
132 $message .= 'processor_id=' . $params['processor_id'];
133 }
134
135 $log = new CRM_Utils_SystemLogger();
136 $log->alert($message, $_REQUEST);
137 }
138
139 /**
140 * Check if capability is supported.
141 *
142 * Capabilities have a one to one relationship with capability-related functions on this class.
143 *
144 * Payment processor classes should over-ride the capability-specific function rather than this one.
145 *
146 * @param string $capability
147 * E.g BackOffice, LiveMode, FutureRecurStartDate.
148 *
149 * @return bool
150 */
151 public function supports($capability) {
152 $function = 'supports' . ucfirst($capability);
153 if (method_exists($this, $function)) {
154 return $this->$function();
155 }
156 return FALSE;
157 }
158
159 /**
160 * Are back office payments supported.
161 *
162 * e.g paypal standard won't permit you to enter a credit card associated
163 * with someone else's login.
164 * The intention is to support off-site (other than paypal) & direct debit but that is not all working yet so to
165 * reach a 'stable' point we disable.
166 *
167 * @return bool
168 */
169 protected function supportsBackOffice() {
170 if ($this->_paymentProcessor['billing_mode'] == 4 || $this->_paymentProcessor['payment_type'] != 1) {
171 return FALSE;
172 }
173 else {
174 return TRUE;
175 }
176 }
177
178 /**
179 * Can more than one transaction be processed at once?
180 *
181 * In general processors that process payment by server to server communication support this while others do not.
182 *
183 * In future we are likely to hit an issue where this depends on whether a token already exists.
184 *
185 * @return bool
186 */
187 protected function supportsMultipleConcurrentPayments() {
188 if ($this->_paymentProcessor['billing_mode'] == 4 || $this->_paymentProcessor['payment_type'] != 1) {
189 return FALSE;
190 }
191 else {
192 return TRUE;
193 }
194 }
195
196 /**
197 * Are live payments supported - e.g dummy doesn't support this.
198 *
199 * @return bool
200 */
201 protected function supportsLiveMode() {
202 return TRUE;
203 }
204
205 /**
206 * Are test payments supported.
207 *
208 * @return bool
209 */
210 protected function supportsTestMode() {
211 return TRUE;
212 }
213
214 /**
215 * Should the first payment date be configurable when setting up back office recurring payments.
216 *
217 * We set this to false for historical consistency but in fact most new processors use tokens for recurring and can support this
218 *
219 * @return bool
220 */
221 protected function supportsFutureRecurStartDate() {
222 return FALSE;
223 }
224
225 /**
226 * Default payment instrument validation.
227 *
228 * Implement the usual Luhn algorithm via a static function in the CRM_Core_Payment_Form if it's a credit card
229 * Not a static function, because I need to check for payment_type.
230 *
231 * @param array $values
232 * @param array $errors
233 */
234 public function validatePaymentInstrument($values, &$errors) {
235 if ($this->_paymentProcessor['payment_type'] == 1) {
236 CRM_Core_Payment_Form::validateCreditCard($values, $errors);
237 }
238 }
239
240 /**
241 * Getter for the payment processor.
242 *
243 * The payment processor array is based on the civicrm_payment_processor table entry.
244 *
245 * @return array
246 * Payment processor array.
247 */
248 public function getPaymentProcessor() {
249 return $this->_paymentProcessor;
250 }
251
252 /**
253 * Setter for the payment processor.
254 *
255 * @param array $processor
256 */
257 public function setPaymentProcessor($processor) {
258 $this->_paymentProcessor = $processor;
259 }
260
261 /**
262 * Setter for the payment form that wants to use the processor.
263 *
264 * @deprecated
265 *
266 * @param CRM_Core_Form $paymentForm
267 */
268 public function setForm(&$paymentForm) {
269 $this->_paymentForm = $paymentForm;
270 }
271
272 /**
273 * Getter for payment form that is using the processor.
274 * @deprecated
275 * @return CRM_Core_Form
276 * A form object
277 */
278 public function getForm() {
279 return $this->_paymentForm;
280 }
281
282 /**
283 * Getter for accessing member vars.
284 *
285 * @todo believe this is unused
286 *
287 * @param string $name
288 *
289 * @return null
290 */
291 public function getVar($name) {
292 return isset($this->$name) ? $this->$name : NULL;
293 }
294
295 /**
296 * Get name for the payment information type.
297 * @todo - use option group + name field (like Omnipay does)
298 * @return string
299 */
300 public function getPaymentTypeName() {
301 return $this->_paymentProcessor['payment_type'] == 1 ? 'credit_card' : 'direct_debit';
302 }
303
304 /**
305 * Get label for the payment information type.
306 * @todo - use option group + labels (like Omnipay does)
307 * @return string
308 */
309 public function getPaymentTypeLabel() {
310 return $this->_paymentProcessor['payment_type'] == 1 ? 'Credit Card' : 'Direct Debit';
311 }
312
313 /**
314 * Get array of fields that should be displayed on the payment form.
315 * @todo make payment type an option value & use it in the function name - currently on debit & credit card work
316 * @return array
317 * @throws CiviCRM_API3_Exception
318 */
319 public function getPaymentFormFields() {
320 if ($this->_paymentProcessor['billing_mode'] == 4) {
321 return array();
322 }
323 return $this->_paymentProcessor['payment_type'] == 1 ? $this->getCreditCardFormFields() : $this->getDirectDebitFormFields();
324 }
325
326 /**
327 * Get array of fields that should be displayed on the payment form for credit cards.
328 *
329 * @return array
330 */
331 protected function getCreditCardFormFields() {
332 return array(
333 'credit_card_type',
334 'credit_card_number',
335 'cvv2',
336 'credit_card_exp_date',
337 );
338 }
339
340 /**
341 * Get array of fields that should be displayed on the payment form for direct debits.
342 *
343 * @return array
344 */
345 protected function getDirectDebitFormFields() {
346 return array(
347 'account_holder',
348 'bank_account_number',
349 'bank_identification_number',
350 'bank_name',
351 );
352 }
353
354 /**
355 * Return an array of all the details about the fields potentially required for payment fields.
356 *
357 * Only those determined by getPaymentFormFields will actually be assigned to the form
358 *
359 * @return array
360 * field metadata
361 */
362 public function getPaymentFormFieldsMetadata() {
363 //@todo convert credit card type into an option value
364 $creditCardType = array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::creditCard();
365 return array(
366 'credit_card_number' => array(
367 'htmlType' => 'text',
368 'name' => 'credit_card_number',
369 'title' => ts('Card Number'),
370 'cc_field' => TRUE,
371 'attributes' => array(
372 'size' => 20,
373 'maxlength' => 20,
374 'autocomplete' => 'off',
375 'class' => 'creditcard',
376 ),
377 'is_required' => TRUE,
378 ),
379 'cvv2' => array(
380 'htmlType' => 'text',
381 'name' => 'cvv2',
382 'title' => ts('Security Code'),
383 'cc_field' => TRUE,
384 'attributes' => array(
385 'size' => 5,
386 'maxlength' => 10,
387 'autocomplete' => 'off',
388 ),
389 'is_required' => CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,
390 'cvv_backoffice_required',
391 NULL,
392 1
393 ),
394 'rules' => array(
395 array(
396 'rule_message' => ts('Please enter a valid value for your card security code. This is usually the last 3-4 digits on the card\'s signature panel.'),
397 'rule_name' => 'integer',
398 'rule_parameters' => NULL,
399 ),
400 ),
401 ),
402 'credit_card_exp_date' => array(
403 'htmlType' => 'date',
404 'name' => 'credit_card_exp_date',
405 'title' => ts('Expiration Date'),
406 'cc_field' => TRUE,
407 'attributes' => CRM_Core_SelectValues::date('creditCard'),
408 'is_required' => TRUE,
409 'rules' => array(
410 array(
411 'rule_message' => ts('Card expiration date cannot be a past date.'),
412 'rule_name' => 'currentDate',
413 'rule_parameters' => TRUE,
414 ),
415 ),
416 ),
417 'credit_card_type' => array(
418 'htmlType' => 'select',
419 'name' => 'credit_card_type',
420 'title' => ts('Card Type'),
421 'cc_field' => TRUE,
422 'attributes' => $creditCardType,
423 'is_required' => FALSE,
424 ),
425 'account_holder' => array(
426 'htmlType' => 'text',
427 'name' => 'account_holder',
428 'title' => ts('Account Holder'),
429 'cc_field' => TRUE,
430 'attributes' => array(
431 'size' => 20,
432 'maxlength' => 34,
433 'autocomplete' => 'on',
434 ),
435 'is_required' => TRUE,
436 ),
437 //e.g. IBAN can have maxlength of 34 digits
438 'bank_account_number' => array(
439 'htmlType' => 'text',
440 'name' => 'bank_account_number',
441 'title' => ts('Bank Account Number'),
442 'cc_field' => TRUE,
443 'attributes' => array(
444 'size' => 20,
445 'maxlength' => 34,
446 'autocomplete' => 'off',
447 ),
448 'rules' => array(
449 array(
450 'rule_message' => ts('Please enter a valid Bank Identification Number (value must not contain punctuation characters).'),
451 'rule_name' => 'nopunctuation',
452 'rule_parameters' => NULL,
453 ),
454 ),
455 'is_required' => TRUE,
456 ),
457 //e.g. SWIFT-BIC can have maxlength of 11 digits
458 'bank_identification_number' => array(
459 'htmlType' => 'text',
460 'name' => 'bank_identification_number',
461 'title' => ts('Bank Identification Number'),
462 'cc_field' => TRUE,
463 'attributes' => array(
464 'size' => 20,
465 'maxlength' => 11,
466 'autocomplete' => 'off',
467 ),
468 'is_required' => TRUE,
469 'rules' => array(
470 array(
471 'rule_message' => ts('Please enter a valid Bank Identification Number (value must not contain punctuation characters).'),
472 'rule_name' => 'nopunctuation',
473 'rule_parameters' => NULL,
474 ),
475 ),
476 ),
477 'bank_name' => array(
478 'htmlType' => 'text',
479 'name' => 'bank_name',
480 'title' => ts('Bank Name'),
481 'cc_field' => TRUE,
482 'attributes' => array(
483 'size' => 20,
484 'maxlength' => 64,
485 'autocomplete' => 'off',
486 ),
487 'is_required' => TRUE,
488
489 ),
490 );
491 }
492
493 /**
494 * Calling this from outside the payment subsystem is deprecated - use doPayment.
495 *
496 * Does a server to server payment transaction.
497 *
498 * Note that doPayment will throw an exception so the code may need to be modified
499 *
500 * @param array $params
501 * Assoc array of input parameters for this transaction.
502 *
503 * @return array
504 * the result in an nice formatted array (or an error object)
505 * @abstract
506 */
507 abstract protected function doDirectPayment(&$params);
508
509 /**
510 * Process payment - this function wraps around both doTransferPayment and doDirectPayment.
511 *
512 * The function ensures an exception is thrown & moves some of this logic out of the form layer and makes the forms
513 * more agnostic.
514 *
515 * Payment processors should set contribution_status_id. This function adds some historical defaults ie. the
516 * assumption that if a 'doDirectPayment' processors comes back it completed the transaction & in fact
517 * doTransferCheckout would not traditionally come back.
518 *
519 * doDirectPayment does not do an immediate payment for Authorize.net or Paypal so the default is assumed
520 * to be Pending.
521 *
522 * @param array $params
523 *
524 * @param string $component
525 *
526 * @return array
527 * Result array
528 *
529 * @throws \Civi\Payment\Exception\PaymentProcessorException
530 */
531 public function doPayment(&$params, $component = 'contribute') {
532 $statuses = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id');
533 if ($this->_paymentProcessor['billing_mode'] == 4) {
534 $result = $this->doTransferCheckout($params, $component);
535 if (is_array($result) && !isset($result['contribution_status_id'])) {
536 $result['contribution_status_id'] = array_search('Pending', $statuses);
537 }
538 }
539 else {
540 $result = $this->doDirectPayment($params, $component);
541 if (is_array($result) && !isset($result['contribution_status_id'])) {
542 if (!empty($params['is_recur'])) {
543 // See comment block.
544 $paymentParams['contribution_status_id'] = array_search('Pending', $statuses);
545 }
546 else {
547 $result['contribution_status_id'] = array_search('Completed', $statuses);
548 }
549 }
550 }
551 if (is_a($result, 'CRM_Core_Error')) {
552 throw new PaymentProcessorException(CRM_Core_Error::getMessages($result));
553 }
554 return $result;
555 }
556
557 /**
558 * This function checks to see if we have the right config values.
559 *
560 * @return string
561 * the error message if any
562 */
563 abstract protected function checkConfig();
564
565 /**
566 * Redirect for paypal.
567 *
568 * @todo move to paypal class or remove
569 *
570 * @param $paymentProcessor
571 *
572 * @return bool
573 */
574 public static function paypalRedirect(&$paymentProcessor) {
575 if (!$paymentProcessor) {
576 return FALSE;
577 }
578
579 if (isset($_GET['payment_date']) &&
580 isset($_GET['merchant_return_link']) &&
581 CRM_Utils_Array::value('payment_status', $_GET) == 'Completed' &&
582 $paymentProcessor['payment_processor_type'] == "PayPal_Standard"
583 ) {
584 return TRUE;
585 }
586
587 return FALSE;
588 }
589
590 /**
591 * Handle incoming payment notification.
592 *
593 * IPNs, also called silent posts are notifications of payment outcomes or activity on an external site.
594 *
595 * @todo move to0 \Civi\Payment\System factory method
596 * Page callback for civicrm/payment/ipn
597 */
598 public static function handleIPN() {
599 self::handlePaymentMethod(
600 'PaymentNotification',
601 array(
602 'processor_name' => @$_GET['processor_name'],
603 'processor_id' => @$_GET['processor_id'],
604 'mode' => @$_GET['mode'],
605 'q' => @$_GET['q'],
606 )
607 );
608 CRM_Utils_System::civiExit();
609 }
610
611 /**
612 * Payment callback handler.
613 *
614 * The processor_name or processor_id is passed in.
615 * Note that processor_id is more reliable as one site may have more than one instance of a
616 * processor & ideally the processor will be validating the results
617 * Load requested payment processor and call that processor's handle<$method> method
618 *
619 * @todo move to \Civi\Payment\System factory method
620 *
621 * @param string $method
622 * 'PaymentNotification' or 'PaymentCron'
623 * @param array $params
624 */
625 public static function handlePaymentMethod($method, $params = array()) {
626 if (!isset($params['processor_id']) && !isset($params['processor_name'])) {
627 $q = explode('/', CRM_Utils_Array::value('q', $params, ''));
628 $lastParam = array_pop($q);
629 if (is_numeric($lastParam)) {
630 $params['processor_id'] = $_GET['processor_id'] = $lastParam;
631 }
632 else {
633 throw new CRM_Core_Exception("Either 'processor_id' or 'processor_name' param is required for payment callback");
634 }
635 }
636
637 self::logPaymentNotification($params);
638
639 $sql = "SELECT ppt.class_name, ppt.name as processor_name, pp.id AS processor_id
640 FROM civicrm_payment_processor_type ppt
641 INNER JOIN civicrm_payment_processor pp
642 ON pp.payment_processor_type_id = ppt.id
643 AND pp.is_active";
644
645 if (isset($params['processor_id'])) {
646 $sql .= " WHERE pp.id = %2";
647 $args[2] = array($params['processor_id'], 'Integer');
648 $notFound = "No active instances of payment processor ID#'{$params['processor_id']}' were found.";
649 }
650 else {
651 // This is called when processor_name is passed - passing processor_id instead is recommended.
652 $sql .= " WHERE ppt.name = %2 AND pp.is_test = %1";
653 $args[1] = array(
654 (CRM_Utils_Array::value('mode', $params) == 'test') ? 1 : 0,
655 'Integer',
656 );
657 $args[2] = array($params['processor_name'], 'String');
658 $notFound = "No active instances of the '{$params['processor_name']}' payment processor were found.";
659 }
660
661 $dao = CRM_Core_DAO::executeQuery($sql, $args);
662
663 // Check whether we found anything at all.
664 if (!$dao->N) {
665 CRM_Core_Error::fatal($notFound);
666 }
667
668 $method = 'handle' . $method;
669 $extension_instance_found = FALSE;
670
671 // In all likelihood, we'll just end up with the one instance returned here. But it's
672 // possible we may get more. Hence, iterate through all instances ..
673
674 while ($dao->fetch()) {
675 // Check pp is extension
676 $ext = CRM_Extension_System::singleton()->getMapper();
677 if ($ext->isExtensionKey($dao->class_name)) {
678 $paymentClass = $ext->keyToClass($dao->class_name, 'payment');
679 require_once $ext->classToPath($paymentClass);
680 }
681 else {
682 // Legacy or extension as module instance
683 $paymentClass = 'CRM_Core_' . $dao->class_name;
684 }
685
686 $processorInstance = Civi\Payment\System::singleton()->getById($dao->processor_id);
687
688 // Should never be empty - we already established this processor_id exists and is active.
689 if (empty($processorInstance)) {
690 continue;
691 }
692
693 // Does PP implement this method, and can we call it?
694 if (!method_exists($processorInstance, $method) ||
695 !is_callable(array($processorInstance, $method))
696 ) {
697 // on the off chance there is a double implementation of this processor we should keep looking for another
698 // note that passing processor_id is more reliable & we should work to deprecate processor_name
699 continue;
700 }
701
702 // Everything, it seems, is ok - execute pp callback handler
703 $processorInstance->$method();
704 $extension_instance_found = TRUE;
705 }
706
707 if (!$extension_instance_found) {
708 CRM_Core_Error::fatal(
709 "No extension instances of the '{$params['processor_name']}' payment processor were found.<br />" .
710 "$method method is unsupported in legacy payment processors."
711 );
712 }
713 }
714
715 /**
716 * Check whether a method is present ( & supported ) by the payment processor object.
717 *
718 * @param string $method
719 * Method to check for.
720 *
721 * @return bool
722 */
723 public function isSupported($method = 'cancelSubscription') {
724 return method_exists(CRM_Utils_System::getClassName($this), $method);
725 }
726
727 /**
728 * Some processors replace the form submit button with their own.
729 *
730 * Returning false here will leave the button off front end forms.
731 *
732 * At this stage there is zero cross-over between back-office processors and processors that suppress the submit.
733 */
734 public function isSuppressSubmitButtons() {
735 return FALSE;
736 }
737
738 /**
739 * Get url for users to manage this recurring contribution for this processor.
740 *
741 * @param int $entityID
742 * @param null $entity
743 * @param string $action
744 *
745 * @return string
746 */
747 public function subscriptionURL($entityID = NULL, $entity = NULL, $action = 'cancel') {
748 // Set URL
749 switch ($action) {
750 case 'cancel':
751 $url = 'civicrm/contribute/unsubscribe';
752 break;
753
754 case 'billing':
755 //in notify mode don't return the update billing url
756 if (!$this->isSupported('updateSubscriptionBillingInfo')) {
757 return NULL;
758 }
759 $url = 'civicrm/contribute/updatebilling';
760 break;
761
762 case 'update':
763 $url = 'civicrm/contribute/updaterecur';
764 break;
765 }
766
767 $session = CRM_Core_Session::singleton();
768 $userId = $session->get('userID');
769 $contactID = 0;
770 $checksumValue = '';
771 $entityArg = '';
772
773 // Find related Contact
774 if ($entityID) {
775 switch ($entity) {
776 case 'membership':
777 $contactID = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $entityID, "contact_id");
778 $entityArg = 'mid';
779 break;
780
781 case 'contribution':
782 $contactID = CRM_Core_DAO::getFieldValue("CRM_Contribute_DAO_Contribution", $entityID, "contact_id");
783 $entityArg = 'coid';
784 break;
785
786 case 'recur':
787 $sql = "
788 SELECT con.contact_id
789 FROM civicrm_contribution_recur rec
790 INNER JOIN civicrm_contribution con ON ( con.contribution_recur_id = rec.id )
791 WHERE rec.id = %1
792 GROUP BY rec.id";
793 $contactID = CRM_Core_DAO::singleValueQuery($sql, array(1 => array($entityID, 'Integer')));
794 $entityArg = 'crid';
795 break;
796 }
797 }
798
799 // Add entity arguments
800 if ($entityArg != '') {
801 // Add checksum argument
802 if ($contactID != 0 && $userId != $contactID) {
803 $checksumValue = '&cs=' . CRM_Contact_BAO_Contact_Utils::generateChecksum($contactID, NULL, 'inf');
804 }
805 return CRM_Utils_System::url($url, "reset=1&{$entityArg}={$entityID}{$checksumValue}", TRUE, NULL, FALSE, TRUE);
806 }
807
808 // Else login URL
809 if ($this->isSupported('accountLoginURL')) {
810 return $this->accountLoginURL();
811 }
812
813 // Else default
814 return $this->_paymentProcessor['url_recur'];
815 }
816
817 }