Merge pull request #23280 from eileenmcnaughton/import_job
[civicrm-core.git] / CRM / Core / Payment / Manual.php
CommitLineData
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 */
17class 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
d737af02
SL
26 /**
27 * Constructor.
28 */
29 public function __construct() {
30 $this->_paymentProcessor = [
31 'payment_type' => 0,
32 'billing_mode' => 0,
33 'id' => 0,
34 'url_recur' => '',
35 'is_recur' => 0,
36 ];
37 }
38
1d1fee72 39 /**
40 * Get billing fields required for this processor.
41 *
42 * We apply the existing default of returning fields only for payment processor type 1. Processors can override to
43 * alter.
44 *
45 * @param int $billingLocationID
46 *
47 * @return array
48 */
49 public function getBillingAddressFields($billingLocationID = NULL) {
50 if (!$billingLocationID) {
51 // Note that although the billing id is passed around the forms the idea that it would be anything other than
52 // the result of the function below doesn't seem to have eventuated.
53 // So taking this as a param is possibly something to be removed in favour of the standard default.
54 $billingLocationID = CRM_Core_BAO_LocationType::getBilling();
55 }
56
57 // Only handle pseudo-profile billing for now.
58 if ($this->billingProfile == 'billing') {
59 // @todo - use profile api to retrieve this - either as pseudo-profile or (better) set up billing
60 // as a reserved profile in the DB and (even better) allow the profile to be selected
61 // on the form instead of just 'billing for pay=later bool'
be2fb01f 62 return [
1d1fee72 63 'first_name' => 'billing_first_name',
64 'middle_name' => 'billing_middle_name',
65 'last_name' => 'billing_last_name',
66 'street_address' => "billing_street_address-{$billingLocationID}",
67 'city' => "billing_city-{$billingLocationID}",
68 'country' => "billing_country_id-{$billingLocationID}",
69 'state_province' => "billing_state_province_id-{$billingLocationID}",
70 'postal_code' => "billing_postal_code-{$billingLocationID}",
be2fb01f 71 ];
1d1fee72 72 }
73 else {
be2fb01f 74 return [];
1d1fee72 75 }
76 }
77
78 /**
79 * Get array of fields that should be displayed on the payment form.
80 *
81 * @return array
82 */
83 public function getPaymentFormFields() {
794d4fc0 84 if (!$this->isBackOffice()) {
be2fb01f 85 return [];
794d4fc0 86 }
87
88 $paymentInstrument = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', $this->getPaymentInstrumentID());
89 if ($paymentInstrument === 'Credit Card') {
be2fb01f 90 return ['credit_card_type', 'pan_truncation'];
794d4fc0 91 }
92 elseif ($paymentInstrument === 'Check') {
be2fb01f 93 return ['check_number'];
794d4fc0 94 }
be2fb01f 95 return [];
1d1fee72 96 }
794d4fc0 97
1d1fee72 98 /**
99 * Process payment.
100 *
101 * The function ensures an exception is thrown & moves some of this logic out of the form layer and makes the forms
102 * more agnostic.
103 *
104 * @param array $params
105 *
106 * @param string $component
107 *
108 * @return array
109 * Result array
110 *
111 * @throws \Civi\Payment\Exception\PaymentProcessorException
112 */
113 public function doPayment(&$params, $component = 'contribute') {
8e819886
MW
114 $result['payment_status_id'] = $this->getResult();
115 if ($result['payment_status_id'] == CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending')) {
116 $result = $this->setStatusPaymentPending($result);
117 }
118 elseif ($result['payment_status_id'] == CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed')) {
119 $result = $this->setStatusPaymentCompleted($result);
120 }
121 else {
122 throw new \Civi\Payment\Exception\PaymentProcessorException('Result from doPayment MUST be one of Completed|Pending');
123 }
124
125 return $result;
1d1fee72 126 }
127
128 /**
129 * Get the result of the payment.
130 *
131 * Usually this will be pending but the calling layer has a chance to set the result.
132 *
133 * This would apply in particular when the form accepts status id.
134 *
135 * Note that currently this payment class is only being used to manage the 'billing block' aspect
136 * of pay later. However, a longer term idea is that by treating 'pay-later' as 'just another processor'
137 * will allow code simplification.
138 *
139 * @return int
140 */
141 protected function getResult() {
142 if (!$this->result) {
ac1493e4 143 $this->setResult(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'));
1d1fee72 144 }
145 return $this->result;
146 }
147
148 /**
149 * Set the result to be returned.
150 *
151 * This would be set from outside the function where we want to pass on the status from the form.
152 *
153 * @param int $result
154 */
155 public function setResult($result) {
156 $this->result = $result;
157 }
158
18135422 159 /**
160 * Set payment instrument id.
161 *
162 * @param int $paymentInstrumentID
163 */
164 public function setPaymentInstrumentID($paymentInstrumentID) {
165 $this->paymentInstrumentID = $paymentInstrumentID;
166 }
167
1d1fee72 168 /**
169 * Get the name of the payment type.
170 *
171 * @return string
172 */
173 public function getPaymentTypeName() {
174 return 'pay-later';
175 }
176
177 /**
178 * Get the name of the payment type.
179 *
180 * @return string
181 */
182 public function getPaymentTypeLabel() {
cf7b5c1f 183 return CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', $this->getPaymentInstrumentID());
1d1fee72 184 }
f48e6cf7 185
c9058b9b
MW
186 /**
187 * Are live payments supported - e.g dummy doesn't support this.
188 *
189 * @return bool
190 */
191 protected function supportsLiveMode() {
192 return TRUE;
193 }
194
195 /**
196 * Are test payments supported.
197 *
198 * @return bool
199 */
200 protected function supportsTestMode() {
201 return TRUE;
202 }
203
ecb7ec32 204 /**
205 * Declare that more than one payment can be processed at once.
206 *
207 * @return bool
208 */
209 protected function supportsMultipleConcurrentPayments() {
210 return TRUE;
211 }
212
95974e8e
DG
213 /**
214 * Checks if backoffice recurring edit is allowed
215 *
216 * @return bool
217 */
218 public function supportsEditRecurringContribution() {
219 return TRUE;
220 }
221
5077b04c 222 /**
223 * Does the processor support the user having a choice as to whether to cancel the recurring with the processor?
224 *
225 * If this returns TRUE then there will be an option to send a cancellation request in the cancellation form.
226 *
227 * This would normally be false for processors where CiviCRM maintains the schedule.
228 *
229 * @return bool
230 */
231 protected function supportsCancelRecurringNotifyOptional() {
232 return FALSE;
233 }
234
18135422 235 /**
236 * Are back office payments supported.
237 *
238 * @return bool
239 */
240 protected function supportsBackOffice() {
241 return TRUE;
242 }
243
6d7d7089
AS
244 /**
245 * Does the processor work without an email address?
246 */
247 protected function supportsNoEmailProvided() {
248 return TRUE;
249 }
250
cd3bc162 251 /**
252 * Should a receipt be sent out for a pending payment.
253 *
254 * e.g for traditional pay later & ones with a delayed settlement a pending receipt makes sense.
255 */
256 public function isSendReceiptForPending() {
257 return TRUE;
258 }
259
e364c762 260 /**
261 * Get help text information (help, description, etc.) about this payment,
262 * to display to the user.
263 *
264 * @param string $context
265 * Context of the text.
266 * Only explicitly supported contexts are handled without error.
267 * Currently supported:
268 * - contributionPageRecurringHelp (params: is_recur_installments, is_email_receipt)
269 *
270 * @param array $params
271 * Parameters for the field, context specific.
272 *
273 * @return string
274 */
275 public function getText($context, $params) {
276 switch ($context) {
277 case 'contributionPageContinueText':
278 if ($params['amount'] <= 0) {
279 return ts('To complete this transaction, click the <strong>Continue</strong> button below.');
280 }
281 return ts('To complete your contribution, click the <strong>Continue</strong> button below.');
282
b888a015 283 default:
284 return parent::getText($context, $params);
e364c762 285 }
286 }
287
b888a015 288 /**
289 * Does this processor support cancelling recurring contributions through code.
290 *
291 * @return bool
292 */
293 protected function supportsCancelRecurring() {
294 return TRUE;
295 }
296
1d1fee72 297}