Merge pull request #4896 from totten/master-movedep
[civicrm-core.git] / CRM / Core / Payment.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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
914a49bf 28use Civi\Payment\System;
353ffa53 29
6a488035
TO
30/**
31 *
32 * @package CRM
06b69b18 33 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
34 * $Id$
35 *
36 */
6a488035
TO
37abstract class CRM_Core_Payment {
38
39 /**
100fef9d 40 * How are we getting billing information?
6a488035
TO
41 *
42 * FORM - we collect it on the same page
43 * BUTTON - the processor collects it and sends it back to us via some protocol
44 */
7da04cde 45 const
6a488035
TO
46 BILLING_MODE_FORM = 1,
47 BILLING_MODE_BUTTON = 2,
48 BILLING_MODE_NOTIFY = 4;
49
50 /**
100fef9d 51 * Which payment type(s) are we using?
6a488035
TO
52 *
53 * credit card
54 * direct debit
55 * or both
43e5f0f6 56 * @todo create option group - nb omnipay uses a 3rd type - transparent redirect cc
6a488035 57 */
7da04cde 58 const
6a488035
TO
59 PAYMENT_TYPE_CREDIT_CARD = 1,
60 PAYMENT_TYPE_DIRECT_DEBIT = 2;
61
62 /**
63 * Subscription / Recurring payment Status
64 * START, END
6a488035 65 */
7da04cde 66 const
6a488035
TO
67 RECURRING_PAYMENT_START = 'START',
68 RECURRING_PAYMENT_END = 'END';
69
353ffa53 70 protected $_paymentProcessor;
6a488035
TO
71
72 /**
100fef9d 73 * Singleton function used to manage this object
914a49bf
EM
74 * We will migrate to calling Civi\Payment\System::singleton()->getByProcessor($paymentProcessor)
75 * & Civi\Payment\System::singleton()->getById($paymentProcessor) directly as the main access methods & work
76 * to remove this function all together
6a488035 77 *
6a0b768e
TO
78 * @param string $mode
79 * The mode of operation: live or test.
80 * @param array $paymentProcessor
81 * The details of the payment processor being invoked.
82 * @param object $paymentForm
83 * Deprecated - avoid referring to this if possible. If you have to use it document why as this is scary interaction.
84 * @param bool $force
85 * Should we force a reload of this payment object.
86 *
87 * @return CRM_Core_Payment
52767de0 88 * @throws \CRM_Core_Exception
6a488035 89 * @static
6a488035 90 */
00be9182 91 public static function &singleton($mode = 'test', &$paymentProcessor, &$paymentForm = NULL, $force = FALSE) {
6a488035
TO
92 // make sure paymentProcessor is not empty
93 // CRM-7424
94 if (empty($paymentProcessor)) {
95 return CRM_Core_DAO::$_nullObject;
96 }
ef1c2283
EM
97 //we use two lines because we can't remove the '&singleton' without risking breakage
98 //of extension classes that extend this one
353ffa53 99 $object = Civi\Payment\System::singleton()->getByProcessor($paymentProcessor);
ef1c2283 100 return $object;
6a488035
TO
101 }
102
e2bef985 103 /**
c490a46a 104 * @param array $params
43e5f0f6 105 * @todo move to factory class \Civi\Payment\System (or similar)
e2bef985 106 * @return mixed
107 */
108 public static function logPaymentNotification($params) {
414e3596 109 $message = 'payment_notification ';
e2bef985 110 if (!empty($params['processor_name'])) {
414e3596 111 $message .= 'processor_name=' . $params['processor_name'];
e2bef985 112 }
113 if (!empty($params['processor_id'])) {
114 $message .= 'processor_id=' . $params['processor_id'];
115 }
414e3596 116
117 $log = new CRM_Utils_SystemLogger();
118 $log->alert($message, $_REQUEST);
e2bef985 119 }
120
fbcb6fba 121 /**
100fef9d 122 * Check if capability is supported
6a0b768e
TO
123 * @param string $capability
124 * E.g BackOffice, LiveMode, FutureRecurStartDate.
fbcb6fba
EM
125 *
126 * @return bool
127 */
128 public function supports($capability) {
129 $function = 'supports' . ucfirst($capability);
130 if (method_exists($this, $function)) {
131 return $this->$function();
132 }
133 return FALSE;
134 }
135
136 /**
100fef9d 137 * Are back office payments supported - e.g paypal standard won't permit you to enter a credit card associated with someone else's login
9c39fb25 138 * The intention is to support off-site (other than paypal) & direct debit but that is not all working yet so to reach a 'stable' point we disable
fbcb6fba
EM
139 * @return bool
140 */
d8ce0d68 141 protected function supportsBackOffice() {
9c39fb25
EM
142 if ($this->_paymentProcessor['billing_mode'] == 4 || $this->_paymentProcessor['payment_type'] != 1) {
143 return FALSE;
144 }
145 else {
146 return TRUE;
147 }
fbcb6fba
EM
148 }
149
150 /**
52767de0 151 * Are live payments supported - e.g dummy doesn't support this
fbcb6fba
EM
152 * @return bool
153 */
d8ce0d68 154 protected function supportsLiveMode() {
fbcb6fba
EM
155 return TRUE;
156 }
157
52767de0
EM
158 /**
159 * Are test payments supported
160 * @return bool
161 */
162 protected function supportsTestMode() {
163 return TRUE;
164 }
165
fbcb6fba 166 /**
100fef9d 167 * Should the first payment date be configurable when setting up back office recurring payments
fbcb6fba
EM
168 * We set this to false for historical consistency but in fact most new processors use tokens for recurring and can support this
169 * @return bool
170 */
d8ce0d68 171 protected function supportsFutureRecurStartDate() {
fbcb6fba
EM
172 return FALSE;
173 }
174
6a488035
TO
175 /**
176 * Setter for the payment form that wants to use the processor
43e5f0f6 177 * @deprecated
ac32ed13 178 * @param CRM_Core_Form $paymentForm
6a488035 179 */
00be9182 180 public function setForm(&$paymentForm) {
6a488035
TO
181 $this->_paymentForm = $paymentForm;
182 }
183
184 /**
185 * Getter for payment form that is using the processor
43e5f0f6 186 * @deprecated
ac32ed13 187 * @return CRM_Core_Form A form object
6a488035 188 */
00be9182 189 public function getForm() {
6a488035
TO
190 return $this->_paymentForm;
191 }
192
193 /**
194 * Getter for accessing member vars
43e5f0f6 195 * @todo believe this is unused
100fef9d 196 * @param string $name
dc913073
EM
197 *
198 * @return null
6a488035 199 */
00be9182 200 public function getVar($name) {
6a488035
TO
201 return isset($this->$name) ? $this->$name : NULL;
202 }
203
dc913073 204 /**
100fef9d 205 * Get name for the payment information type
43e5f0f6 206 * @todo - use option group + name field (like Omnipay does)
dc913073
EM
207 * @return string
208 */
209 public function getPaymentTypeName() {
459091e1 210 return $this->_paymentProcessor['payment_type'] == 1 ? 'credit_card' : 'direct_debit';
dc913073
EM
211 }
212
213 /**
100fef9d 214 * Get label for the payment information type
43e5f0f6 215 * @todo - use option group + labels (like Omnipay does)
dc913073
EM
216 * @return string
217 */
218 public function getPaymentTypeLabel() {
459091e1 219 return $this->_paymentProcessor['payment_type'] == 1 ? 'Credit Card' : 'Direct Debit';
dc913073
EM
220 }
221
44b6505d 222 /**
100fef9d 223 * Get array of fields that should be displayed on the payment form
44b6505d
EM
224 * @todo make payment type an option value & use it in the function name - currently on debit & credit card work
225 * @return array
226 * @throws CiviCRM_API3_Exception
227 */
228 public function getPaymentFormFields() {
dc913073 229 if ($this->_paymentProcessor['billing_mode'] == 4) {
44b6505d
EM
230 return array();
231 }
232 return $this->_paymentProcessor['payment_type'] == 1 ? $this->getCreditCardFormFields() : $this->getDirectDebitFormFields();
233 }
234
235 /**
100fef9d 236 * Get array of fields that should be displayed on the payment form for credit cards
dc913073 237 *
44b6505d
EM
238 * @return array
239 */
240 protected function getCreditCardFormFields() {
241 return array(
242 'credit_card_type',
243 'credit_card_number',
244 'cvv2',
245 'credit_card_exp_date',
246 );
247 }
248
249 /**
100fef9d 250 * Get array of fields that should be displayed on the payment form for direct debits
dc913073 251 *
44b6505d
EM
252 * @return array
253 */
254 protected function getDirectDebitFormFields() {
255 return array(
256 'account_holder',
257 'bank_account_number',
258 'bank_identification_number',
259 'bank_name',
260 );
261 }
262
dc913073 263 /**
100fef9d 264 * Return an array of all the details about the fields potentially required for payment fields
dc913073
EM
265 * Only those determined by getPaymentFormFields will actually be assigned to the form
266 *
a6c01b45
CW
267 * @return array
268 * field metadata
dc913073
EM
269 */
270 public function getPaymentFormFieldsMetadata() {
271 //@todo convert credit card type into an option value
272 $creditCardType = array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::creditCard();
273 return array(
274 'credit_card_number' => array(
275 'htmlType' => 'text',
276 'name' => 'credit_card_number',
277 'title' => ts('Card Number'),
278 'cc_field' => TRUE,
279 'attributes' => array(
280 'size' => 20,
281 'maxlength' => 20,
21dfd5f5 282 'autocomplete' => 'off',
dc913073
EM
283 ),
284 'is_required' => TRUE,
285 ),
286 'cvv2' => array(
287 'htmlType' => 'text',
288 'name' => 'cvv2',
289 'title' => ts('Security Code'),
290 'cc_field' => TRUE,
291 'attributes' => array(
292 'size' => 5,
293 'maxlength' => 10,
21dfd5f5 294 'autocomplete' => 'off',
dc913073
EM
295 ),
296 'is_required' => CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,
297 'cvv_backoffice_required',
298 NULL,
299 1
300 ),
301 'rules' => array(
302 array(
303 '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.'),
304 'rule_name' => 'integer',
305 'rule_parameters' => NULL,
353ffa53
TO
306 )
307 ),
dc913073
EM
308 ),
309 'credit_card_exp_date' => array(
310 'htmlType' => 'date',
311 'name' => 'credit_card_exp_date',
312 'title' => ts('Expiration Date'),
313 'cc_field' => TRUE,
314 'attributes' => CRM_Core_SelectValues::date('creditCard'),
315 'is_required' => TRUE,
316 'rules' => array(
317 array(
318 'rule_message' => ts('Card expiration date cannot be a past date.'),
319 'rule_name' => 'currentDate',
320 'rule_parameters' => TRUE,
353ffa53
TO
321 )
322 ),
dc913073
EM
323 ),
324 'credit_card_type' => array(
325 'htmlType' => 'select',
326 'name' => 'credit_card_type',
327 'title' => ts('Card Type'),
328 'cc_field' => TRUE,
329 'attributes' => $creditCardType,
330 'is_required' => FALSE,
331 ),
332 'account_holder' => array(
333 'htmlType' => 'text',
334 'name' => 'account_holder',
335 'title' => ts('Account Holder'),
336 'cc_field' => TRUE,
337 'attributes' => array(
338 'size' => 20,
339 'maxlength' => 34,
21dfd5f5 340 'autocomplete' => 'on',
dc913073
EM
341 ),
342 'is_required' => TRUE,
343 ),
344 //e.g. IBAN can have maxlength of 34 digits
345 'bank_account_number' => array(
346 'htmlType' => 'text',
347 'name' => 'bank_account_number',
348 'title' => ts('Bank Account Number'),
349 'cc_field' => TRUE,
350 'attributes' => array(
351 'size' => 20,
352 'maxlength' => 34,
21dfd5f5 353 'autocomplete' => 'off',
dc913073
EM
354 ),
355 'rules' => array(
356 array(
357 'rule_message' => ts('Please enter a valid Bank Identification Number (value must not contain punctuation characters).'),
358 'rule_name' => 'nopunctuation',
359 'rule_parameters' => NULL,
353ffa53
TO
360 )
361 ),
dc913073
EM
362 'is_required' => TRUE,
363 ),
364 //e.g. SWIFT-BIC can have maxlength of 11 digits
365 'bank_identification_number' => array(
366 'htmlType' => 'text',
367 'name' => 'bank_identification_number',
368 'title' => ts('Bank Identification Number'),
369 'cc_field' => TRUE,
370 'attributes' => array(
371 'size' => 20,
372 'maxlength' => 11,
21dfd5f5 373 'autocomplete' => 'off',
dc913073
EM
374 ),
375 'is_required' => TRUE,
376 'rules' => array(
377 array(
378 'rule_message' => ts('Please enter a valid Bank Identification Number (value must not contain punctuation characters).'),
379 'rule_name' => 'nopunctuation',
380 'rule_parameters' => NULL,
353ffa53
TO
381 )
382 ),
dc913073
EM
383 ),
384 'bank_name' => array(
385 'htmlType' => 'text',
386 'name' => 'bank_name',
387 'title' => ts('Bank Name'),
388 'cc_field' => TRUE,
389 'attributes' => array(
390 'size' => 20,
391 'maxlength' => 64,
21dfd5f5 392 'autocomplete' => 'off',
dc913073
EM
393 ),
394 'is_required' => TRUE,
395
21dfd5f5 396 ),
dc913073
EM
397 );
398 }
44b6505d 399
6a488035
TO
400 /**
401 * This function collects all the information from a web/api form and invokes
402 * the relevant payment processor specific functions to perform the transaction
403 *
6a0b768e
TO
404 * @param array $params
405 * Assoc array of input parameters for this transaction.
6a488035 406 *
a6c01b45
CW
407 * @return array
408 * the result in an nice formatted array (or an error object)
6a488035
TO
409 * @abstract
410 */
411 abstract function doDirectPayment(&$params);
412
c1cc3e0c 413 /**
100fef9d 414 * Process payment - this function wraps around both doTransferPayment and doDirectPayment
c1cc3e0c
EM
415 * it ensures an exception is thrown & moves some of this logic out of the form layer and makes the forms more agnostic
416 *
417 * @param array $params
418 *
419 * @param $component
420 *
a6c01b45
CW
421 * @return array
422 * (modified)
c1cc3e0c
EM
423 * @throws CRM_Core_Exception
424 */
425 public function doPayment(&$params, $component) {
426 if ($this->_paymentProcessor['billing_mode'] == 4) {
427 $result = $this->doTransferCheckout($params, $component);
428 }
429 else {
430 $result = $this->doDirectPayment($params, $component);
431 }
432 if (is_a($result, 'CRM_Core_Error')) {
433 throw new CRM_Core_Exception(CRM_Core_Error::getMessages($result));
434 }
a9cf9972 435 //CRM-15767 - Submit Credit Card Contribution not being saved
436 return $result;
c1cc3e0c
EM
437 }
438
6a488035
TO
439 /**
440 * This function checks to see if we have the right config values
441 *
a6c01b45
CW
442 * @return string
443 * the error message if any
6a488035
TO
444 */
445 abstract function checkConfig();
446
a0ee3941
EM
447 /**
448 * @param $paymentProcessor
43e5f0f6 449 * @todo move to paypal class or remover
a0ee3941
EM
450 * @return bool
451 */
00be9182 452 public static function paypalRedirect(&$paymentProcessor) {
6a488035
TO
453 if (!$paymentProcessor) {
454 return FALSE;
455 }
456
457 if (isset($_GET['payment_date']) &&
458 isset($_GET['merchant_return_link']) &&
459 CRM_Utils_Array::value('payment_status', $_GET) == 'Completed' &&
460 $paymentProcessor['payment_processor_type'] == "PayPal_Standard"
461 ) {
462 return TRUE;
463 }
464
465 return FALSE;
466 }
467
468 /**
43e5f0f6 469 * @todo move to0 \Civi\Payment\System factory method
6a488035 470 * Page callback for civicrm/payment/ipn
6a488035 471 */
00be9182 472 public static function handleIPN() {
6a488035
TO
473 self::handlePaymentMethod(
474 'PaymentNotification',
475 array(
476 'processor_name' => @$_GET['processor_name'],
42b90e8f 477 'processor_id' => @$_GET['processor_id'],
6a488035
TO
478 'mode' => @$_GET['mode'],
479 )
480 );
481 }
482
483 /**
43d1ae00
EM
484 * Payment callback handler. The processor_name or processor_id is passed in.
485 * Note that processor_id is more reliable as one site may have more than one instance of a
486 * processor & ideally the processor will be validating the results
6a488035 487 * Load requested payment processor and call that processor's handle<$method> method
43e5f0f6 488 * @todo move to0 \Civi\Payment\System factory method
6a488035 489 *
4691b077
EM
490 * @param $method
491 * @param array $params
6a488035 492 */
00be9182 493 public static function handlePaymentMethod($method, $params = array()) {
42b90e8f
CB
494 if (!isset($params['processor_id']) && !isset($params['processor_name'])) {
495 CRM_Core_Error::fatal("Either 'processor_id' or 'processor_name' param is required for payment callback");
6a488035 496 }
e2bef985 497 self::logPaymentNotification($params);
6a488035
TO
498
499 // Query db for processor ..
500 $mode = @$params['mode'];
501
42b90e8f
CB
502 $sql = "SELECT ppt.class_name, ppt.name as processor_name, pp.id AS processor_id
503 FROM civicrm_payment_processor_type ppt
504 INNER JOIN civicrm_payment_processor pp
505 ON pp.payment_processor_type_id = ppt.id
506 AND pp.is_active
507 AND pp.is_test = %1";
508 $args[1] = array($mode == 'test' ? 1 : 0, 'Integer');
509
510 if (isset($params['processor_id'])) {
511 $sql .= " WHERE pp.id = %2";
512 $args[2] = array($params['processor_id'], 'Integer');
513 $notfound = "No active instances of payment processor ID#'{$params['processor_id']}' were found.";
514 }
515 else {
516 $sql .= " WHERE ppt.name = %2";
517 $args[2] = array($params['processor_name'], 'String');
518 $notfound = "No active instances of the '{$params['processor_name']}' payment processor were found.";
519 }
520
521 $dao = CRM_Core_DAO::executeQuery($sql, $args);
6a488035
TO
522
523 // Check whether we found anything at all ..
524 if (!$dao->N) {
42b90e8f 525 CRM_Core_Error::fatal($notfound);
6a488035
TO
526 }
527
528 $method = 'handle' . $method;
529 $extension_instance_found = FALSE;
530
531 // In all likelihood, we'll just end up with the one instance returned here. But it's
532 // possible we may get more. Hence, iterate through all instances ..
533
534 while ($dao->fetch()) {
535 // Check pp is extension
536 $ext = CRM_Extension_System::singleton()->getMapper();
537 if ($ext->isExtensionKey($dao->class_name)) {
6a488035
TO
538 $paymentClass = $ext->keyToClass($dao->class_name, 'payment');
539 require_once $ext->classToPath($paymentClass);
540 }
541 else {
43d1ae00 542 // Legacy or extension as module instance
d031c654 543 if (empty($paymentClass)) {
43d1ae00
EM
544 $paymentClass = 'CRM_Core_' . $dao->class_name;
545
546 }
6a488035
TO
547 }
548
549 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($dao->processor_id, $mode);
550
551 // Should never be empty - we already established this processor_id exists and is active.
552 if (empty($paymentProcessor)) {
553 continue;
554 }
555
556 // Instantiate PP
60631917 557 $processorInstance = new $paymentClass($mode, $paymentProcessor);
6a488035
TO
558
559 // Does PP implement this method, and can we call it?
560 if (!method_exists($processorInstance, $method) ||
561 !is_callable(array($processorInstance, $method))
562 ) {
43d1ae00
EM
563 // on the off chance there is a double implementation of this processor we should keep looking for another
564 // note that passing processor_id is more reliable & we should work to deprecate processor_name
565 continue;
6a488035
TO
566 }
567
568 // Everything, it seems, is ok - execute pp callback handler
569 $processorInstance->$method();
a5ef96f6 570 $extension_instance_found = TRUE;
6a488035
TO
571 }
572
4f99ca55
TO
573 if (!$extension_instance_found) {
574 CRM_Core_Error::fatal(
575 "No extension instances of the '{$params['processor_name']}' payment processor were found.<br />" .
576 "$method method is unsupported in legacy payment processors."
2aa397bc
TO
577 );
578 }
6a488035
TO
579
580 // Exit here on web requests, allowing just the plain text response to be echoed
581 if ($method == 'handlePaymentNotification') {
582 CRM_Utils_System::civiExit();
583 }
584 }
585
586 /**
100fef9d 587 * Check whether a method is present ( & supported ) by the payment processor object.
6a488035 588 *
6a0b768e
TO
589 * @param string $method
590 * Method to check for.
6a488035
TO
591 *
592 * @return boolean
6a488035 593 */
00be9182 594 public function isSupported($method = 'cancelSubscription') {
6a488035
TO
595 return method_exists(CRM_Utils_System::getClassName($this), $method);
596 }
597
a0ee3941 598 /**
100fef9d 599 * @param int $entityID
a0ee3941
EM
600 * @param null $entity
601 * @param string $action
602 *
603 * @return string
604 */
00be9182 605 public function subscriptionURL($entityID = NULL, $entity = NULL, $action = 'cancel') {
03cfff4c
KW
606 // Set URL
607 switch ($action) {
2aa397bc 608 case 'cancel':
03cfff4c
KW
609 $url = 'civicrm/contribute/unsubscribe';
610 break;
2aa397bc
TO
611
612 case 'billing':
03cfff4c 613 //in notify mode don't return the update billing url
68acd6ae 614 if (!$this->isSupported('updateSubscriptionBillingInfo')) {
03cfff4c
KW
615 return NULL;
616 }
68acd6ae 617 $url = 'civicrm/contribute/updatebilling';
03cfff4c 618 break;
2aa397bc
TO
619
620 case 'update':
03cfff4c
KW
621 $url = 'civicrm/contribute/updaterecur';
622 break;
6a488035
TO
623 }
624
353ffa53
TO
625 $session = CRM_Core_Session::singleton();
626 $userId = $session->get('userID');
627 $contactID = 0;
03cfff4c 628 $checksumValue = '';
353ffa53 629 $entityArg = '';
03cfff4c
KW
630
631 // Find related Contact
632 if ($entityID) {
633 switch ($entity) {
2aa397bc 634 case 'membership':
03cfff4c
KW
635 $contactID = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $entityID, "contact_id");
636 $entityArg = 'mid';
637 break;
638
2aa397bc 639 case 'contribution':
03cfff4c
KW
640 $contactID = CRM_Core_DAO::getFieldValue("CRM_Contribute_DAO_Contribution", $entityID, "contact_id");
641 $entityArg = 'coid';
642 break;
643
2aa397bc 644 case 'recur':
03cfff4c 645 $sql = "
6a488035
TO
646 SELECT con.contact_id
647 FROM civicrm_contribution_recur rec
648INNER JOIN civicrm_contribution con ON ( con.contribution_recur_id = rec.id )
649 WHERE rec.id = %1
650 GROUP BY rec.id";
03cfff4c
KW
651 $contactID = CRM_Core_DAO::singleValueQuery($sql, array(1 => array($entityID, 'Integer')));
652 $entityArg = 'crid';
653 break;
6a488035 654 }
6a488035
TO
655 }
656
03cfff4c
KW
657 // Add entity arguments
658 if ($entityArg != '') {
659 // Add checksum argument
660 if ($contactID != 0 && $userId != $contactID) {
661 $checksumValue = '&cs=' . CRM_Contact_BAO_Contact_Utils::generateChecksum($contactID, NULL, 'inf');
662 }
663 return CRM_Utils_System::url($url, "reset=1&{$entityArg}={$entityID}{$checksumValue}", TRUE, NULL, FALSE, TRUE);
664 }
665
666 // Else login URL
6a488035
TO
667 if ($this->isSupported('accountLoginURL')) {
668 return $this->accountLoginURL();
669 }
03cfff4c
KW
670
671 // Else default
6a488035
TO
672 return $this->_paymentProcessor['url_recur'];
673 }
6a488035 674}