-
-
Notifications
You must be signed in to change notification settings - Fork 817
/
Payment.php
1959 lines (1814 loc) · 62 KB
/
Payment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
use Civi\Api4\Participant;
use Civi\Payment\System;
use Civi\Payment\Exception\PaymentProcessorException;
use Civi\Payment\PropertyBag;
/**
* Class CRM_Core_Payment.
*
* This class is the main class for the payment processor subsystem.
*
* It is the parent class for payment processors. It also holds some IPN related functions
* that need to be moved. In particular handlePaymentMethod should be moved to a factory class.
*/
abstract class CRM_Core_Payment {
/**
* Component - ie. event or contribute.
*
* This is used for setting return urls.
*
* @var string
*/
protected $_component;
/**
* How are we getting billing information.
*
* We are trying to completely deprecate these parameters.
*
* FORM - we collect it on the same page
* BUTTON - the processor collects it and sends it back to us via some protocol
*/
const
BILLING_MODE_FORM = 1,
BILLING_MODE_BUTTON = 2,
BILLING_MODE_NOTIFY = 4;
/**
* Which payment type(s) are we using?
*
* credit card
* direct debit
* or both
* @todo create option group - nb omnipay uses a 3rd type - transparent redirect cc
*/
const
PAYMENT_TYPE_CREDIT_CARD = 1,
PAYMENT_TYPE_DIRECT_DEBIT = 2;
/**
* Subscription / Recurring payment Status
* START, END
*/
const
RECURRING_PAYMENT_START = 'START',
RECURRING_PAYMENT_END = 'END';
/**
* @var array
*/
protected $_paymentProcessor;
/**
* Base url of the calling form (offsite processors).
*
* @var string
*/
protected $baseReturnUrl;
/**
* Return url upon success (offsite processors).
*
* @var string
*/
protected $successUrl;
/**
* Return url upon failure (offsite processors).
*
* @var string
*/
protected $cancelUrl;
/**
* Processor type label.
*
* (Deprecated unused parameter).
*
* @var string
* @deprecated
*
*/
public $_processorName;
/**
* The profile configured to show on the billing form.
*
* Currently only the pseudo-profile 'billing' is supported but hopefully in time we will take an id and
* load that from the DB and the processor will be able to return a set of fields that combines it's minimum
* requirements with the configured requirements.
*
* Currently only the pseudo-processor 'manual' or 'pay-later' uses this setting to return a 'curated' set
* of fields.
*
* Note this change would probably include converting 'billing' to a reserved profile.
*
* @var int|string
*/
protected $billingProfile;
/**
* Payment instrument ID.
*
* This is normally retrieved from the payment_processor table.
*
* @var int
*/
protected $paymentInstrumentID;
/**
* Is this a back office transaction.
*
* @var bool
*/
protected $backOffice = FALSE;
/**
* This is only needed during the transitional phase. In future you should
* pass your own PropertyBag into the method you're calling.
*
* New code should NOT use $this->propertyBag.
*
* @var Civi\Payment\PropertyBag
*/
protected $propertyBag;
/**
* Return the payment instrument ID to use.
*
* Note:
* We normally SHOULD be returning the payment instrument of the payment processor.
* However there is an outstanding case where this needs overriding, which is
* when using CRM_Core_Payment_Manual which uses the pseudo-processor (id = 0).
*
* i.e. If you're writing a Payment Processor you should NOT be using
* setPaymentInstrumentID() at all.
*
* @todo
* Ideally this exception-to-the-rule should be handled outside of this class
* i.e. this class's getPaymentInstrumentID method should return it from the
* payment processor and CRM_Core_Payment_Manual could override it to provide 0.
*
* @return int
*/
public function getPaymentInstrumentID() {
return isset($this->paymentInstrumentID)
? $this->paymentInstrumentID
: (int) ($this->_paymentProcessor['payment_instrument_id'] ?? 0);
}
/**
* Getter for the id Payment Processor ID.
*
* @return int
*/
public function getID() {
return (int) $this->_paymentProcessor['id'];
}
/**
* @deprecated Set payment Instrument id - see note on getPaymentInstrumentID.
*
* By default we actually ignore the form value. The manual processor takes
* it more seriously.
*
* @param int $paymentInstrumentID
*/
public function setPaymentInstrumentID($paymentInstrumentID) {
$this->paymentInstrumentID = (int) $paymentInstrumentID;
// See note on getPaymentInstrumentID().
return $this->getPaymentInstrumentID();
}
/**
* @return bool
*/
public function isBackOffice() {
return $this->backOffice;
}
/**
* Set back office property.
*
* @param bool $isBackOffice
*/
public function setBackOffice($isBackOffice) {
$this->backOffice = $isBackOffice;
}
/**
* Set base return path (offsite processors).
*
* This is only useful with an internal civicrm form.
*
* @param string $url
* Internal civicrm path.
*/
public function setBaseReturnUrl($url) {
$this->baseReturnUrl = $url;
}
/**
* Set success return URL (offsite processors).
*
* This overrides $baseReturnUrl
*
* @param string $url
* Full url of site to return browser to upon success.
*/
public function setSuccessUrl($url) {
$this->successUrl = $url;
}
/**
* Set cancel return URL (offsite processors).
*
* This overrides $baseReturnUrl
*
* @param string $url
* Full url of site to return browser to upon failure.
*/
public function setCancelUrl($url) {
$this->cancelUrl = $url;
}
/**
* Set the configured payment profile.
*
* @param int|string $value
*/
public function setBillingProfile($value) {
$this->billingProfile = $value;
}
/**
* Opportunity for the payment processor to override the entire form build.
*
* @param CRM_Core_Form $form
*
* @return bool
* Should form building stop at this point?
*/
public function buildForm(&$form) {
return FALSE;
}
/**
* Log payment notification message to forensic system log.
*
* @todo move to factory class \Civi\Payment\System (or similar)
*
* @param array $params
*/
public static function logPaymentNotification($params) {
$message = 'payment_notification ';
if (!empty($params['processor_name'])) {
$message .= 'processor_name=' . $params['processor_name'];
}
if (!empty($params['processor_id'])) {
$message .= 'processor_id=' . $params['processor_id'];
}
$log = new CRM_Utils_SystemLogger();
// $_REQUEST doesn't handle JSON, to support providers that POST JSON we need the raw POST data.
$rawRequestData = file_get_contents("php://input");
if (CRM_Utils_JSON::isValidJSON($rawRequestData)) {
$log->alert($message, json_decode($rawRequestData, TRUE));
}
else {
$log->alert($message, $_REQUEST);
}
}
/**
* Check if capability is supported.
*
* Capabilities have a one to one relationship with capability-related functions on this class.
*
* Payment processor classes should over-ride the capability-specific function rather than this one.
*
* @param string $capability
* E.g BackOffice, LiveMode, FutureRecurStartDate.
*
* @return bool
*/
public function supports($capability) {
$function = 'supports' . ucfirst($capability);
if (method_exists($this, $function)) {
return $this->$function();
}
return FALSE;
}
/**
* Are back office payments supported.
*
* e.g paypal standard won't permit you to enter a credit card associated
* with someone else's login.
* The intention is to support off-site (other than paypal) & direct debit but that is not all working yet so to
* reach a 'stable' point we disable.
*
* @return bool
*/
protected function supportsBackOffice() {
if ($this->_paymentProcessor['billing_mode'] == 4 || $this->_paymentProcessor['payment_type'] != 1) {
return FALSE;
}
else {
return TRUE;
}
}
/**
* Can more than one transaction be processed at once?
*
* In general processors that process payment by server to server communication support this while others do not.
*
* In future we are likely to hit an issue where this depends on whether a token already exists.
*
* @return bool
*/
protected function supportsMultipleConcurrentPayments() {
if ($this->_paymentProcessor['billing_mode'] == 4 || $this->_paymentProcessor['payment_type'] != 1) {
return FALSE;
}
else {
return TRUE;
}
}
/**
* Are live payments supported - e.g dummy doesn't support this.
*
* @return bool
*/
protected function supportsLiveMode() {
return empty($this->_paymentProcessor['is_test']);
}
/**
* Are test payments supported.
*
* @return bool
*/
protected function supportsTestMode() {
return !empty($this->_paymentProcessor['is_test']);
}
/**
* Does this payment processor support refund?
*
* @return bool
*/
public function supportsRefund() {
return FALSE;
}
/**
* Should the first payment date be configurable when setting up back office recurring payments.
*
* We set this to false for historical consistency but in fact most new processors use tokens for recurring and can support this
*
* @return bool
*/
protected function supportsFutureRecurStartDate() {
return FALSE;
}
/**
* Does this processor support cancelling recurring contributions through code.
*
* If the processor returns true it must be possible to take action from within CiviCRM
* that will result in no further payments being processed. In the case of token processors (e.g
* IATS, eWay) updating the contribution_recur table is probably sufficient.
*
* @return bool
*/
protected function supportsCancelRecurring() {
return method_exists(CRM_Utils_System::getClassName($this), 'cancelSubscription');
}
/**
* Does the processor support the user having a choice as to whether to cancel the recurring with the processor?
*
* If this returns TRUE then there will be an option to send a cancellation request in the cancellation form.
*
* This would normally be false for processors where CiviCRM maintains the schedule.
*
* @return bool
*/
protected function supportsCancelRecurringNotifyOptional() {
return $this->supportsCancelRecurring();
}
/**
* Does this processor support pre-approval.
*
* This would generally look like a redirect to enter credentials which can then be used in a later payment call.
*
* Currently Paypal express supports this, with a redirect to paypal after the 'Main' form is submitted in the
* contribution page. This token can then be processed at the confirm phase. Although this flow 'looks' like the
* 'notify' flow a key difference is that in the notify flow they don't have to return but in this flow they do.
*
* @return bool
*/
protected function supportsPreApproval() {
return FALSE;
}
/**
* Does this processor support updating billing info for recurring contributions through code.
*
* If the processor returns true then it must be possible to update billing info from within CiviCRM
* that will be updated at the payment processor.
*
* @return bool
*/
protected function supportsUpdateSubscriptionBillingInfo() {
return method_exists(CRM_Utils_System::getClassName($this), 'updateSubscriptionBillingInfo');
}
/**
* Can recurring contributions be set against pledges.
*
* In practice all processors that use the baseIPN function to finish transactions or
* call the completetransaction api support this by looking up previous contributions in the
* series and, if there is a prior contribution against a pledge, and the pledge is not complete,
* adding the new payment to the pledge.
*
* However, only enabling for processors it has been tested against.
*
* @return bool
*/
protected function supportsRecurContributionsForPledges() {
return FALSE;
}
/**
* Does the processor work without an email address?
*
* The historic assumption is that all processors require an email address. This capability
* allows a processor to state it does not need to be provided with an email address.
* NB: when this was added (Feb 2020), the Manual processor class overrides this but
* the only use of the capability is in the webform_civicrm module. It is not currently
* used in core but may be in future.
*
* @return bool
*/
protected function supportsNoEmailProvided() {
return FALSE;
}
/**
* Function to action pre-approval if supported
*
* @param array $params
* Parameters from the form
*
* This function returns an array which should contain
* - pre_approval_parameters (this will be stored on the calling form & available later)
* - redirect_url (if set the browser will be redirected to this.
*/
public function doPreApproval(&$params) {
}
/**
* Get any details that may be available to the payment processor due to an approval process having happened.
*
* In some cases the browser is redirected to enter details on a processor site. Some details may be available as a
* result.
*
* @param array $storedDetails
*
* @return array
*/
public function getPreApprovalDetails($storedDetails) {
return [];
}
/**
* Default payment instrument validation.
*
* Payment processors should override this.
*
* @param array $values
* @param array $errors
*/
public function validatePaymentInstrument($values, &$errors) {
CRM_Core_Form::validateMandatoryFields($this->getMandatoryFields(), $values, $errors);
if ($this->_paymentProcessor['payment_type'] == 1) {
CRM_Core_Payment_Form::validateCreditCard($values, $errors, $this->_paymentProcessor['id']);
}
}
/**
* Getter for the payment processor.
*
* The payment processor array is based on the civicrm_payment_processor table entry.
*
* @return array
* Payment processor array.
*/
public function getPaymentProcessor() {
return $this->_paymentProcessor;
}
/**
* Setter for the payment processor.
*
* @param array $processor
*/
public function setPaymentProcessor($processor) {
$this->_paymentProcessor = $processor;
}
/**
* Setter for the payment form that wants to use the processor.
*
* @deprecated
*
* @param CRM_Core_Form $paymentForm
*/
public function setForm(&$paymentForm) {
$this->_paymentForm = $paymentForm;
}
/**
* Getter for payment form that is using the processor.
* @deprecated
* @return CRM_Core_Form
* A form object
*/
public function getForm() {
return $this->_paymentForm;
}
/**
* Get help text information (help, description, etc.) about this payment,
* to display to the user.
*
* @param string $context
* Context of the text.
* Only explicitly supported contexts are handled without error.
* Currently supported:
* - contributionPageRecurringHelp (params: is_recur_installments, is_email_receipt)
* - contributionPageContinueText (params: amount, is_payment_to_existing)
* - cancelRecurDetailText:
* params:
* mode, amount, currency, frequency_interval, frequency_unit,
* installments, {membershipType|only if mode=auto_renew},
* selfService (bool) - TRUE if user doesn't have "edit contributions" permission.
* ie. they are accessing via a "self-service" link from an email receipt or similar.
* - cancelRecurNotSupportedText
*
* @param array $params
* Parameters for the field, context specific.
*
* @return string
*/
public function getText($context, $params) {
// I have deliberately added a noisy fail here.
// The function is intended to be extendable, but not by changes
// not documented clearly above.
switch ($context) {
case 'contributionPageRecurringHelp':
if ($params['is_recur_installments']) {
return ts('You can specify the number of installments, or you can leave the number of installments blank if you want to make an open-ended commitment. In either case, you can choose to cancel at any time.');
}
return '';
case 'contributionPageContinueText':
if ($params['amount'] <= 0.0 || (int) $this->_paymentProcessor['billing_mode'] === 4) {
return ts('Click the <strong>Continue</strong> button to proceed with the payment.');
}
if ($params['is_payment_to_existing']) {
return ts('Click the <strong>Make Payment</strong> button to proceed with the payment.');
}
return ts('Click the <strong>Make Contribution</strong> button to proceed with the payment.');
case 'contributionPageConfirmText':
if ($params['amount'] <= 0.0) {
return '';
}
if ((int) $this->_paymentProcessor['billing_mode'] !== 4) {
return ts('Your contribution will not be completed until you click the <strong>%1</strong> button. Please click the button one time only.', [1 => ts('Make Contribution')]);
}
return '';
case 'contributionPageButtonText':
if ($params['amount'] <= 0.0 || (int) $this->_paymentProcessor['billing_mode'] === 4) {
return ts('Continue');
}
if ($params['is_payment_to_existing']) {
return ts('Make Payment');
}
return ts('Make Contribution');
case 'eventContinueText':
// This use of the ts function uses the legacy interpolation of the button name to avoid translations having to be re-done.
if ((int) $this->_paymentProcessor['billing_mode'] === self::BILLING_MODE_NOTIFY) {
return ts('Click <strong>%1</strong> to checkout with %2.', [1 => ts('Register'), 2 => $this->_paymentProcessor['frontend_title']]);
}
return ts('Click <strong>%1</strong> to complete your registration.', [1 => ts('Register')]);
case 'eventConfirmText':
if ((int) $this->_paymentProcessor['billing_mode'] === self::BILLING_MODE_NOTIFY) {
return ts('Your registration payment has been submitted to %1 for processing', [1 => $this->_paymentProcessor['frontend_title']]);
}
return '';
case 'eventConfirmEmailText':
return ts('A registration confirmation email will be sent to %1 once the transaction is processed successfully.', [1 => $params['email']]);
case 'cancelRecurDetailText':
if ($params['mode'] === 'auto_renew') {
return ts('Click the button below if you want to cancel the auto-renewal option for your %1 membership. This will not cancel your membership. However you will need to arrange payment for renewal when your membership expires.',
[1 => $params['membershipType']]
);
}
else {
$text = ts('Recurring Contribution Details: %1 every %2 %3', [
1 => CRM_Utils_Money::format($params['amount'], $params['currency']),
2 => $params['frequency_interval'],
3 => $params['frequency_unit'],
]);
if (!empty($params['installments'])) {
$text .= ' ' . ts('for %1 installments', [1 => $params['installments']]) . '.';
}
$text = "<strong>{$text}</strong><div class='content'>";
$text .= ts('Click the button below to cancel this commitment and stop future transactions. This does not affect contributions which have already been completed.');
$text .= '</div>';
return $text;
}
case 'cancelRecurNotSupportedText':
if (!$this->supportsCancelRecurring()) {
return ts('Automatic cancellation is not supported for this payment processor. You or the contributor will need to manually cancel this recurring contribution using the payment processor website.');
}
return '';
case 'agreementTitle':
if ($this->getPaymentTypeName() !== 'direct_debit' || $this->_paymentProcessor['billing_mode'] != 1) {
return '';
}
// @todo - 'encourage' processors to override...
// CRM_Core_Error::deprecatedWarning('Payment processors should override getText for agreement text');
return ts('Agreement');
case 'agreementText':
if ($this->getPaymentTypeName() !== 'direct_debit' || $this->_paymentProcessor['billing_mode'] != 1) {
return '';
}
// @todo - 'encourage' processors to override...
// CRM_Core_Error::deprecatedWarning('Payment processors should override getText for agreement text');
return ts('Your account data will be used to charge your bank account via direct debit. While submitting this form you agree to the charging of your bank account via direct debit.');
}
CRM_Core_Error::deprecatedFunctionWarning('Calls to getText must use a supported method');
return '';
}
/**
* Get the title of the payment processor to display to the user
*
* @return string
*/
public function getTitle() {
return $this->getPaymentProcessor()['title'] ?? $this->getPaymentProcessor()['name'];
}
/**
* Getter for accessing member vars.
*
* @todo believe this is unused
*
* @param string $name
*
* @return null
*/
public function getVar($name) {
return $this->$name ?? NULL;
}
/**
* Get name for the payment information type.
* @todo - use option group + name field (like Omnipay does)
* @return string
*/
public function getPaymentTypeName() {
return $this->_paymentProcessor['payment_type'] == 1 ? 'credit_card' : 'direct_debit';
}
/**
* Get label for the payment information type.
* @todo - use option group + labels (like Omnipay does)
* @return string
*/
public function getPaymentTypeLabel() {
return $this->_paymentProcessor['payment_type'] == 1 ? ts('Credit Card') : ts('Direct Debit');
}
/**
* Get array of fields that should be displayed on the payment form.
*
* Common results are
* array('credit_card_type', 'credit_card_number', 'cvv2', 'credit_card_exp_date')
* or
* array('account_holder', 'bank_account_number', 'bank_identification_number', 'bank_name')
* or
* array()
*
* @return array
* Array of payment fields appropriate to the payment processor.
*
* @throws CRM_Core_Exception
*/
public function getPaymentFormFields() {
if ($this->_paymentProcessor['billing_mode'] == 4) {
return [];
}
return $this->_paymentProcessor['payment_type'] == 1 ? $this->getCreditCardFormFields() : $this->getDirectDebitFormFields();
}
/**
* Get an array of the fields that can be edited on the recurring contribution.
*
* Some payment processors support editing the amount and other scheduling details of recurring payments, especially
* those which use tokens. Others are fixed. This function allows the processor to return an array of the fields that
* can be updated from the contribution recur edit screen.
*
* The fields are likely to be a subset of these
* - 'amount',
* - 'installments',
* - 'frequency_interval',
* - 'frequency_unit',
* - 'cycle_day',
* - 'next_sched_contribution_date',
* - 'end_date',
* - 'failure_retry_day',
*
* The form does not restrict which fields from the contribution_recur table can be added (although if the html_type
* metadata is not defined in the xml for the field it will cause an error.
*
* Open question - would it make sense to return membership_id in this - which is sometimes editable and is on that
* form (UpdateSubscription).
*
* @return array
*/
public function getEditableRecurringScheduleFields() {
if ($this->supports('changeSubscriptionAmount')) {
return ['amount'];
}
return [];
}
/**
* Get the help text to present on the recurring update page.
*
* This should reflect what can or cannot be edited.
*
* @return string
*/
public function getRecurringScheduleUpdateHelpText() {
if (!in_array('amount', $this->getEditableRecurringScheduleFields())) {
return ts('Updates made using this form will change the recurring contribution information stored in your CiviCRM database, but will NOT be sent to the payment processor. You must enter the same changes using the payment processor web site.');
}
return ts('Use this form to change the amount or number of installments for this recurring contribution. Changes will be automatically sent to the payment processor. You can not change the contribution frequency.');
}
/**
* Get the metadata for all required fields.
*
* @return array;
*/
protected function getMandatoryFields() {
$mandatoryFields = [];
foreach ($this->getAllFields() as $field_name => $field_spec) {
if (!empty($field_spec['is_required'])) {
$mandatoryFields[$field_name] = $field_spec;
}
}
return $mandatoryFields;
}
/**
* Get the metadata of all the fields configured for this processor.
*
* @return array
*
* @throws \CRM_Core_Exception
*/
protected function getAllFields() {
$paymentFields = array_intersect_key($this->getPaymentFormFieldsMetadata(), array_flip($this->getPaymentFormFields()));
$billingFields = array_intersect_key($this->getBillingAddressFieldsMetadata(), array_flip($this->getBillingAddressFields()));
return array_merge($paymentFields, $billingFields);
}
/**
* Get array of fields that should be displayed on the payment form for credit cards.
*
* @return array
*/
protected function getCreditCardFormFields() {
return [
'credit_card_type',
'credit_card_number',
'cvv2',
'credit_card_exp_date',
];
}
/**
* Get array of fields that should be displayed on the payment form for direct debits.
*
* @return array
*/
protected function getDirectDebitFormFields() {
return [
'account_holder',
'bank_account_number',
'bank_identification_number',
'bank_name',
];
}
/**
* Return an array of all the details about the fields potentially required for payment fields.
*
* Only those determined by getPaymentFormFields will actually be assigned to the form
*
* @return array
* field metadata
*/
public function getPaymentFormFieldsMetadata() {
//@todo convert credit card type into an option value
$creditCardType = ['' => ts('- select -')] + CRM_Contribute_PseudoConstant::creditCard();
$isCVVRequired = Civi::settings()->get('cvv_backoffice_required');
if (!$this->isBackOffice()) {
$isCVVRequired = TRUE;
}
return [
'credit_card_number' => [
'htmlType' => 'text',
'name' => 'credit_card_number',
'title' => ts('Card Number'),
'attributes' => [
'size' => 20,
'maxlength' => 20,
'autocomplete' => 'off',
'class' => 'creditcard required',
],
'is_required' => TRUE,
// 'description' => '16 digit card number', // If you enable a description field it will be shown below the field on the form
],
'cvv2' => [
'htmlType' => 'text',
'name' => 'cvv2',
'title' => ts('Security Code'),
'attributes' => [
'size' => 5,
'maxlength' => 10,
'autocomplete' => 'off',
'class' => ($isCVVRequired ? 'required' : ''),
],
'is_required' => $isCVVRequired,
'rules' => [
[
'rule_message' => ts('Please enter a valid value for your card security code. This is usually the last 3-4 digits on the card\'s signature panel.'),
'rule_name' => 'integer',
'rule_parameters' => NULL,
],
],
],
'credit_card_exp_date' => [
'htmlType' => 'date',
'name' => 'credit_card_exp_date',
'title' => ts('Expiration Date'),
'attributes' => CRM_Core_SelectValues::date('creditCard'),
'is_required' => TRUE,
'rules' => [
[
'rule_message' => ts('Card expiration date cannot be a past date.'),
'rule_name' => 'currentDate',
'rule_parameters' => TRUE,
],
],
'extra' => ['class' => 'crm-form-select required'],
],
'credit_card_type' => [
'htmlType' => 'select',
'name' => 'credit_card_type',
'title' => ts('Card Type'),
'attributes' => $creditCardType,
'is_required' => FALSE,
],
'account_holder' => [
'htmlType' => 'text',
'name' => 'account_holder',
'title' => ts('Account Holder'),
'attributes' => [
'size' => 20,
'maxlength' => 34,
'autocomplete' => 'on',
'class' => 'required',
],
'is_required' => TRUE,
],
//e.g. IBAN can have maxlength of 34 digits
'bank_account_number' => [
'htmlType' => 'text',
'name' => 'bank_account_number',
'title' => ts('Bank Account Number'),
'attributes' => [
'size' => 20,
'maxlength' => 34,
'autocomplete' => 'off',
'class' => 'required',
],
'rules' => [
[
'rule_message' => ts('Please enter a valid Bank Identification Number (value must not contain punctuation characters).'),
'rule_name' => 'nopunctuation',
'rule_parameters' => NULL,
],
],
'is_required' => TRUE,
],
//e.g. SWIFT-BIC can have maxlength of 11 digits
'bank_identification_number' => [
'htmlType' => 'text',
'name' => 'bank_identification_number',
'title' => ts('Bank Identification Number'),
'attributes' => [
'size' => 20,
'maxlength' => 11,
'autocomplete' => 'off',
'class' => 'required',
],
'is_required' => TRUE,
'rules' => [
[
'rule_message' => ts('Please enter a valid Bank Identification Number (value must not contain punctuation characters).'),
'rule_name' => 'nopunctuation',
'rule_parameters' => NULL,
],
],
],
'bank_name' => [
'htmlType' => 'text',
'name' => 'bank_name',
'title' => ts('Bank Name'),
'attributes' => [
'size' => 20,
'maxlength' => 64,
'autocomplete' => 'off',
'class' => 'required',
],
'is_required' => TRUE,
],
'check_number' => [
'htmlType' => 'text',
'name' => 'check_number',
'title' => ts('Check Number'),
'is_required' => FALSE,
'attributes' => NULL,
],
'pan_truncation' => [
'htmlType' => 'text',
'name' => 'pan_truncation',
'title' => ts('Last 4 digits of the card'),
'is_required' => FALSE,
'attributes' => [
'size' => 4,
'maxlength' => 4,
'minlength' => 4,
'autocomplete' => 'off',
],
'rules' => [