+ /**
+ * 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() {
+ if ($this->_processorName == ts('PayPal Express')) {
+ return TRUE;
+ }
+ 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);
+ if ($this->_processorName == 'PayPal Express') {
+ CRM_Core_Region::instance('billing-block-post')->add(array(
+ 'template' => 'CRM/Financial/Form/PaypalExpress.tpl',
+ 'name' => 'paypal_express',
+ ));
+ }
+ if ($this->_processorName == 'PayPal Pro') {
+ CRM_Core_Region::instance('billing-block-pre')->add(array(
+ 'template' => 'CRM/Financial/Form/PaypalPro.tpl',
+ ));
+ }
+ }
+ 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 CRM_Core_Form $form
+ */
+ protected function addPaypalExpressCode(&$form) {
+ if (empty($form->isBackOffice)) {
+ $form->_expressButtonName = $form->getButtonName('upload', 'express');
+ $form->assign('expressButtonName', $form->_expressButtonName);
+ $form->add(
+ 'image',
+ $form->_expressButtonName,
+ $this->_paymentProcessor['url_button'],
+ array('class' => 'crm-form-submit')
+ );
+ }
+ }
+