CRM/Core/Payment add missing code blocks (autogenerated)
[civicrm-core.git] / CRM / Core / Payment / ProcessorForm.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06b69b18 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
37 * base class for building payment block for online contribution / event pages
38 */
39class CRM_Core_Payment_ProcessorForm {
40
6c786a9b
EM
41 /**
42 * @param $form
43 * @param null $type
44 * @param null $mode
45 *
46 * @throws Exception
47 */
6a488035
TO
48 static function preProcess(&$form, $type = NULL, $mode = NULL ) {
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
60 $form->set('paymentProcessor', $form->_paymentProcessor);
61
62 // also set cancel subscription url
8cc574cf 63 if (!empty($form->_paymentProcessor['is_recur']) && !empty($form->_values['is_recur'])) {
6a488035
TO
64 $form->_paymentObject = &CRM_Core_Payment::singleton($mode, $form->_paymentProcessor, $form);
65 $form->_values['cancelSubscriptionUrl'] = $form->_paymentObject->subscriptionURL();
66 }
67
68 //checks after setting $form->_paymentProcessor
69 // we do this outside of the above conditional to avoid
70 // saving the country/state list in the session (which could be huge)
71
8cc574cf 72 if (($form->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM) && !empty($form->_values['is_monetary'])) {
6a488035
TO
73 if ($form->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT) {
74 CRM_Core_Payment_Form::setDirectDebitFields($form);
75 }
76 else {
77 CRM_Core_Payment_Form::setCreditCardFields($form);
78 }
79 }
80
81 $form->assign_by_ref('paymentProcessor', $form->_paymentProcessor);
82
83 // check if this is a paypal auto return and redirect accordingly
84 if (CRM_Core_Payment::paypalRedirect($form->_paymentProcessor)) {
85 $url = CRM_Utils_System::url('civicrm/contribute/transact',
86 "_qf_ThankYou_display=1&qfKey={$form->controller->_key}"
87 );
88 CRM_Utils_System::redirect($url);
89 }
90
91 // make sure we have a valid payment class, else abort
a7488080 92 if (!empty($form->_values['is_monetary']) &&
8cc574cf 93 !$form->_paymentProcessor['class_name'] && empty($form->_values['is_pay_later'])) {
6a488035
TO
94 CRM_Core_Error::fatal(ts('Payment processor is not set for this page'));
95 }
96
8cc574cf
CW
97 if (!empty($form->_membershipBlock) && !empty($form->_membershipBlock['is_separate_payment']) &&
98 (!empty($form->_paymentProcessor['class_name']) &&
6a488035
TO
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
6c786a9b
EM
110 /**
111 * @param $form
112 */
6a488035
TO
113 static function buildQuickform(&$form) {
114 $form->addElement('hidden', 'hidden_processor', 1);
115
4839c695
KJ
116 $profileAddressFields = $form->get('profileAddressFields');
117 if (!empty($profileAddressFields)) {
118 $form->assign('profileAddressFields', $profileAddressFields);
119 }
120
6a488035
TO
121 // before we do this lets see if the payment processor has implemented a buildForm method
122 if (method_exists($form->_paymentProcessor['instance'], 'buildForm') &&
123 is_callable(array($form->_paymentProcessor['instance'], 'buildForm'))) {
124 // the payment processor implements the buildForm function, let the payment
125 // processor do the work
126 $form->_paymentProcessor['instance']->buildForm($form);
127 return;
128 }
129
130 if (($form->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT)) {
131 CRM_Core_Payment_Form::buildDirectDebit($form);
132 }
133 elseif (($form->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_CREDIT_CARD)) {
134 CRM_Core_Payment_Form::buildCreditCard($form);
135 }
136 }
137}
138