Merge pull request #12557 from eileenmcnaughton/activity
[civicrm-core.git] / CRM / Core / Payment.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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 * Component - ie. event or contribute.
43 *
44 * This is used for setting return urls.
45 *
46 * @var string
47 */
48 protected $_component;
49
50 /**
51 * How are we getting billing information.
52 *
53 * We are trying to completely deprecate these parameters.
54 *
55 * FORM - we collect it on the same page
56 * BUTTON - the processor collects it and sends it back to us via some protocol
57 */
58 const
59 BILLING_MODE_FORM = 1,
60 BILLING_MODE_BUTTON = 2,
61 BILLING_MODE_NOTIFY = 4;
62
63 /**
64 * Which payment type(s) are we using?
65 *
66 * credit card
67 * direct debit
68 * or both
69 * @todo create option group - nb omnipay uses a 3rd type - transparent redirect cc
70 */
71 const
72 PAYMENT_TYPE_CREDIT_CARD = 1,
73 PAYMENT_TYPE_DIRECT_DEBIT = 2;
74
75 /**
76 * Subscription / Recurring payment Status
77 * START, END
78 */
79 const
80 RECURRING_PAYMENT_START = 'START',
81 RECURRING_PAYMENT_END = 'END';
82
83 protected $_paymentProcessor;
84
85 /**
86 * Base url of the calling form (offsite processors).
87 *
88 * @var string
89 */
90 protected $baseReturnUrl;
91
92 /**
93 * Return url upon success (offsite processors).
94 *
95 * @var string
96 */
97 protected $successUrl;
98
99 /**
100 * Return url upon failure (offsite processors).
101 *
102 * @var string
103 */
104 protected $cancelUrl;
105
106 /**
107 * Processor type label.
108 *
109 * (Deprecated parameter but used in some messages).
110 *
111 * @deprecated
112 *
113 * @var string
114 */
115 public $_processorName;
116
117 /**
118 * The profile configured to show on the billing form.
119 *
120 * Currently only the pseudo-profile 'billing' is supported but hopefully in time we will take an id and
121 * load that from the DB and the processor will be able to return a set of fields that combines it's minimum
122 * requirements with the configured requirements.
123 *
124 * Currently only the pseudo-processor 'manual' or 'pay-later' uses this setting to return a 'curated' set
125 * of fields.
126 *
127 * Note this change would probably include converting 'billing' to a reserved profile.
128 *
129 * @var int|string
130 */
131 protected $billingProfile;
132
133 /**
134 * Payment instrument ID.
135 *
136 * This is normally retrieved from the payment_processor table.
137 *
138 * @var int
139 */
140 protected $paymentInstrumentID;
141
142 /**
143 * Is this a back office transaction.
144 *
145 * @var bool
146 */
147 protected $backOffice = FALSE;
148
149 /**
150 * @return bool
151 */
152 public function isBackOffice() {
153 return $this->backOffice;
154 }
155
156 /**
157 * Set back office property.
158 *
159 * @param bool $isBackOffice
160 */
161 public function setBackOffice($isBackOffice) {
162 $this->backOffice = $isBackOffice;
163 }
164
165 /**
166 * Get payment instrument id.
167 *
168 * @return int
169 */
170 public function getPaymentInstrumentID() {
171 return $this->paymentInstrumentID ? $this->paymentInstrumentID : $this->_paymentProcessor['payment_instrument_id'];
172 }
173
174 /**
175 * Set payment Instrument id.
176 *
177 * By default we actually ignore the form value. The manual processor takes it more seriously.
178 *
179 * @param int $paymentInstrumentID
180 */
181 public function setPaymentInstrumentID($paymentInstrumentID) {
182 $this->paymentInstrumentID = $this->_paymentProcessor['payment_instrument_id'];
183 }
184
185 /**
186 * Set base return path (offsite processors).
187 *
188 * This is only useful with an internal civicrm form.
189 *
190 * @param string $url
191 * Internal civicrm path.
192 */
193 public function setBaseReturnUrl($url) {
194 $this->baseReturnUrl = $url;
195 }
196
197 /**
198 * Set success return URL (offsite processors).
199 *
200 * This overrides $baseReturnUrl
201 *
202 * @param string $url
203 * Full url of site to return browser to upon success.
204 */
205 public function setSuccessUrl($url) {
206 $this->successUrl = $url;
207 }
208
209 /**
210 * Set cancel return URL (offsite processors).
211 *
212 * This overrides $baseReturnUrl
213 *
214 * @param string $url
215 * Full url of site to return browser to upon failure.
216 */
217 public function setCancelUrl($url) {
218 $this->cancelUrl = $url;
219 }
220
221 /**
222 * Set the configured payment profile.
223 *
224 * @param int|string $value
225 */
226 public function setBillingProfile($value) {
227 $this->billingProfile = $value;
228 }
229
230 /**
231 * Opportunity for the payment processor to override the entire form build.
232 *
233 * @param CRM_Core_Form $form
234 *
235 * @return bool
236 * Should form building stop at this point?
237 */
238 public function buildForm(&$form) {
239 return FALSE;
240 }
241
242 /**
243 * Log payment notification message to forensic system log.
244 *
245 * @todo move to factory class \Civi\Payment\System (or similar)
246 *
247 * @param array $params
248 *
249 * @return mixed
250 */
251 public static function logPaymentNotification($params) {
252 $message = 'payment_notification ';
253 if (!empty($params['processor_name'])) {
254 $message .= 'processor_name=' . $params['processor_name'];
255 }
256 if (!empty($params['processor_id'])) {
257 $message .= 'processor_id=' . $params['processor_id'];
258 }
259
260 $log = new CRM_Utils_SystemLogger();
261 $log->alert($message, $_REQUEST);
262 }
263
264 /**
265 * Check if capability is supported.
266 *
267 * Capabilities have a one to one relationship with capability-related functions on this class.
268 *
269 * Payment processor classes should over-ride the capability-specific function rather than this one.
270 *
271 * @param string $capability
272 * E.g BackOffice, LiveMode, FutureRecurStartDate.
273 *
274 * @return bool
275 */
276 public function supports($capability) {
277 $function = 'supports' . ucfirst($capability);
278 if (method_exists($this, $function)) {
279 return $this->$function();
280 }
281 return FALSE;
282 }
283
284 /**
285 * Are back office payments supported.
286 *
287 * e.g paypal standard won't permit you to enter a credit card associated
288 * with someone else's login.
289 * The intention is to support off-site (other than paypal) & direct debit but that is not all working yet so to
290 * reach a 'stable' point we disable.
291 *
292 * @return bool
293 */
294 protected function supportsBackOffice() {
295 if ($this->_paymentProcessor['billing_mode'] == 4 || $this->_paymentProcessor['payment_type'] != 1) {
296 return FALSE;
297 }
298 else {
299 return TRUE;
300 }
301 }
302
303 /**
304 * Can more than one transaction be processed at once?
305 *
306 * In general processors that process payment by server to server communication support this while others do not.
307 *
308 * In future we are likely to hit an issue where this depends on whether a token already exists.
309 *
310 * @return bool
311 */
312 protected function supportsMultipleConcurrentPayments() {
313 if ($this->_paymentProcessor['billing_mode'] == 4 || $this->_paymentProcessor['payment_type'] != 1) {
314 return FALSE;
315 }
316 else {
317 return TRUE;
318 }
319 }
320
321 /**
322 * Are live payments supported - e.g dummy doesn't support this.
323 *
324 * @return bool
325 */
326 protected function supportsLiveMode() {
327 return TRUE;
328 }
329
330 /**
331 * Are test payments supported.
332 *
333 * @return bool
334 */
335 protected function supportsTestMode() {
336 return TRUE;
337 }
338
339 /**
340 * Should the first payment date be configurable when setting up back office recurring payments.
341 *
342 * We set this to false for historical consistency but in fact most new processors use tokens for recurring and can support this
343 *
344 * @return bool
345 */
346 protected function supportsFutureRecurStartDate() {
347 return FALSE;
348 }
349
350 /**
351 * Does this processor support cancelling recurring contributions through code.
352 *
353 * If the processor returns true it must be possible to take action from within CiviCRM
354 * that will result in no further payments being processed. In the case of token processors (e.g
355 * IATS, eWay) updating the contribution_recur table is probably sufficient.
356 *
357 * @return bool
358 */
359 protected function supportsCancelRecurring() {
360 return method_exists(CRM_Utils_System::getClassName($this), 'cancelSubscription');
361 }
362
363 /**
364 * Does this processor support pre-approval.
365 *
366 * This would generally look like a redirect to enter credentials which can then be used in a later payment call.
367 *
368 * Currently Paypal express supports this, with a redirect to paypal after the 'Main' form is submitted in the
369 * contribution page. This token can then be processed at the confirm phase. Although this flow 'looks' like the
370 * 'notify' flow a key difference is that in the notify flow they don't have to return but in this flow they do.
371 *
372 * @return bool
373 */
374 protected function supportsPreApproval() {
375 return FALSE;
376 }
377
378 /**
379 * Does this processor support updating billing info for recurring contributions through code.
380 *
381 * If the processor returns true then it must be possible to update billing info from within CiviCRM
382 * that will be updated at the payment processor.
383 *
384 * @return bool
385 */
386 protected function supportsUpdateSubscriptionBillingInfo() {
387 return method_exists(CRM_Utils_System::getClassName($this), 'updateSubscriptionBillingInfo');
388 }
389
390 /**
391 * Can recurring contributions be set against pledges.
392 *
393 * In practice all processors that use the baseIPN function to finish transactions or
394 * call the completetransaction api support this by looking up previous contributions in the
395 * series and, if there is a prior contribution against a pledge, and the pledge is not complete,
396 * adding the new payment to the pledge.
397 *
398 * However, only enabling for processors it has been tested against.
399 *
400 * @return bool
401 */
402 protected function supportsRecurContributionsForPledges() {
403 return FALSE;
404 }
405
406 /**
407 * Function to action pre-approval if supported
408 *
409 * @param array $params
410 * Parameters from the form
411 *
412 * This function returns an array which should contain
413 * - pre_approval_parameters (this will be stored on the calling form & available later)
414 * - redirect_url (if set the browser will be redirected to this.
415 */
416 public function doPreApproval(&$params) {}
417
418 /**
419 * Get any details that may be available to the payment processor due to an approval process having happened.
420 *
421 * In some cases the browser is redirected to enter details on a processor site. Some details may be available as a
422 * result.
423 *
424 * @param array $storedDetails
425 *
426 * @return array
427 */
428 public function getPreApprovalDetails($storedDetails) {
429 return array();
430 }
431
432 /**
433 * Default payment instrument validation.
434 *
435 * Implement the usual Luhn algorithm via a static function in the CRM_Core_Payment_Form if it's a credit card
436 * Not a static function, because I need to check for payment_type.
437 *
438 * @param array $values
439 * @param array $errors
440 */
441 public function validatePaymentInstrument($values, &$errors) {
442 CRM_Core_Form::validateMandatoryFields($this->getMandatoryFields(), $values, $errors);
443 if ($this->_paymentProcessor['payment_type'] == 1) {
444 CRM_Core_Payment_Form::validateCreditCard($values, $errors, $this->_paymentProcessor['id']);
445 }
446 }
447
448 /**
449 * Getter for the payment processor.
450 *
451 * The payment processor array is based on the civicrm_payment_processor table entry.
452 *
453 * @return array
454 * Payment processor array.
455 */
456 public function getPaymentProcessor() {
457 return $this->_paymentProcessor;
458 }
459
460 /**
461 * Setter for the payment processor.
462 *
463 * @param array $processor
464 */
465 public function setPaymentProcessor($processor) {
466 $this->_paymentProcessor = $processor;
467 }
468
469 /**
470 * Setter for the payment form that wants to use the processor.
471 *
472 * @deprecated
473 *
474 * @param CRM_Core_Form $paymentForm
475 */
476 public function setForm(&$paymentForm) {
477 $this->_paymentForm = $paymentForm;
478 }
479
480 /**
481 * Getter for payment form that is using the processor.
482 * @deprecated
483 * @return CRM_Core_Form
484 * A form object
485 */
486 public function getForm() {
487 return $this->_paymentForm;
488 }
489
490 /**
491 * Get help text information (help, description, etc.) about this payment,
492 * to display to the user.
493 *
494 * @param string $context
495 * Context of the text.
496 * Only explicitly supported contexts are handled without error.
497 * Currently supported:
498 * - contributionPageRecurringHelp (params: is_recur_installments, is_email_receipt)
499 *
500 * @param array $params
501 * Parameters for the field, context specific.
502 *
503 * @return string
504 */
505 public function getText($context, $params) {
506 // I have deliberately added a noisy fail here.
507 // The function is intended to be extendable, but not by changes
508 // not documented clearly above.
509 switch ($context) {
510 case 'contributionPageRecurringHelp':
511 // require exactly two parameters
512 if (array_keys($params) == array('is_recur_installments', 'is_email_receipt')) {
513 $gotText = ts('Your recurring contribution will be processed automatically.');
514 if ($params['is_recur_installments']) {
515 $gotText .= ' ' . ts('You can specify the number of installments, or you can leave the number of installments blank if you want to make an open-ended commitment. In either case, you can choose to cancel at any time.');
516 }
517 if ($params['is_email_receipt']) {
518 $gotText .= ' ' . ts('You will receive an email receipt for each recurring contribution.');
519 }
520 }
521 break;
522 }
523 return $gotText;
524 }
525
526 /**
527 * Getter for accessing member vars.
528 *
529 * @todo believe this is unused
530 *
531 * @param string $name
532 *
533 * @return null
534 */
535 public function getVar($name) {
536 return isset($this->$name) ? $this->$name : NULL;
537 }
538
539 /**
540 * Get name for the payment information type.
541 * @todo - use option group + name field (like Omnipay does)
542 * @return string
543 */
544 public function getPaymentTypeName() {
545 return $this->_paymentProcessor['payment_type'] == 1 ? 'credit_card' : 'direct_debit';
546 }
547
548 /**
549 * Get label for the payment information type.
550 * @todo - use option group + labels (like Omnipay does)
551 * @return string
552 */
553 public function getPaymentTypeLabel() {
554 return $this->_paymentProcessor['payment_type'] == 1 ? 'Credit Card' : 'Direct Debit';
555 }
556
557 /**
558 * Get array of fields that should be displayed on the payment form.
559 *
560 * Common results are
561 * array('credit_card_type', 'credit_card_number', 'cvv2', 'credit_card_exp_date')
562 * or
563 * array('account_holder', 'bank_account_number', 'bank_identification_number', 'bank_name')
564 * or
565 * array()
566 *
567 * @return array
568 * Array of payment fields appropriate to the payment processor.
569 *
570 * @throws CiviCRM_API3_Exception
571 */
572 public function getPaymentFormFields() {
573 if ($this->_paymentProcessor['billing_mode'] == 4) {
574 return array();
575 }
576 return $this->_paymentProcessor['payment_type'] == 1 ? $this->getCreditCardFormFields() : $this->getDirectDebitFormFields();
577 }
578
579 /**
580 * Get an array of the fields that can be edited on the recurring contribution.
581 *
582 * Some payment processors support editing the amount and other scheduling details of recurring payments, especially
583 * those which use tokens. Others are fixed. This function allows the processor to return an array of the fields that
584 * can be updated from the contribution recur edit screen.
585 *
586 * The fields are likely to be a subset of these
587 * - 'amount',
588 * - 'installments',
589 * - 'frequency_interval',
590 * - 'frequency_unit',
591 * - 'cycle_day',
592 * - 'next_sched_contribution_date',
593 * - 'end_date',
594 * - 'failure_retry_day',
595 *
596 * The form does not restrict which fields from the contribution_recur table can be added (although if the html_type
597 * metadata is not defined in the xml for the field it will cause an error.
598 *
599 * Open question - would it make sense to return membership_id in this - which is sometimes editable and is on that
600 * form (UpdateSubscription).
601 *
602 * @return array
603 */
604 public function getEditableRecurringScheduleFields() {
605 if ($this->supports('changeSubscriptionAmount')) {
606 return array('amount');
607 }
608 }
609
610 /**
611 * Get the help text to present on the recurring update page.
612 *
613 * This should reflect what can or cannot be edited.
614 *
615 * @return string
616 */
617 public function getRecurringScheduleUpdateHelpText() {
618 if (!in_array('amount', $this->getEditableRecurringScheduleFields())) {
619 return ts('Updates made using this form will change the recurring contribution information stored in your CiviCRM database, but will NOT be sent to the payment processor. You must enter the same changes using the payment processor web site.');
620 }
621 return ts('Use this form to change the amount or number of installments for this recurring contribution. Changes will be automatically sent to the payment processor. You can not change the contribution frequency.');
622 }
623
624 /**
625 * Get the metadata for all required fields.
626 *
627 * @return array;
628 */
629 protected function getMandatoryFields() {
630 $mandatoryFields = array();
631 foreach ($this->getAllFields() as $field_name => $field_spec) {
632 if (!empty($field_spec['is_required'])) {
633 $mandatoryFields[$field_name] = $field_spec;
634 }
635 }
636 return $mandatoryFields;
637 }
638
639 /**
640 * Get the metadata of all the fields configured for this processor.
641 *
642 * @return array
643 */
644 protected function getAllFields() {
645 $paymentFields = array_intersect_key($this->getPaymentFormFieldsMetadata(), array_flip($this->getPaymentFormFields()));
646 $billingFields = array_intersect_key($this->getBillingAddressFieldsMetadata(), array_flip($this->getBillingAddressFields()));
647 return array_merge($paymentFields, $billingFields);
648 }
649 /**
650 * Get array of fields that should be displayed on the payment form for credit cards.
651 *
652 * @return array
653 */
654 protected function getCreditCardFormFields() {
655 return array(
656 'credit_card_type',
657 'credit_card_number',
658 'cvv2',
659 'credit_card_exp_date',
660 );
661 }
662
663 /**
664 * Get array of fields that should be displayed on the payment form for direct debits.
665 *
666 * @return array
667 */
668 protected function getDirectDebitFormFields() {
669 return array(
670 'account_holder',
671 'bank_account_number',
672 'bank_identification_number',
673 'bank_name',
674 );
675 }
676
677 /**
678 * Return an array of all the details about the fields potentially required for payment fields.
679 *
680 * Only those determined by getPaymentFormFields will actually be assigned to the form
681 *
682 * @return array
683 * field metadata
684 */
685 public function getPaymentFormFieldsMetadata() {
686 //@todo convert credit card type into an option value
687 $creditCardType = array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::creditCard();
688 $isCVVRequired = Civi::settings()->get('cvv_backoffice_required');
689 if (!$this->isBackOffice()) {
690 $isCVVRequired = TRUE;
691 }
692 return array(
693 'credit_card_number' => array(
694 'htmlType' => 'text',
695 'name' => 'credit_card_number',
696 'title' => ts('Card Number'),
697 'attributes' => array(
698 'size' => 20,
699 'maxlength' => 20,
700 'autocomplete' => 'off',
701 'class' => 'creditcard',
702 ),
703 'is_required' => TRUE,
704 // 'description' => '16 digit card number', // If you enable a description field it will be shown below the field on the form
705 ),
706 'cvv2' => array(
707 'htmlType' => 'text',
708 'name' => 'cvv2',
709 'title' => ts('Security Code'),
710 'attributes' => array(
711 'size' => 5,
712 'maxlength' => 10,
713 'autocomplete' => 'off',
714 ),
715 'is_required' => $isCVVRequired,
716 'rules' => array(
717 array(
718 '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.'),
719 'rule_name' => 'integer',
720 'rule_parameters' => NULL,
721 ),
722 ),
723 ),
724 'credit_card_exp_date' => array(
725 'htmlType' => 'date',
726 'name' => 'credit_card_exp_date',
727 'title' => ts('Expiration Date'),
728 'attributes' => CRM_Core_SelectValues::date('creditCard'),
729 'is_required' => TRUE,
730 'rules' => array(
731 array(
732 'rule_message' => ts('Card expiration date cannot be a past date.'),
733 'rule_name' => 'currentDate',
734 'rule_parameters' => TRUE,
735 ),
736 ),
737 ),
738 'credit_card_type' => array(
739 'htmlType' => 'select',
740 'name' => 'credit_card_type',
741 'title' => ts('Card Type'),
742 'attributes' => $creditCardType,
743 'is_required' => FALSE,
744 ),
745 'account_holder' => array(
746 'htmlType' => 'text',
747 'name' => 'account_holder',
748 'title' => ts('Account Holder'),
749 'attributes' => array(
750 'size' => 20,
751 'maxlength' => 34,
752 'autocomplete' => 'on',
753 ),
754 'is_required' => TRUE,
755 ),
756 //e.g. IBAN can have maxlength of 34 digits
757 'bank_account_number' => array(
758 'htmlType' => 'text',
759 'name' => 'bank_account_number',
760 'title' => ts('Bank Account Number'),
761 'attributes' => array(
762 'size' => 20,
763 'maxlength' => 34,
764 'autocomplete' => 'off',
765 ),
766 'rules' => array(
767 array(
768 'rule_message' => ts('Please enter a valid Bank Identification Number (value must not contain punctuation characters).'),
769 'rule_name' => 'nopunctuation',
770 'rule_parameters' => NULL,
771 ),
772 ),
773 'is_required' => TRUE,
774 ),
775 //e.g. SWIFT-BIC can have maxlength of 11 digits
776 'bank_identification_number' => array(
777 'htmlType' => 'text',
778 'name' => 'bank_identification_number',
779 'title' => ts('Bank Identification Number'),
780 'attributes' => array(
781 'size' => 20,
782 'maxlength' => 11,
783 'autocomplete' => 'off',
784 ),
785 'is_required' => TRUE,
786 'rules' => array(
787 array(
788 'rule_message' => ts('Please enter a valid Bank Identification Number (value must not contain punctuation characters).'),
789 'rule_name' => 'nopunctuation',
790 'rule_parameters' => NULL,
791 ),
792 ),
793 ),
794 'bank_name' => array(
795 'htmlType' => 'text',
796 'name' => 'bank_name',
797 'title' => ts('Bank Name'),
798 'attributes' => array(
799 'size' => 20,
800 'maxlength' => 64,
801 'autocomplete' => 'off',
802 ),
803 'is_required' => TRUE,
804
805 ),
806 'check_number' => array(
807 'htmlType' => 'text',
808 'name' => 'check_number',
809 'title' => ts('Check Number'),
810 'is_required' => FALSE,
811 'attributes' => NULL,
812 ),
813 'pan_truncation' => array(
814 'htmlType' => 'text',
815 'name' => 'pan_truncation',
816 'title' => ts('Last 4 digits of the card'),
817 'is_required' => FALSE,
818 'attributes' => array(
819 'size' => 4,
820 'maxlength' => 4,
821 'minlength' => 4,
822 'autocomplete' => 'off',
823 ),
824 'rules' => array(
825 array(
826 'rule_message' => ts('Please enter valid last 4 digit card number.'),
827 'rule_name' => 'numeric',
828 'rule_parameters' => NULL,
829 ),
830 ),
831 ),
832 'payment_token' => array(
833 'htmlType' => 'hidden',
834 'name' => 'payment_token',
835 'title' => ts('Authorization token'),
836 'is_required' => FALSE,
837 'attributes' => ['size' => 10, 'autocomplete' => 'off', 'id' => 'payment_token'],
838 ),
839 );
840 }
841
842 /**
843 * Get billing fields required for this processor.
844 *
845 * We apply the existing default of returning fields only for payment processor type 1. Processors can override to
846 * alter.
847 *
848 * @param int $billingLocationID
849 *
850 * @return array
851 */
852 public function getBillingAddressFields($billingLocationID = NULL) {
853 if (!$billingLocationID) {
854 // Note that although the billing id is passed around the forms the idea that it would be anything other than
855 // the result of the function below doesn't seem to have eventuated.
856 // So taking this as a param is possibly something to be removed in favour of the standard default.
857 $billingLocationID = CRM_Core_BAO_LocationType::getBilling();
858 }
859 if ($this->_paymentProcessor['billing_mode'] != 1 && $this->_paymentProcessor['billing_mode'] != 3) {
860 return array();
861 }
862 return array(
863 'first_name' => 'billing_first_name',
864 'middle_name' => 'billing_middle_name',
865 'last_name' => 'billing_last_name',
866 'street_address' => "billing_street_address-{$billingLocationID}",
867 'city' => "billing_city-{$billingLocationID}",
868 'country' => "billing_country_id-{$billingLocationID}",
869 'state_province' => "billing_state_province_id-{$billingLocationID}",
870 'postal_code' => "billing_postal_code-{$billingLocationID}",
871 );
872 }
873
874 /**
875 * Get form metadata for billing address fields.
876 *
877 * @param int $billingLocationID
878 *
879 * @return array
880 * Array of metadata for address fields.
881 */
882 public function getBillingAddressFieldsMetadata($billingLocationID = NULL) {
883 if (!$billingLocationID) {
884 // Note that although the billing id is passed around the forms the idea that it would be anything other than
885 // the result of the function below doesn't seem to have eventuated.
886 // So taking this as a param is possibly something to be removed in favour of the standard default.
887 $billingLocationID = CRM_Core_BAO_LocationType::getBilling();
888 }
889 $metadata = array();
890 $metadata['billing_first_name'] = array(
891 'htmlType' => 'text',
892 'name' => 'billing_first_name',
893 'title' => ts('Billing First Name'),
894 'cc_field' => TRUE,
895 'attributes' => array(
896 'size' => 30,
897 'maxlength' => 60,
898 'autocomplete' => 'off',
899 ),
900 'is_required' => TRUE,
901 );
902
903 $metadata['billing_middle_name'] = array(
904 'htmlType' => 'text',
905 'name' => 'billing_middle_name',
906 'title' => ts('Billing Middle Name'),
907 'cc_field' => TRUE,
908 'attributes' => array(
909 'size' => 30,
910 'maxlength' => 60,
911 'autocomplete' => 'off',
912 ),
913 'is_required' => FALSE,
914 );
915
916 $metadata['billing_last_name'] = array(
917 'htmlType' => 'text',
918 'name' => 'billing_last_name',
919 'title' => ts('Billing Last Name'),
920 'cc_field' => TRUE,
921 'attributes' => array(
922 'size' => 30,
923 'maxlength' => 60,
924 'autocomplete' => 'off',
925 ),
926 'is_required' => TRUE,
927 );
928
929 $metadata["billing_street_address-{$billingLocationID}"] = array(
930 'htmlType' => 'text',
931 'name' => "billing_street_address-{$billingLocationID}",
932 'title' => ts('Street Address'),
933 'cc_field' => TRUE,
934 'attributes' => array(
935 'size' => 30,
936 'maxlength' => 60,
937 'autocomplete' => 'off',
938 ),
939 'is_required' => TRUE,
940 );
941
942 $metadata["billing_city-{$billingLocationID}"] = array(
943 'htmlType' => 'text',
944 'name' => "billing_city-{$billingLocationID}",
945 'title' => ts('City'),
946 'cc_field' => TRUE,
947 'attributes' => array(
948 'size' => 30,
949 'maxlength' => 60,
950 'autocomplete' => 'off',
951 ),
952 'is_required' => TRUE,
953 );
954
955 $metadata["billing_state_province_id-{$billingLocationID}"] = array(
956 'htmlType' => 'chainSelect',
957 'title' => ts('State/Province'),
958 'name' => "billing_state_province_id-{$billingLocationID}",
959 'cc_field' => TRUE,
960 'is_required' => TRUE,
961 );
962
963 $metadata["billing_postal_code-{$billingLocationID}"] = array(
964 'htmlType' => 'text',
965 'name' => "billing_postal_code-{$billingLocationID}",
966 'title' => ts('Postal Code'),
967 'cc_field' => TRUE,
968 'attributes' => array(
969 'size' => 30,
970 'maxlength' => 60,
971 'autocomplete' => 'off',
972 ),
973 'is_required' => TRUE,
974 );
975
976 $metadata["billing_country_id-{$billingLocationID}"] = array(
977 'htmlType' => 'select',
978 'name' => "billing_country_id-{$billingLocationID}",
979 'title' => ts('Country'),
980 'cc_field' => TRUE,
981 'attributes' => array(
982 '' => ts('- select -'),
983 ) + CRM_Core_PseudoConstant::country(),
984 'is_required' => TRUE,
985 );
986 return $metadata;
987 }
988
989 /**
990 * Get base url dependent on component.
991 *
992 * (or preferably set it using the setter function).
993 *
994 * @return string
995 */
996 protected function getBaseReturnUrl() {
997 if ($this->baseReturnUrl) {
998 return $this->baseReturnUrl;
999 }
1000 if ($this->_component == 'event') {
1001 $baseURL = 'civicrm/event/register';
1002 }
1003 else {
1004 $baseURL = 'civicrm/contribute/transact';
1005 }
1006 return $baseURL;
1007 }
1008
1009 /**
1010 * Get the currency for the transaction.
1011 *
1012 * Handle any inconsistency about how it is passed in here.
1013 *
1014 * @param $params
1015 *
1016 * @return string
1017 */
1018 protected function getCurrency($params) {
1019 return CRM_Utils_Array::value('currencyID', $params, CRM_Utils_Array::value('currency', $params));
1020 }
1021
1022 /**
1023 * Get the currency for the transaction.
1024 *
1025 * Handle any inconsistency about how it is passed in here.
1026 *
1027 * @param $params
1028 *
1029 * @return string
1030 */
1031 protected function getAmount($params) {
1032 return CRM_Utils_Money::format($params['amount'], NULL, NULL, TRUE);
1033 }
1034
1035 /**
1036 * Get url to return to after cancelled or failed transaction.
1037 *
1038 * @param string $qfKey
1039 * @param int $participantID
1040 *
1041 * @return string cancel url
1042 */
1043 public function getCancelUrl($qfKey, $participantID) {
1044 if (isset($this->cancelUrl)) {
1045 return $this->cancelUrl;
1046 }
1047
1048 if ($this->_component == 'event') {
1049 return CRM_Utils_System::url($this->getBaseReturnUrl(), array(
1050 'reset' => 1,
1051 'cc' => 'fail',
1052 'participantId' => $participantID,
1053 ),
1054 TRUE, NULL, FALSE
1055 );
1056 }
1057
1058 return CRM_Utils_System::url($this->getBaseReturnUrl(), array(
1059 '_qf_Main_display' => 1,
1060 'qfKey' => $qfKey,
1061 'cancel' => 1,
1062 ),
1063 TRUE, NULL, FALSE
1064 );
1065 }
1066
1067 /**
1068 * Get URL to return the browser to on success.
1069 *
1070 * @param $qfKey
1071 *
1072 * @return string
1073 */
1074 protected function getReturnSuccessUrl($qfKey) {
1075 if (isset($this->successUrl)) {
1076 return $this->successUrl;
1077 }
1078
1079 return CRM_Utils_System::url($this->getBaseReturnUrl(), array(
1080 '_qf_ThankYou_display' => 1,
1081 'qfKey' => $qfKey,
1082 ),
1083 TRUE, NULL, FALSE
1084 );
1085 }
1086
1087 /**
1088 * Get URL to return the browser to on failure.
1089 *
1090 * @param string $key
1091 * @param int $participantID
1092 * @param int $eventID
1093 *
1094 * @return string
1095 * URL for a failing transactor to be redirected to.
1096 */
1097 protected function getReturnFailUrl($key, $participantID = NULL, $eventID = NULL) {
1098 if (isset($this->cancelUrl)) {
1099 return $this->cancelUrl;
1100 }
1101
1102 $test = $this->_is_test ? '&action=preview' : '';
1103 if ($this->_component == "event") {
1104 return CRM_Utils_System::url('civicrm/event/register',
1105 "reset=1&cc=fail&participantId={$participantID}&id={$eventID}{$test}&qfKey={$key}",
1106 FALSE, NULL, FALSE
1107 );
1108 }
1109 else {
1110 return CRM_Utils_System::url('civicrm/contribute/transact',
1111 "_qf_Main_display=1&cancel=1&qfKey={$key}{$test}",
1112 FALSE, NULL, FALSE
1113 );
1114 }
1115 }
1116
1117 /**
1118 * Get URl for when the back button is pressed.
1119 *
1120 * @param $qfKey
1121 *
1122 * @return string url
1123 */
1124 protected function getGoBackUrl($qfKey) {
1125 return CRM_Utils_System::url($this->getBaseReturnUrl(), array(
1126 '_qf_Confirm_display' => 'true',
1127 'qfKey' => $qfKey,
1128 ),
1129 TRUE, NULL, FALSE
1130 );
1131 }
1132
1133 /**
1134 * Get the notify (aka ipn, web hook or silent post) url.
1135 *
1136 * If there is no '.' in it we assume that we are dealing with localhost or
1137 * similar and it is unreachable from the web & hence invalid.
1138 *
1139 * @return string
1140 * URL to notify outcome of transaction.
1141 */
1142 protected function getNotifyUrl() {
1143 $url = CRM_Utils_System::url(
1144 'civicrm/payment/ipn/' . $this->_paymentProcessor['id'],
1145 array(),
1146 TRUE,
1147 NULL,
1148 FALSE
1149 );
1150 return (stristr($url, '.')) ? $url : '';
1151 }
1152
1153 /**
1154 * Calling this from outside the payment subsystem is deprecated - use doPayment.
1155 *
1156 * Does a server to server payment transaction.
1157 *
1158 * @param array $params
1159 * Assoc array of input parameters for this transaction.
1160 *
1161 * @return array
1162 * the result in an nice formatted array (or an error object - but throwing exceptions is preferred)
1163 */
1164 protected function doDirectPayment(&$params) {
1165 return $params;
1166 }
1167
1168 /**
1169 * Process payment - this function wraps around both doTransferCheckout and doDirectPayment.
1170 *
1171 * The function ensures an exception is thrown & moves some of this logic out of the form layer and makes the forms
1172 * more agnostic.
1173 *
1174 * Payment processors should set payment_status_id. This function adds some historical defaults ie. the
1175 * assumption that if a 'doDirectPayment' processors comes back it completed the transaction & in fact
1176 * doTransferCheckout would not traditionally come back.
1177 *
1178 * doDirectPayment does not do an immediate payment for Authorize.net or Paypal so the default is assumed
1179 * to be Pending.
1180 *
1181 * Once this function is fully rolled out then it will be preferred for processors to throw exceptions than to
1182 * return Error objects
1183 *
1184 * @param array $params
1185 *
1186 * @param string $component
1187 *
1188 * @return array
1189 * Result array
1190 *
1191 * @throws \Civi\Payment\Exception\PaymentProcessorException
1192 */
1193 public function doPayment(&$params, $component = 'contribute') {
1194 $this->_component = $component;
1195 $statuses = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id', 'validate');
1196
1197 // If we have a $0 amount, skip call to processor and set payment_status to Completed.
1198 // Conceivably a processor might override this - perhaps for setting up a token - but we don't
1199 // have an example of that at the mome.
1200 if ($params['amount'] == 0) {
1201 $result['payment_status_id'] = array_search('Completed', $statuses);
1202 return $result;
1203 }
1204
1205 if ($this->_paymentProcessor['billing_mode'] == 4) {
1206 $result = $this->doTransferCheckout($params, $component);
1207 if (is_array($result) && !isset($result['payment_status_id'])) {
1208 $result['payment_status_id'] = array_search('Pending', $statuses);
1209 }
1210 }
1211 else {
1212 $result = $this->doDirectPayment($params, $component);
1213 if (is_array($result) && !isset($result['payment_status_id'])) {
1214 if (!empty($params['is_recur'])) {
1215 // See comment block.
1216 $result['payment_status_id'] = array_search('Pending', $statuses);
1217 }
1218 else {
1219 $result['payment_status_id'] = array_search('Completed', $statuses);
1220 }
1221 }
1222 }
1223 if (is_a($result, 'CRM_Core_Error')) {
1224 throw new PaymentProcessorException(CRM_Core_Error::getMessages($result));
1225 }
1226 return $result;
1227 }
1228
1229 /**
1230 * Query payment processor for details about a transaction.
1231 *
1232 * @param array $params
1233 * Array of parameters containing one of:
1234 * - trxn_id Id of an individual transaction.
1235 * - processor_id Id of a recurring contribution series as stored in the civicrm_contribution_recur table.
1236 *
1237 * @return array
1238 * Extra parameters retrieved.
1239 * Any parameters retrievable through this should be documented in the function comments at
1240 * CRM_Core_Payment::doQuery. Currently:
1241 * - fee_amount Amount of fee paid
1242 */
1243 public function doQuery($params) {
1244 return array();
1245 }
1246
1247 /**
1248 * This function checks to see if we have the right config values.
1249 *
1250 * @return string
1251 * the error message if any
1252 */
1253 abstract protected function checkConfig();
1254
1255 /**
1256 * Redirect for paypal.
1257 *
1258 * @todo move to paypal class or remove
1259 *
1260 * @param $paymentProcessor
1261 *
1262 * @return bool
1263 */
1264 public static function paypalRedirect(&$paymentProcessor) {
1265 if (!$paymentProcessor) {
1266 return FALSE;
1267 }
1268
1269 if (isset($_GET['payment_date']) &&
1270 isset($_GET['merchant_return_link']) &&
1271 CRM_Utils_Array::value('payment_status', $_GET) == 'Completed' &&
1272 $paymentProcessor['payment_processor_type'] == "PayPal_Standard"
1273 ) {
1274 return TRUE;
1275 }
1276
1277 return FALSE;
1278 }
1279
1280 /**
1281 * Handle incoming payment notification.
1282 *
1283 * IPNs, also called silent posts are notifications of payment outcomes or activity on an external site.
1284 *
1285 * @todo move to0 \Civi\Payment\System factory method
1286 * Page callback for civicrm/payment/ipn
1287 */
1288 public static function handleIPN() {
1289 self::handlePaymentMethod(
1290 'PaymentNotification',
1291 array(
1292 'processor_name' => @$_GET['processor_name'],
1293 'processor_id' => @$_GET['processor_id'],
1294 'mode' => @$_GET['mode'],
1295 )
1296 );
1297 CRM_Utils_System::civiExit();
1298 }
1299
1300 /**
1301 * Payment callback handler.
1302 *
1303 * The processor_name or processor_id is passed in.
1304 * Note that processor_id is more reliable as one site may have more than one instance of a
1305 * processor & ideally the processor will be validating the results
1306 * Load requested payment processor and call that processor's handle<$method> method
1307 *
1308 * @todo move to \Civi\Payment\System factory method
1309 *
1310 * @param string $method
1311 * 'PaymentNotification' or 'PaymentCron'
1312 * @param array $params
1313 *
1314 * @throws \CRM_Core_Exception
1315 * @throws \Exception
1316 */
1317 public static function handlePaymentMethod($method, $params = array()) {
1318 if (!isset($params['processor_id']) && !isset($params['processor_name'])) {
1319 $q = explode('/', CRM_Utils_Array::value(CRM_Core_Config::singleton()->userFrameworkURLVar, $_GET, ''));
1320 $lastParam = array_pop($q);
1321 if (is_numeric($lastParam)) {
1322 $params['processor_id'] = $_GET['processor_id'] = $lastParam;
1323 }
1324 else {
1325 self::logPaymentNotification($params);
1326 throw new CRM_Core_Exception("Either 'processor_id' (recommended) or 'processor_name' (deprecated) is required for payment callback.");
1327 }
1328 }
1329
1330 self::logPaymentNotification($params);
1331
1332 $sql = "SELECT ppt.class_name, ppt.name as processor_name, pp.id AS processor_id
1333 FROM civicrm_payment_processor_type ppt
1334 INNER JOIN civicrm_payment_processor pp
1335 ON pp.payment_processor_type_id = ppt.id
1336 AND pp.is_active";
1337
1338 if (isset($params['processor_id'])) {
1339 $sql .= " WHERE pp.id = %2";
1340 $args[2] = array($params['processor_id'], 'Integer');
1341 $notFound = ts("No active instances of payment processor %1 were found.", array(1 => $params['processor_id']));
1342 }
1343 else {
1344 // This is called when processor_name is passed - passing processor_id instead is recommended.
1345 $sql .= " WHERE ppt.name = %2 AND pp.is_test = %1";
1346 $args[1] = array(
1347 (CRM_Utils_Array::value('mode', $params) == 'test') ? 1 : 0,
1348 'Integer',
1349 );
1350 $args[2] = array($params['processor_name'], 'String');
1351 $notFound = ts("No active instances of payment processor '%1' were found.", array(1 => $params['processor_name']));
1352 }
1353
1354 $dao = CRM_Core_DAO::executeQuery($sql, $args);
1355
1356 // Check whether we found anything at all.
1357 if (!$dao->N) {
1358 CRM_Core_Error::fatal($notFound);
1359 }
1360
1361 $method = 'handle' . $method;
1362 $extension_instance_found = FALSE;
1363
1364 // In all likelihood, we'll just end up with the one instance returned here. But it's
1365 // possible we may get more. Hence, iterate through all instances ..
1366
1367 while ($dao->fetch()) {
1368 // Check pp is extension - is this still required - surely the singleton below handles it.
1369 $ext = CRM_Extension_System::singleton()->getMapper();
1370 if ($ext->isExtensionKey($dao->class_name)) {
1371 $paymentClass = $ext->keyToClass($dao->class_name, 'payment');
1372 require_once $ext->classToPath($paymentClass);
1373 }
1374
1375 $processorInstance = System::singleton()->getById($dao->processor_id);
1376
1377 // Should never be empty - we already established this processor_id exists and is active.
1378 if (empty($processorInstance)) {
1379 continue;
1380 }
1381
1382 // Does PP implement this method, and can we call it?
1383 if (!method_exists($processorInstance, $method) ||
1384 !is_callable(array($processorInstance, $method))
1385 ) {
1386 // on the off chance there is a double implementation of this processor we should keep looking for another
1387 // note that passing processor_id is more reliable & we should work to deprecate processor_name
1388 continue;
1389 }
1390
1391 // Everything, it seems, is ok - execute pp callback handler
1392 $processorInstance->$method();
1393 $extension_instance_found = TRUE;
1394 }
1395
1396 // Call IPN postIPNProcess hook to allow for custom processing of IPN data.
1397 $IPNParams = array_merge($_GET, $_REQUEST);
1398 CRM_Utils_Hook::postIPNProcess($IPNParams);
1399 if (!$extension_instance_found) {
1400 $message = "No extension instances of the '%1' payment processor were found.<br />" .
1401 "%2 method is unsupported in legacy payment processors.";
1402 CRM_Core_Error::fatal(ts($message, array(1 => $params['processor_name'], 2 => $method)));
1403 }
1404 }
1405
1406 /**
1407 * Check whether a method is present ( & supported ) by the payment processor object.
1408 *
1409 * @deprecated - use $paymentProcessor->supports(array('cancelRecurring');
1410 *
1411 * @param string $method
1412 * Method to check for.
1413 *
1414 * @return bool
1415 */
1416 public function isSupported($method) {
1417 return method_exists(CRM_Utils_System::getClassName($this), $method);
1418 }
1419
1420 /**
1421 * Some processors replace the form submit button with their own.
1422 *
1423 * Returning false here will leave the button off front end forms.
1424 *
1425 * At this stage there is zero cross-over between back-office processors and processors that suppress the submit.
1426 */
1427 public function isSuppressSubmitButtons() {
1428 return FALSE;
1429 }
1430
1431 /**
1432 * Checks to see if invoice_id already exists in db.
1433 *
1434 * It's arguable if this belongs in the payment subsystem at all but since several processors implement it
1435 * it is better to standardise to being here.
1436 *
1437 * @param int $invoiceId The ID to check.
1438 *
1439 * @param null $contributionID
1440 * If a contribution exists pass in the contribution ID.
1441 *
1442 * @return bool
1443 * True if invoice ID otherwise exists, else false
1444 */
1445 protected function checkDupe($invoiceId, $contributionID = NULL) {
1446 $contribution = new CRM_Contribute_DAO_Contribution();
1447 $contribution->invoice_id = $invoiceId;
1448 if ($contributionID) {
1449 $contribution->whereAdd("id <> $contributionID");
1450 }
1451 return $contribution->find();
1452 }
1453
1454 /**
1455 * Get url for users to manage this recurring contribution for this processor.
1456 *
1457 * @param int $entityID
1458 * @param null $entity
1459 * @param string $action
1460 *
1461 * @return string
1462 */
1463 public function subscriptionURL($entityID = NULL, $entity = NULL, $action = 'cancel') {
1464 // Set URL
1465 switch ($action) {
1466 case 'cancel':
1467 $url = 'civicrm/contribute/unsubscribe';
1468 break;
1469
1470 case 'billing':
1471 //in notify mode don't return the update billing url
1472 if (!$this->supports('updateSubscriptionBillingInfo')) {
1473 return NULL;
1474 }
1475 $url = 'civicrm/contribute/updatebilling';
1476 break;
1477
1478 case 'update':
1479 $url = 'civicrm/contribute/updaterecur';
1480 break;
1481 }
1482
1483 $userId = CRM_Core_Session::singleton()->get('userID');
1484 $contactID = 0;
1485 $checksumValue = '';
1486 $entityArg = '';
1487
1488 // Find related Contact
1489 if ($entityID) {
1490 switch ($entity) {
1491 case 'membership':
1492 $contactID = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $entityID, "contact_id");
1493 $entityArg = 'mid';
1494 break;
1495
1496 case 'contribution':
1497 $contactID = CRM_Core_DAO::getFieldValue("CRM_Contribute_DAO_Contribution", $entityID, "contact_id");
1498 $entityArg = 'coid';
1499 break;
1500
1501 case 'recur':
1502 $sql = "
1503 SELECT DISTINCT con.contact_id
1504 FROM civicrm_contribution_recur rec
1505 INNER JOIN civicrm_contribution con ON ( con.contribution_recur_id = rec.id )
1506 WHERE rec.id = %1";
1507 $contactID = CRM_Core_DAO::singleValueQuery($sql, array(1 => array($entityID, 'Integer')));
1508 $entityArg = 'crid';
1509 break;
1510 }
1511 }
1512
1513 // Add entity arguments
1514 if ($entityArg != '') {
1515 // Add checksum argument
1516 if ($contactID != 0 && $userId != $contactID) {
1517 $checksumValue = '&cs=' . CRM_Contact_BAO_Contact_Utils::generateChecksum($contactID, NULL, 'inf');
1518 }
1519 return CRM_Utils_System::url($url, "reset=1&{$entityArg}={$entityID}{$checksumValue}", TRUE, NULL, FALSE, TRUE);
1520 }
1521
1522 // Else login URL
1523 if ($this->supports('accountLoginURL')) {
1524 return $this->accountLoginURL();
1525 }
1526
1527 // Else default
1528 return isset($this->_paymentProcessor['url_recur']) ? $this->_paymentProcessor['url_recur'] : '';
1529 }
1530
1531 /**
1532 * Get description of payment to pass to processor.
1533 *
1534 * This is often what people see in the interface so we want to get
1535 * as much unique information in as possible within the field length (& presumably the early part of the field)
1536 *
1537 * People seeing these can be assumed to be advanced users so quantity of information probably trumps
1538 * having field names to clarify
1539 *
1540 * @param array $params
1541 * @param int $length
1542 *
1543 * @return string
1544 */
1545 protected function getPaymentDescription($params, $length = 24) {
1546 $parts = array('contactID', 'contributionID', 'description', 'billing_first_name', 'billing_last_name');
1547 $validParts = array();
1548 if (isset($params['description'])) {
1549 $uninformativeStrings = array(ts('Online Event Registration: '), ts('Online Contribution: '));
1550 $params['description'] = str_replace($uninformativeStrings, '', $params['description']);
1551 }
1552 foreach ($parts as $part) {
1553 if ((!empty($params[$part]))) {
1554 $validParts[] = $params[$part];
1555 }
1556 }
1557 return substr(implode('-', $validParts), 0, $length);
1558 }
1559
1560 /**
1561 * Checks if backoffice recurring edit is allowed
1562 *
1563 * @return bool
1564 */
1565 public function supportsEditRecurringContribution() {
1566 return FALSE;
1567 }
1568
1569 /**
1570 * Does this processor support changing the amount for recurring contributions through code.
1571 *
1572 * If the processor returns true then it must be possible to update the amount from within CiviCRM
1573 * that will be updated at the payment processor.
1574 *
1575 * @return bool
1576 */
1577 protected function supportsChangeSubscriptionAmount() {
1578 return method_exists(CRM_Utils_System::getClassName($this), 'changeSubscriptionAmount');
1579 }
1580
1581 /**
1582 * Checks if payment processor supports recurring contributions
1583 *
1584 * @return bool
1585 */
1586 public function supportsRecurring() {
1587 if (!empty($this->_paymentProcessor['is_recur'])) {
1588 return TRUE;
1589 }
1590 return FALSE;
1591 }
1592
1593 /**
1594 * Checks if payment processor supports an account login URL
1595 * TODO: This is checked by self::subscriptionURL but is only used if no entityID is found.
1596 * TODO: It is implemented by AuthorizeNET, any others?
1597 *
1598 * @return bool
1599 */
1600 protected function supportsAccountLoginURL() {
1601 return method_exists(CRM_Utils_System::getClassName($this), 'accountLoginURL');
1602 }
1603
1604 /**
1605 * Should a receipt be sent out for a pending payment.
1606 *
1607 * e.g for traditional pay later & ones with a delayed settlement a pending receipt makes sense.
1608 */
1609 public function isSendReceiptForPending() {
1610 return FALSE;
1611 }
1612
1613 }