3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Core_Payment_Manual
extends CRM_Core_Payment
{
22 * This function checks to see if we have the right config values.
24 public function checkConfig() {}
27 * Get billing fields required for this processor.
29 * We apply the existing default of returning fields only for payment processor type 1. Processors can override to
32 * @param int $billingLocationID
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();
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'
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}",
66 * Get array of fields that should be displayed on the payment form.
70 public function getPaymentFormFields() {
71 if (!$this->isBackOffice()) {
75 $paymentInstrument = CRM_Core_PseudoConstant
::getName('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', $this->getPaymentInstrumentID());
76 if ($paymentInstrument === 'Credit Card') {
77 return ['credit_card_type', 'pan_truncation'];
79 elseif ($paymentInstrument === 'Check') {
80 return ['check_number'];
88 * The function ensures an exception is thrown & moves some of this logic out of the form layer and makes the forms
91 * @param array $params
93 * @param string $component
98 * @throws \Civi\Payment\Exception\PaymentProcessorException
100 public function doPayment(&$params, $component = 'contribute') {
101 $params['payment_status_id'] = $this->getResult();
106 * Get the result of the payment.
108 * Usually this will be pending but the calling layer has a chance to set the result.
110 * This would apply in particular when the form accepts status id.
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.
118 protected function getResult() {
119 if (!$this->result
) {
120 $this->setResult(CRM_Core_PseudoConstant
::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'));
122 return $this->result
;
126 * Set the result to be returned.
128 * This would be set from outside the function where we want to pass on the status from the form.
132 public function setResult($result) {
133 $this->result
= $result;
137 * Set payment instrument id.
139 * @param int $paymentInstrumentID
141 public function setPaymentInstrumentID($paymentInstrumentID) {
142 $this->paymentInstrumentID
= $paymentInstrumentID;
146 * Get the name of the payment type.
150 public function getPaymentTypeName() {
155 * Get the name of the payment type.
159 public function getPaymentTypeLabel() {
160 return CRM_Core_PseudoConstant
::getLabel('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', $this->getPaymentInstrumentID());
164 * Are live payments supported - e.g dummy doesn't support this.
168 protected function supportsLiveMode() {
173 * Are test payments supported.
177 protected function supportsTestMode() {
182 * Declare that more than one payment can be processed at once.
186 protected function supportsMultipleConcurrentPayments() {
191 * Checks if backoffice recurring edit is allowed
195 public function supportsEditRecurringContribution() {
200 * Are back office payments supported.
204 protected function supportsBackOffice() {
209 * Does the processor work without an email address?
211 protected function supportsNoEmailProvided() {
216 * Submit a manual payment.
218 * @param array $params
219 * Assoc array of input parameters for this transaction.
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);
229 $result['payment_status_id'] = array_search('Completed', $statuses);
235 * Should a receipt be sent out for a pending payment.
237 * e.g for traditional pay later & ones with a delayed settlement a pending receipt makes sense.
239 public function isSendReceiptForPending() {
244 * Get help text information (help, description, etc.) about this payment,
245 * to display to the user.
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)
253 * @param array $params
254 * Parameters for the field, context specific.
258 public function getText($context, $params) {
260 case 'contributionPageContinueText':
261 if ($params['amount'] <= 0) {
262 return ts('To complete this transaction, click the <strong>Continue</strong> button below.');
264 return ts('To complete your contribution, click the <strong>Continue</strong> button below.');