Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * base class for building payment block for online contribution / event pages | |
38 | */ | |
39 | class CRM_Core_Payment_ProcessorForm { | |
40 | ||
41 | static function preProcess(&$form, $type = NULL, $mode = NULL ) { | |
42 | if ($type) { | |
43 | $form->_type = $type; | |
44 | } | |
45 | else { | |
46 | $form->_type = CRM_Utils_Request::retrieve('type', 'String', $form); | |
47 | } | |
48 | ||
49 | if ($form->_type) { | |
50 | $form->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($form->_type, $form->_mode); | |
51 | } | |
52 | ||
53 | $form->set('paymentProcessor', $form->_paymentProcessor); | |
54 | ||
55 | // also set cancel subscription url | |
56 | if (CRM_Utils_Array::value('is_recur', $form->_paymentProcessor) && | |
57 | CRM_Utils_Array::value('is_recur', $form->_values) | |
58 | ) { | |
59 | $form->_paymentObject = &CRM_Core_Payment::singleton($mode, $form->_paymentProcessor, $form); | |
60 | $form->_values['cancelSubscriptionUrl'] = $form->_paymentObject->subscriptionURL(); | |
61 | } | |
62 | ||
63 | //checks after setting $form->_paymentProcessor | |
64 | // we do this outside of the above conditional to avoid | |
65 | // saving the country/state list in the session (which could be huge) | |
66 | ||
67 | if (($form->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM) && | |
68 | CRM_Utils_Array::value('is_monetary', $form->_values) | |
69 | ) { | |
70 | if ($form->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT) { | |
71 | CRM_Core_Payment_Form::setDirectDebitFields($form); | |
72 | } | |
73 | else { | |
74 | CRM_Core_Payment_Form::setCreditCardFields($form); | |
75 | } | |
76 | } | |
77 | ||
78 | $form->assign_by_ref('paymentProcessor', $form->_paymentProcessor); | |
79 | ||
80 | // check if this is a paypal auto return and redirect accordingly | |
81 | if (CRM_Core_Payment::paypalRedirect($form->_paymentProcessor)) { | |
82 | $url = CRM_Utils_System::url('civicrm/contribute/transact', | |
83 | "_qf_ThankYou_display=1&qfKey={$form->controller->_key}" | |
84 | ); | |
85 | CRM_Utils_System::redirect($url); | |
86 | } | |
87 | ||
88 | // make sure we have a valid payment class, else abort | |
89 | if (CRM_Utils_Array::value('is_monetary', $form->_values) && | |
90 | !$form->_paymentProcessor['class_name'] && | |
91 | !CRM_Utils_Array::value('is_pay_later', $form->_values) | |
92 | ) { | |
93 | CRM_Core_Error::fatal(ts('Payment processor is not set for this page')); | |
94 | } | |
95 | ||
96 | if (!empty($form->_membershipBlock) && | |
97 | CRM_Utils_Array::value('is_separate_payment', $form->_membershipBlock) && | |
98 | (CRM_Utils_Array::value('class_name', $form->_paymentProcessor) && | |
99 | !(CRM_Utils_Array::value('billing_mode', $form->_paymentProcessor) & CRM_Core_Payment::BILLING_MODE_FORM) | |
100 | ) | |
101 | ) { | |
102 | ||
103 | 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', | |
104 | array(1 => $form->_paymentProcessor['payment_processor_type']) | |
c48c8f82 CW |
105 | ) |
106 | ); | |
6a488035 | 107 | } |
6a488035 TO |
108 | } |
109 | ||
110 | static function buildQuickform(&$form) { | |
111 | $form->addElement('hidden', 'hidden_processor', 1); | |
112 | ||
4839c695 KJ |
113 | $profileAddressFields = $form->get('profileAddressFields'); |
114 | if (!empty($profileAddressFields)) { | |
115 | $form->assign('profileAddressFields', $profileAddressFields); | |
116 | } | |
117 | ||
6a488035 TO |
118 | // before we do this lets see if the payment processor has implemented a buildForm method |
119 | if (method_exists($form->_paymentProcessor['instance'], 'buildForm') && | |
120 | is_callable(array($form->_paymentProcessor['instance'], 'buildForm'))) { | |
121 | // the payment processor implements the buildForm function, let the payment | |
122 | // processor do the work | |
123 | $form->_paymentProcessor['instance']->buildForm($form); | |
124 | return; | |
125 | } | |
126 | ||
127 | if (($form->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT)) { | |
128 | CRM_Core_Payment_Form::buildDirectDebit($form); | |
129 | } | |
130 | elseif (($form->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_CREDIT_CARD)) { | |
131 | CRM_Core_Payment_Form::buildCreditCard($form); | |
132 | } | |
133 | } | |
134 | } | |
135 |