Commit | Line | Data |
---|---|---|
1d1fee72 | 1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
1d1fee72 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
1d1fee72 | 9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
1d1fee72 | 16 | */ |
17 | class CRM_Core_Payment_Manual extends CRM_Core_Payment { | |
18 | ||
19 | protected $result; | |
20 | ||
21 | /** | |
22 | * This function checks to see if we have the right config values. | |
1d1fee72 | 23 | */ |
f48e6cf7 | 24 | public function checkConfig() {} |
1d1fee72 | 25 | |
26 | /** | |
27 | * Get billing fields required for this processor. | |
28 | * | |
29 | * We apply the existing default of returning fields only for payment processor type 1. Processors can override to | |
30 | * alter. | |
31 | * | |
32 | * @param int $billingLocationID | |
33 | * | |
34 | * @return array | |
35 | */ | |
36 | public function getBillingAddressFields($billingLocationID = NULL) { | |
37 | if (!$billingLocationID) { | |
38 | // Note that although the billing id is passed around the forms the idea that it would be anything other than | |
39 | // the result of the function below doesn't seem to have eventuated. | |
40 | // So taking this as a param is possibly something to be removed in favour of the standard default. | |
41 | $billingLocationID = CRM_Core_BAO_LocationType::getBilling(); | |
42 | } | |
43 | ||
44 | // Only handle pseudo-profile billing for now. | |
45 | if ($this->billingProfile == 'billing') { | |
46 | // @todo - use profile api to retrieve this - either as pseudo-profile or (better) set up billing | |
47 | // as a reserved profile in the DB and (even better) allow the profile to be selected | |
48 | // on the form instead of just 'billing for pay=later bool' | |
be2fb01f | 49 | return [ |
1d1fee72 | 50 | 'first_name' => 'billing_first_name', |
51 | 'middle_name' => 'billing_middle_name', | |
52 | 'last_name' => 'billing_last_name', | |
53 | 'street_address' => "billing_street_address-{$billingLocationID}", | |
54 | 'city' => "billing_city-{$billingLocationID}", | |
55 | 'country' => "billing_country_id-{$billingLocationID}", | |
56 | 'state_province' => "billing_state_province_id-{$billingLocationID}", | |
57 | 'postal_code' => "billing_postal_code-{$billingLocationID}", | |
be2fb01f | 58 | ]; |
1d1fee72 | 59 | } |
60 | else { | |
be2fb01f | 61 | return []; |
1d1fee72 | 62 | } |
63 | } | |
64 | ||
65 | /** | |
66 | * Get array of fields that should be displayed on the payment form. | |
67 | * | |
68 | * @return array | |
69 | */ | |
70 | public function getPaymentFormFields() { | |
794d4fc0 | 71 | if (!$this->isBackOffice()) { |
be2fb01f | 72 | return []; |
794d4fc0 | 73 | } |
74 | ||
75 | $paymentInstrument = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', $this->getPaymentInstrumentID()); | |
76 | if ($paymentInstrument === 'Credit Card') { | |
be2fb01f | 77 | return ['credit_card_type', 'pan_truncation']; |
794d4fc0 | 78 | } |
79 | elseif ($paymentInstrument === 'Check') { | |
be2fb01f | 80 | return ['check_number']; |
794d4fc0 | 81 | } |
be2fb01f | 82 | return []; |
1d1fee72 | 83 | } |
794d4fc0 | 84 | |
1d1fee72 | 85 | /** |
86 | * Process payment. | |
87 | * | |
88 | * The function ensures an exception is thrown & moves some of this logic out of the form layer and makes the forms | |
89 | * more agnostic. | |
90 | * | |
91 | * @param array $params | |
92 | * | |
93 | * @param string $component | |
94 | * | |
95 | * @return array | |
96 | * Result array | |
97 | * | |
98 | * @throws \Civi\Payment\Exception\PaymentProcessorException | |
99 | */ | |
100 | public function doPayment(&$params, $component = 'contribute') { | |
101 | $params['payment_status_id'] = $this->getResult(); | |
102 | return $params; | |
103 | } | |
104 | ||
105 | /** | |
106 | * Get the result of the payment. | |
107 | * | |
108 | * Usually this will be pending but the calling layer has a chance to set the result. | |
109 | * | |
110 | * This would apply in particular when the form accepts status id. | |
111 | * | |
112 | * Note that currently this payment class is only being used to manage the 'billing block' aspect | |
113 | * of pay later. However, a longer term idea is that by treating 'pay-later' as 'just another processor' | |
114 | * will allow code simplification. | |
115 | * | |
116 | * @return int | |
117 | */ | |
118 | protected function getResult() { | |
119 | if (!$this->result) { | |
ac1493e4 | 120 | $this->setResult(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending')); |
1d1fee72 | 121 | } |
122 | return $this->result; | |
123 | } | |
124 | ||
125 | /** | |
126 | * Set the result to be returned. | |
127 | * | |
128 | * This would be set from outside the function where we want to pass on the status from the form. | |
129 | * | |
130 | * @param int $result | |
131 | */ | |
132 | public function setResult($result) { | |
133 | $this->result = $result; | |
134 | } | |
135 | ||
18135422 | 136 | /** |
137 | * Set payment instrument id. | |
138 | * | |
139 | * @param int $paymentInstrumentID | |
140 | */ | |
141 | public function setPaymentInstrumentID($paymentInstrumentID) { | |
142 | $this->paymentInstrumentID = $paymentInstrumentID; | |
143 | } | |
144 | ||
1d1fee72 | 145 | /** |
146 | * Get the name of the payment type. | |
147 | * | |
148 | * @return string | |
149 | */ | |
150 | public function getPaymentTypeName() { | |
151 | return 'pay-later'; | |
152 | } | |
153 | ||
154 | /** | |
155 | * Get the name of the payment type. | |
156 | * | |
157 | * @return string | |
158 | */ | |
159 | public function getPaymentTypeLabel() { | |
cf7b5c1f | 160 | return CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', $this->getPaymentInstrumentID()); |
1d1fee72 | 161 | } |
f48e6cf7 | 162 | |
c9058b9b MW |
163 | /** |
164 | * Are live payments supported - e.g dummy doesn't support this. | |
165 | * | |
166 | * @return bool | |
167 | */ | |
168 | protected function supportsLiveMode() { | |
169 | return TRUE; | |
170 | } | |
171 | ||
172 | /** | |
173 | * Are test payments supported. | |
174 | * | |
175 | * @return bool | |
176 | */ | |
177 | protected function supportsTestMode() { | |
178 | return TRUE; | |
179 | } | |
180 | ||
ecb7ec32 | 181 | /** |
182 | * Declare that more than one payment can be processed at once. | |
183 | * | |
184 | * @return bool | |
185 | */ | |
186 | protected function supportsMultipleConcurrentPayments() { | |
187 | return TRUE; | |
188 | } | |
189 | ||
95974e8e DG |
190 | /** |
191 | * Checks if backoffice recurring edit is allowed | |
192 | * | |
193 | * @return bool | |
194 | */ | |
195 | public function supportsEditRecurringContribution() { | |
196 | return TRUE; | |
197 | } | |
198 | ||
18135422 | 199 | /** |
200 | * Are back office payments supported. | |
201 | * | |
202 | * @return bool | |
203 | */ | |
204 | protected function supportsBackOffice() { | |
205 | return TRUE; | |
206 | } | |
207 | ||
6d7d7089 AS |
208 | /** |
209 | * Does the processor work without an email address? | |
210 | */ | |
211 | protected function supportsNoEmailProvided() { | |
212 | return TRUE; | |
213 | } | |
214 | ||
95974e8e | 215 | /** |
3e473c0b | 216 | * Submit a manual payment. |
95974e8e DG |
217 | * |
218 | * @param array $params | |
219 | * Assoc array of input parameters for this transaction. | |
3e473c0b | 220 | * |
221 | * @return array | |
95974e8e DG |
222 | */ |
223 | public function doDirectPayment(&$params) { | |
224 | $statuses = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id'); | |
225 | if ($params['is_pay_later']) { | |
226 | $result['payment_status_id'] = array_search('Pending', $statuses); | |
227 | } | |
228 | else { | |
229 | $result['payment_status_id'] = array_search('Completed', $statuses); | |
230 | } | |
3e473c0b | 231 | return $result; |
95974e8e DG |
232 | } |
233 | ||
cd3bc162 | 234 | /** |
235 | * Should a receipt be sent out for a pending payment. | |
236 | * | |
237 | * e.g for traditional pay later & ones with a delayed settlement a pending receipt makes sense. | |
238 | */ | |
239 | public function isSendReceiptForPending() { | |
240 | return TRUE; | |
241 | } | |
242 | ||
e364c762 | 243 | /** |
244 | * Get help text information (help, description, etc.) about this payment, | |
245 | * to display to the user. | |
246 | * | |
247 | * @param string $context | |
248 | * Context of the text. | |
249 | * Only explicitly supported contexts are handled without error. | |
250 | * Currently supported: | |
251 | * - contributionPageRecurringHelp (params: is_recur_installments, is_email_receipt) | |
252 | * | |
253 | * @param array $params | |
254 | * Parameters for the field, context specific. | |
255 | * | |
256 | * @return string | |
257 | */ | |
258 | public function getText($context, $params) { | |
259 | switch ($context) { | |
260 | case 'contributionPageContinueText': | |
261 | if ($params['amount'] <= 0) { | |
262 | return ts('To complete this transaction, click the <strong>Continue</strong> button below.'); | |
263 | } | |
264 | return ts('To complete your contribution, click the <strong>Continue</strong> button below.'); | |
265 | ||
266 | } | |
267 | } | |
268 | ||
1d1fee72 | 269 | } |