3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * base class for building payment block for online contribution / event pages
39 class CRM_Core_Payment_ProcessorForm
{
41 static function preProcess(&$form, $type = NULL, $mode = NULL ) {
46 $form->_type
= CRM_Utils_Request
::retrieve('type', 'String', $form);
50 $form->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($form->_type
, $form->_mode
);
53 $form->set('paymentProcessor', $form->_paymentProcessor
);
55 // also set cancel subscription url
56 if (!empty($form->_paymentProcessor
['is_recur']) && !empty($form->_values
['is_recur'])) {
57 $form->_paymentObject
= &CRM_Core_Payment
::singleton($mode, $form->_paymentProcessor
, $form);
58 $form->_values
['cancelSubscriptionUrl'] = $form->_paymentObject
->subscriptionURL();
61 //checks after setting $form->_paymentProcessor
62 // we do this outside of the above conditional to avoid
63 // saving the country/state list in the session (which could be huge)
65 if (($form->_paymentProcessor
['billing_mode'] & CRM_Core_Payment
::BILLING_MODE_FORM
) && !empty($form->_values
['is_monetary'])) {
66 if ($form->_paymentProcessor
['payment_type'] & CRM_Core_Payment
::PAYMENT_TYPE_DIRECT_DEBIT
) {
67 CRM_Core_Payment_Form
::setDirectDebitFields($form);
70 CRM_Core_Payment_Form
::setCreditCardFields($form);
74 $form->assign_by_ref('paymentProcessor', $form->_paymentProcessor
);
76 // check if this is a paypal auto return and redirect accordingly
77 if (CRM_Core_Payment
::paypalRedirect($form->_paymentProcessor
)) {
78 $url = CRM_Utils_System
::url('civicrm/contribute/transact',
79 "_qf_ThankYou_display=1&qfKey={$form->controller->_key}"
81 CRM_Utils_System
::redirect($url);
84 // make sure we have a valid payment class, else abort
85 if (!empty($form->_values
['is_monetary']) &&
86 !$form->_paymentProcessor
['class_name'] && empty($form->_values
['is_pay_later'])) {
87 CRM_Core_Error
::fatal(ts('Payment processor is not set for this page'));
90 if (!empty($form->_membershipBlock
) && !empty($form->_membershipBlock
['is_separate_payment']) &&
91 (!empty($form->_paymentProcessor
['class_name']) &&
92 !(CRM_Utils_Array
::value('billing_mode', $form->_paymentProcessor
) & CRM_Core_Payment
::BILLING_MODE_FORM
)
96 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',
97 array(1 => $form->_paymentProcessor
['payment_processor_type'])
103 static function buildQuickform(&$form) {
104 $form->addElement('hidden', 'hidden_processor', 1);
106 $profileAddressFields = $form->get('profileAddressFields');
107 if (!empty($profileAddressFields)) {
108 $form->assign('profileAddressFields', $profileAddressFields);
111 // check if show billing setting is enabled
112 if ($form->getVar( '_ppType' ) == 0 && $form->_isBillingAddressRequiredForPayLater
) {
113 CRM_Core_Payment_Form
::buildAddressBlock($form);
117 // before we do this lets see if the payment processor has implemented a buildForm method
118 if (method_exists($form->_paymentProcessor
['instance'], 'buildForm') &&
119 is_callable(array($form->_paymentProcessor
['instance'], 'buildForm'))) {
120 // the payment processor implements the buildForm function, let the payment
121 // processor do the work
122 $form->_paymentProcessor
['instance']->buildForm($form);
126 if (($form->_paymentProcessor
['payment_type'] & CRM_Core_Payment
::PAYMENT_TYPE_DIRECT_DEBIT
)) {
127 CRM_Core_Payment_Form
::buildDirectDebit($form);
129 elseif (($form->_paymentProcessor
['payment_type'] & CRM_Core_Payment
::PAYMENT_TYPE_CREDIT_CARD
)) {
130 CRM_Core_Payment_Form
::buildCreditCard($form);