Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 | 27 | |
31d31a05 | 28 | use Civi\Payment\System; |
6a488035 TO |
29 | /** |
30 | * | |
31 | * @package CRM | |
e7112fa7 | 32 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
33 | */ |
34 | ||
31d31a05 | 35 | |
6a488035 | 36 | /** |
31d31a05 | 37 | * Base class for building payment block for online contribution / event pages. |
6a488035 TO |
38 | */ |
39 | class CRM_Core_Payment_ProcessorForm { | |
40 | ||
6c786a9b | 41 | /** |
a9768188 | 42 | * @param CRM_Contribute_Form_Contribution_Main|CRM_Event_Form_Registration_Register|CRM_Financial_Form_Payment $form |
6c786a9b EM |
43 | * @param null $type |
44 | * @param null $mode | |
45 | * | |
46 | * @throws Exception | |
47 | */ | |
2aa397bc | 48 | public static function preProcess(&$form, $type = NULL, $mode = NULL) { |
6a488035 TO |
49 | if ($type) { |
50 | $form->_type = $type; | |
51 | } | |
52 | else { | |
53 | $form->_type = CRM_Utils_Request::retrieve('type', 'String', $form); | |
54 | } | |
55 | ||
56 | if ($form->_type) { | |
57 | $form->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($form->_type, $form->_mode); | |
58 | } | |
59 | ||
986905f5 | 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. | |
62 | return; | |
63 | } | |
6a488035 | 64 | $form->set('paymentProcessor', $form->_paymentProcessor); |
31d31a05 | 65 | $form->_paymentObject = Civi\Payment\System::singleton()->getByProcessor($form->_paymentProcessor); |
1ba4a3aa EM |
66 | |
67 | $form->assign('suppressSubmitButton', $form->_paymentObject->isSuppressSubmitButtons()); | |
6a488035 TO |
68 | |
69 | // also set cancel subscription url | |
8cc574cf | 70 | if (!empty($form->_paymentProcessor['is_recur']) && !empty($form->_values['is_recur'])) { |
6a488035 TO |
71 | $form->_values['cancelSubscriptionUrl'] = $form->_paymentObject->subscriptionURL(); |
72 | } | |
73 | ||
74 | //checks after setting $form->_paymentProcessor | |
75 | // we do this outside of the above conditional to avoid | |
76 | // saving the country/state list in the session (which could be huge) | |
1d1fee72 | 77 | CRM_Core_Payment_Form::setPaymentFieldsByProcessor( |
78 | $form, | |
79 | $form->_paymentProcessor, | |
80 | CRM_Utils_Request::retrieve('billing_profile_id', 'String') | |
81 | ); | |
6a488035 | 82 | |
6a488035 TO |
83 | $form->assign_by_ref('paymentProcessor', $form->_paymentProcessor); |
84 | ||
85 | // check if this is a paypal auto return and redirect accordingly | |
dde5a0ef | 86 | //@todo - determine if this is legacy and remove |
6a488035 TO |
87 | if (CRM_Core_Payment::paypalRedirect($form->_paymentProcessor)) { |
88 | $url = CRM_Utils_System::url('civicrm/contribute/transact', | |
89 | "_qf_ThankYou_display=1&qfKey={$form->controller->_key}" | |
90 | ); | |
91 | CRM_Utils_System::redirect($url); | |
92 | } | |
93 | ||
94 | // make sure we have a valid payment class, else abort | |
a7488080 | 95 | if (!empty($form->_values['is_monetary']) && |
353ffa53 TO |
96 | !$form->_paymentProcessor['class_name'] && empty($form->_values['is_pay_later']) |
97 | ) { | |
6a488035 TO |
98 | CRM_Core_Error::fatal(ts('Payment processor is not set for this page')); |
99 | } | |
100 | ||
8cc574cf CW |
101 | if (!empty($form->_membershipBlock) && !empty($form->_membershipBlock['is_separate_payment']) && |
102 | (!empty($form->_paymentProcessor['class_name']) && | |
75ead8de | 103 | !$form->_paymentObject->supports('MultipleConcurrentPayments') |
6a488035 TO |
104 | ) |
105 | ) { | |
106 | ||
107 | 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', | |
108 | array(1 => $form->_paymentProcessor['payment_processor_type']) | |
c48c8f82 CW |
109 | ) |
110 | ); | |
6a488035 | 111 | } |
6a488035 TO |
112 | } |
113 | ||
6c786a9b | 114 | /** |
9d421118 | 115 | * Build the payment processor form. |
116 | * | |
117 | * @param CRM_Core_Form $form | |
6c786a9b | 118 | */ |
00be9182 | 119 | public static function buildQuickform(&$form) { |
dde5a0ef | 120 | //@todo document why this addHidden is here |
01da20ea | 121 | //CRM-15743 - we should not set/create hidden element for pay later |
122 | // because payment processor is not selected | |
8bf11c13 | 123 | $processorId = $form->getVar('_paymentProcessorID'); |
1d1fee72 | 124 | $billing_profile_id = CRM_Utils_Request::retrieve('billing_profile_id', 'String'); |
125 | if (!empty($form->_values) && !empty($form->_values['is_billing_required'])) { | |
126 | $billing_profile_id = 'billing'; | |
127 | } | |
8bf11c13 | 128 | if (!empty($processorId)) { |
d1fcde00 | 129 | $form->addElement('hidden', 'hidden_processor', 1); |
130 | } | |
1d1fee72 | 131 | CRM_Core_Payment_Form::buildPaymentForm($form, $form->_paymentProcessor, $billing_profile_id, FALSE); |
6a488035 | 132 | } |
96025800 | 133 | |
6a488035 | 134 | } |