From 6d7d70894d324e6f3c1759dc1f40ad0a144ed7b1 Mon Sep 17 00:00:00 2001 From: Aidan Saunders Date: Mon, 10 Feb 2020 16:54:54 +0000 Subject: [PATCH] Add function to specify whether payment processor requires email address Manual payment processor implements this capability Test included --- CRM/Core/Payment.php | 15 +++++++++++++++ CRM/Core/Payment/Manual.php | 7 +++++++ .../CRM/Financial/BAO/PaymentProcessorTest.php | 15 +++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 18d89d9589..1ac470d157 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -442,6 +442,21 @@ abstract class CRM_Core_Payment { 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 * diff --git a/CRM/Core/Payment/Manual.php b/CRM/Core/Payment/Manual.php index fe267437f9..3027564199 100644 --- a/CRM/Core/Payment/Manual.php +++ b/CRM/Core/Payment/Manual.php @@ -205,6 +205,13 @@ class CRM_Core_Payment_Manual extends CRM_Core_Payment { return TRUE; } + /** + * Does the processor work without an email address? + */ + protected function supportsNoEmailProvided() { + return TRUE; + } + /** * Submit a manual payment. * diff --git a/tests/phpunit/CRM/Financial/BAO/PaymentProcessorTest.php b/tests/phpunit/CRM/Financial/BAO/PaymentProcessorTest.php index 675349f222..6c84e1e1e0 100644 --- a/tests/phpunit/CRM/Financial/BAO/PaymentProcessorTest.php +++ b/tests/phpunit/CRM/Financial/BAO/PaymentProcessorTest.php @@ -73,4 +73,19 @@ class CRM_Financial_BAO_PaymentProcessorTest extends CiviUnitTestCase { $this->assertEquals([$liveProcessorID], array_keys($processors), 'Only the Live processor should be returned'); } + /** + * Test the Manual processor supports 'NoEmailProvided' + */ + public function testManualProcessorSupportsNoEmailProvided() { + $processors = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors(['NoEmailProvided']); + $found = FALSE; + foreach ($processors as $processor) { + if ($processor['class_name'] == 'Payment_Manual') { + $found = TRUE; + continue; + } + } + $this->assertTrue($found, 'The Manual payment processor should support "NoEmailProvided"'); + } + } -- 2.25.1