From dbbd55dc02a23d246b5aaa8e44ecc694f87467ac Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 3 Jun 2015 15:25:32 +1200 Subject: [PATCH] CRM-16555 move paypal code addition to buildForm Not 100% sure about bringing this (existing override) to the fore as opposed to a more granular one but it does already exist?. The biggest problem is the temptation to do lots of altering from there which might not be upgrade proof - as opposed to just addition as per here --- CRM/Core/Payment.php | 12 ++++++++++ CRM/Core/Payment/Form.php | 28 ++++-------------------- CRM/Core/Payment/PayPalImpl.php | 34 +++++++++++++++++++++++++++++ templates/CRM/Core/BillingBlock.tpl | 12 +++++----- 4 files changed, 55 insertions(+), 31 deletions(-) diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 03f43009dd..3a35c663eb 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -102,6 +102,18 @@ abstract class CRM_Core_Payment { return $object; } + /** + * 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. * diff --git a/CRM/Core/Payment/Form.php b/CRM/Core/Payment/Form.php index 7569320a9d..cde6d66028 100644 --- a/CRM/Core/Payment/Form.php +++ b/CRM/Core/Payment/Form.php @@ -263,14 +263,15 @@ class CRM_Core_Payment_Form { // $processor->buildForm appears to be an undocumented (possibly unused) option for payment processors // which was previously available only in some form flows if (!empty($form->_paymentProcessor) && !empty($form->_paymentProcessor['object']) && $form->_paymentProcessor['object']->isSupported('buildForm')) { - $form->_paymentProcessor['object']->buildForm($form); - return NULL; + if ($form->_paymentProcessor['object']->buildForm($form)) { + return NULL; + } } + self::setPaymentFieldsByProcessor($form, $processor, empty($isBillingDataOptional)); self::addCommonFields($form, !$isBillingDataOptional, $form->_paymentFields); self::addRules($form, $form->_paymentFields); - self::addPaypalExpressCode($form); return (!empty($form->_paymentFields)); } @@ -294,27 +295,6 @@ class CRM_Core_Payment_Form { } } - /** - * Billing mode button is basically synonymous with paypal express - this is probably a good example of 'odds & sods' code we - * need to find a way for the payment processor to assign. A tricky aspect is that the payment processor may need to set the order - * - * @param $form - */ - protected static function addPaypalExpressCode(&$form) { - if (empty($form->isBackOffice)) { - if (CRM_Utils_Array::value('billing_mode', $form->_paymentProcessor) == 3 - ) { - $form->_expressButtonName = $form->getButtonName('upload', 'express'); - $form->assign('expressButtonName', $form->_expressButtonName); - $form->add('image', - $form->_expressButtonName, - $form->_paymentProcessor['url_button'], - array('class' => 'crm-form-submit') - ); - } - } - } - /** * Validate the payment instrument values before passing it to the payment processor * We want this to be overrideable by the payment processor, and default to using diff --git a/CRM/Core/Payment/PayPalImpl.php b/CRM/Core/Payment/PayPalImpl.php index 3c0443e4b4..5316ff5523 100644 --- a/CRM/Core/Payment/PayPalImpl.php +++ b/CRM/Core/Payment/PayPalImpl.php @@ -85,6 +85,40 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { return FALSE; } + /** + * 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) { + if ($this->_processorName == 'PayPal Express' || $this->_processorName == 'PayPal Pro') { + $this->addPaypalExpressCode($form); + } + return FALSE; + } + + /** + * Billing mode button is basically synonymous with paypal express - this is probably a good example of 'odds & sods' code we + * need to find a way for the payment processor to assign. A tricky aspect is that the payment processor may need to set the order + * + * @param $form + */ + protected static function addPaypalExpressCode(&$form) { + if (empty($form->isBackOffice)) { + $form->_expressButtonName = $form->getButtonName('upload', 'express'); + $form->assign('expressButtonName', $form->_expressButtonName); + $form->add( + 'image', + $form->_expressButtonName, + $form->_paymentProcessor['url_button'], + array('class' => 'crm-form-submit') + ); + } + } + /** * Express checkout code. Check PayPal documentation for more information * diff --git a/templates/CRM/Core/BillingBlock.tpl b/templates/CRM/Core/BillingBlock.tpl index 74963fcfa3..ef1c67237f 100644 --- a/templates/CRM/Core/BillingBlock.tpl +++ b/templates/CRM/Core/BillingBlock.tpl @@ -226,11 +226,9 @@ {/if} {/crmRegion} +{crmRegion name="billing-block-post"} + {* Payment processors sometimes need to append something to the end of the billing block. We create a region for + clarity - the plan is to move to assigning this through the payment processor to this region *} + {include file= "CRM/Financial/Form/PaypalExpress.tpl"} +{/crmRegion} -{if $is_monetary} - {crmRegion name="billing-block-post"} - {* Payment processors sometimes need to append something to the end of the billing block. We create a region for - clarity - the plan is to move to assigning this through the payment processor to this region *} - {include file= "CRM/Financial/Form/PaypalExpress.tpl"} - {/crmRegion} -{/if} -- 2.25.1