3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
28 use Civi\Payment\System
;
32 * @copyright CiviCRM LLC (c) 2004-2016
37 * Base class for building payment block for online contribution / event pages.
39 class CRM_Core_Payment_ProcessorForm
{
42 * @param CRM_Contribute_Form_Contribution_Main|CRM_Event_Form_Registration_Register|CRM_Financial_Form_Payment $form
48 public static function preProcess(&$form, $type = NULL, $mode = NULL) {
53 $form->_type
= CRM_Utils_Request
::retrieve('type', 'String', $form);
57 $form->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($form->_type
, $form->_mode
);
60 if (empty($form->_paymentProcessor
)) {
61 // This would happen when hitting the back-button on a multi-page form with a $0 selection in play.
64 $form->set('paymentProcessor', $form->_paymentProcessor
);
65 $form->_paymentObject
= System
::singleton()->getByProcessor($form->_paymentProcessor
);
67 $form->assign('suppressSubmitButton', $form->_paymentObject
->isSuppressSubmitButtons());
69 $form->assign('currency', CRM_Utils_Array
::value('currency', $form->_values
));
71 // also set cancel subscription url
72 if (!empty($form->_paymentProcessor
['is_recur']) && !empty($form->_values
['is_recur'])) {
73 $form->_values
['cancelSubscriptionUrl'] = $form->_paymentObject
->subscriptionURL(NULL, NULL, 'cancel');
76 //checks after setting $form->_paymentProcessor
77 // we do this outside of the above conditional to avoid
78 // saving the country/state list in the session (which could be huge)
79 CRM_Core_Payment_Form
::setPaymentFieldsByProcessor(
81 $form->_paymentProcessor
,
82 CRM_Utils_Request
::retrieve('billing_profile_id', 'String')
85 $form->assign_by_ref('paymentProcessor', $form->_paymentProcessor
);
87 // check if this is a paypal auto return and redirect accordingly
88 //@todo - determine if this is legacy and remove
89 if (CRM_Core_Payment
::paypalRedirect($form->_paymentProcessor
)) {
90 $url = CRM_Utils_System
::url('civicrm/contribute/transact',
91 "_qf_ThankYou_display=1&qfKey={$form->controller->_key}"
93 CRM_Utils_System
::redirect($url);
96 // make sure we have a valid payment class, else abort
97 if (!empty($form->_values
['is_monetary']) &&
98 !$form->_paymentProcessor
['class_name'] && empty($form->_values
['is_pay_later'])
100 CRM_Core_Error
::fatal(ts('Payment processor is not set for this page'));
103 if (!empty($form->_membershipBlock
) && !empty($form->_membershipBlock
['is_separate_payment']) &&
104 (!empty($form->_paymentProcessor
['class_name']) &&
105 !$form->_paymentObject
->supports('MultipleConcurrentPayments')
109 CRM_Core_Error
::fatal(ts('This contribution page is configured to support separate contribution and membership payments. This %1 plugin does not currently support multiple simultaneous payments, or the option to "Execute real-time monetary transactions" is disabled. Please contact the site administrator and notify them of this error',
110 array(1 => $form->_paymentProcessor
['payment_processor_type'])
117 * Build the payment processor form.
119 * @param CRM_Core_Form $form
121 public static function buildQuickform(&$form) {
122 //@todo document why this addHidden is here
123 //CRM-15743 - we should not set/create hidden element for pay later
124 // because payment processor is not selected
125 $processorId = $form->getVar('_paymentProcessorID');
126 $billing_profile_id = CRM_Utils_Request
::retrieve('billing_profile_id', 'String');
127 if (!empty($form->_values
) && !empty($form->_values
['is_billing_required'])) {
128 $billing_profile_id = 'billing';
130 if (!empty($processorId)) {
131 $form->addElement('hidden', 'hidden_processor', 1);
133 CRM_Core_Payment_Form
::buildPaymentForm($form, $form->_paymentProcessor
, $billing_profile_id, FALSE);