Commit | Line | Data |
---|---|---|
1d1fee72 | 1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.7 | | |
5 | +--------------------------------------------------------------------+ | |
0f03f337 | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
1d1fee72 | 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 | |
0f03f337 | 31 | * @copyright CiviCRM LLC (c) 2004-2017 |
1d1fee72 | 32 | */ |
33 | class CRM_Core_Payment_Manual extends CRM_Core_Payment { | |
34 | ||
35 | protected $result; | |
36 | ||
37 | /** | |
38 | * This function checks to see if we have the right config values. | |
1d1fee72 | 39 | */ |
f48e6cf7 | 40 | public function checkConfig() {} |
1d1fee72 | 41 | |
42 | /** | |
43 | * Get billing fields required for this processor. | |
44 | * | |
45 | * We apply the existing default of returning fields only for payment processor type 1. Processors can override to | |
46 | * alter. | |
47 | * | |
48 | * @param int $billingLocationID | |
49 | * | |
50 | * @return array | |
51 | */ | |
52 | public function getBillingAddressFields($billingLocationID = NULL) { | |
53 | if (!$billingLocationID) { | |
54 | // Note that although the billing id is passed around the forms the idea that it would be anything other than | |
55 | // the result of the function below doesn't seem to have eventuated. | |
56 | // So taking this as a param is possibly something to be removed in favour of the standard default. | |
57 | $billingLocationID = CRM_Core_BAO_LocationType::getBilling(); | |
58 | } | |
59 | ||
60 | // Only handle pseudo-profile billing for now. | |
61 | if ($this->billingProfile == 'billing') { | |
62 | // @todo - use profile api to retrieve this - either as pseudo-profile or (better) set up billing | |
63 | // as a reserved profile in the DB and (even better) allow the profile to be selected | |
64 | // on the form instead of just 'billing for pay=later bool' | |
65 | return array( | |
66 | 'first_name' => 'billing_first_name', | |
67 | 'middle_name' => 'billing_middle_name', | |
68 | 'last_name' => 'billing_last_name', | |
69 | 'street_address' => "billing_street_address-{$billingLocationID}", | |
70 | 'city' => "billing_city-{$billingLocationID}", | |
71 | 'country' => "billing_country_id-{$billingLocationID}", | |
72 | 'state_province' => "billing_state_province_id-{$billingLocationID}", | |
73 | 'postal_code' => "billing_postal_code-{$billingLocationID}", | |
74 | ); | |
75 | } | |
76 | else { | |
77 | return array(); | |
78 | } | |
79 | } | |
80 | ||
81 | /** | |
82 | * Get array of fields that should be displayed on the payment form. | |
83 | * | |
84 | * @return array | |
85 | */ | |
86 | public function getPaymentFormFields() { | |
794d4fc0 | 87 | if (!$this->isBackOffice()) { |
88 | return array(); | |
89 | } | |
90 | ||
91 | $paymentInstrument = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', $this->getPaymentInstrumentID()); | |
92 | if ($paymentInstrument === 'Credit Card') { | |
93 | // @todo - return credit_card_type field once the underlying code works to extract this field. | |
94 | // Note the problem is this should be stored in civicrm_financial_trxn.credit_card_type. | |
95 | // However there is an ambiguity as that field is an integer & should hence be called | |
96 | // credit_card_type_id, or it should store 'visa' It probably makes sense to fix that before going much | |
97 | // further as the code I've seen makes it clear that it will require work arounds. | |
98 | return array('pan_truncation'); | |
99 | } | |
100 | elseif ($paymentInstrument === 'Check') { | |
101 | // Really we should render check_number here, but we need to review how we edit | |
102 | // check_numebr since we expose it as editable on the contribution form, | |
103 | // even though it should only be editable from a transation specific form. | |
104 | return array(); | |
105 | } | |
1d1fee72 | 106 | return array(); |
107 | } | |
794d4fc0 | 108 | |
1d1fee72 | 109 | /** |
110 | * Process payment. | |
111 | * | |
112 | * The function ensures an exception is thrown & moves some of this logic out of the form layer and makes the forms | |
113 | * more agnostic. | |
114 | * | |
115 | * @param array $params | |
116 | * | |
117 | * @param string $component | |
118 | * | |
119 | * @return array | |
120 | * Result array | |
121 | * | |
122 | * @throws \Civi\Payment\Exception\PaymentProcessorException | |
123 | */ | |
124 | public function doPayment(&$params, $component = 'contribute') { | |
125 | $params['payment_status_id'] = $this->getResult(); | |
126 | return $params; | |
127 | } | |
128 | ||
129 | /** | |
130 | * Get the result of the payment. | |
131 | * | |
132 | * Usually this will be pending but the calling layer has a chance to set the result. | |
133 | * | |
134 | * This would apply in particular when the form accepts status id. | |
135 | * | |
136 | * Note that currently this payment class is only being used to manage the 'billing block' aspect | |
137 | * of pay later. However, a longer term idea is that by treating 'pay-later' as 'just another processor' | |
138 | * will allow code simplification. | |
139 | * | |
140 | * @return int | |
141 | */ | |
142 | protected function getResult() { | |
143 | if (!$this->result) { | |
144 | $this->setResult(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'status_id', 'Pending')); | |
145 | } | |
146 | return $this->result; | |
147 | } | |
148 | ||
149 | /** | |
150 | * Set the result to be returned. | |
151 | * | |
152 | * This would be set from outside the function where we want to pass on the status from the form. | |
153 | * | |
154 | * @param int $result | |
155 | */ | |
156 | public function setResult($result) { | |
157 | $this->result = $result; | |
158 | } | |
159 | ||
18135422 | 160 | /** |
161 | * Set payment instrument id. | |
162 | * | |
163 | * @param int $paymentInstrumentID | |
164 | */ | |
165 | public function setPaymentInstrumentID($paymentInstrumentID) { | |
166 | $this->paymentInstrumentID = $paymentInstrumentID; | |
167 | } | |
168 | ||
1d1fee72 | 169 | /** |
170 | * Get the name of the payment type. | |
171 | * | |
172 | * @return string | |
173 | */ | |
174 | public function getPaymentTypeName() { | |
175 | return 'pay-later'; | |
176 | } | |
177 | ||
178 | /** | |
179 | * Get the name of the payment type. | |
180 | * | |
181 | * @return string | |
182 | */ | |
183 | public function getPaymentTypeLabel() { | |
0dc4ef42 | 184 | return CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', $this->getPaymentInstrumentID()); |
1d1fee72 | 185 | } |
f48e6cf7 | 186 | |
ecb7ec32 | 187 | /** |
188 | * Declare that more than one payment can be processed at once. | |
189 | * | |
190 | * @return bool | |
191 | */ | |
192 | protected function supportsMultipleConcurrentPayments() { | |
193 | return TRUE; | |
194 | } | |
195 | ||
95974e8e DG |
196 | /** |
197 | * Checks if backoffice recurring edit is allowed | |
198 | * | |
199 | * @return bool | |
200 | */ | |
201 | public function supportsEditRecurringContribution() { | |
202 | return TRUE; | |
203 | } | |
204 | ||
18135422 | 205 | /** |
206 | * Are back office payments supported. | |
207 | * | |
208 | * @return bool | |
209 | */ | |
210 | protected function supportsBackOffice() { | |
211 | return TRUE; | |
212 | } | |
213 | ||
95974e8e | 214 | /** |
3e473c0b | 215 | * Submit a manual payment. |
95974e8e DG |
216 | * |
217 | * @param array $params | |
218 | * Assoc array of input parameters for this transaction. | |
3e473c0b | 219 | * |
220 | * @return array | |
95974e8e DG |
221 | */ |
222 | public function doDirectPayment(&$params) { | |
223 | $statuses = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id'); | |
224 | if ($params['is_pay_later']) { | |
225 | $result['payment_status_id'] = array_search('Pending', $statuses); | |
226 | } | |
227 | else { | |
228 | $result['payment_status_id'] = array_search('Completed', $statuses); | |
229 | } | |
3e473c0b | 230 | return $result; |
95974e8e DG |
231 | } |
232 | ||
cd3bc162 | 233 | /** |
234 | * Should a receipt be sent out for a pending payment. | |
235 | * | |
236 | * e.g for traditional pay later & ones with a delayed settlement a pending receipt makes sense. | |
237 | */ | |
238 | public function isSendReceiptForPending() { | |
239 | return TRUE; | |
240 | } | |
241 | ||
1d1fee72 | 242 | } |