$this->_processorName = ts('PayPal Express');
}
- if (!$this->_paymentProcessor['user_name']) {
- CRM_Core_Error::fatal(ts('Could not find user name for payment processor'));
- }
}
/**
return FALSE;
}
+ /**
+ * 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 $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')
+ );
+ }
+ }
+
/**
* Express checkout code. Check PayPal documentation for more information
*
$this->initialize($args, 'SetExpressCheckout');
- $args['paymentAction'] = $params['payment_action'];
+ $args['paymentAction'] = 'Sale';
$args['amt'] = $params['amount'];
$args['currencyCode'] = $params['currencyID'];
$args['desc'] = CRM_Utils_Array::value('description', $params);
$args['invnum'] = $params['invoiceID'];
- $args['returnURL'] = $params['returnURL'];
- $args['cancelURL'] = $params['cancelURL'];
+ $args['returnURL'] = $this->getReturnSuccessUrl($params['qfKey']);
+ $args['cancelURL'] = $this->getCancelUrl($params['qfKey'], NULL);
$args['version'] = '56.0';
//LCD if recurring, collect additional data and set some values
$args = array();
$this->initialize($args, 'DoExpressCheckoutPayment');
-
$args['token'] = $params['token'];
- $args['paymentAction'] = $params['payment_action'];
+ $args['paymentAction'] = 'Sale';
$args['amt'] = $params['amount'];
$args['currencyCode'] = $params['currencyID'];
$args['payerID'] = $params['payer_id'];
$args['invnum'] = $params['invoiceID'];
- $args['returnURL'] = CRM_Utils_Array::value('returnURL', $params);
- $args['cancelURL'] = CRM_Utils_Array::value('cancelURL', $params);
+ $args['returnURL'] = $this->getReturnSuccessUrl($params['qfKey']);
+ $args['cancelURL'] = $this->getCancelUrl($params['qfKey'], NULL);
$args['desc'] = $params['description'];
// add CiviCRM BN code
$start_date = date('Y-m-d\T00:00:00\Z', $start_time);
$args['token'] = $params['token'];
- $args['paymentAction'] = $params['payment_action'];
+ $args['paymentAction'] = 'Sale';
$args['amt'] = $params['amount'];
$args['currencyCode'] = $params['currencyID'];
$args['payerID'] = $params['payer_id'];
$this->initialize($args, 'DoDirectPayment');
- $args['paymentAction'] = $params['payment_action'];
+ $args['paymentAction'] = 'Sale';
$args['amt'] = $params['amount'];
$args['currencyCode'] = $params['currencyID'];
$args['invnum'] = $params['invoiceID'];
public function checkConfig() {
$error = array();
$paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(FALSE, NULL, 'name');
- if (
- $this->_paymentProcessor['payment_processor_type_id'] == CRM_Utils_Array::key('PayPal_Standard', $paymentProcessorType) ||
- $this->_paymentProcessor['payment_processor_type_id'] == CRM_Utils_Array::key('PayPal', $paymentProcessorType)
- ) {
- if (empty($this->_paymentProcessor['user_name'])) {
- $error[] = ts('User Name is not set in the Administer » System Settings » Payment Processors.');
- }
- }
if ($this->_paymentProcessor['payment_processor_type_id'] != CRM_Utils_Array::key('PayPal_Standard', $paymentProcessorType)) {
if (empty($this->_paymentProcessor['signature'])) {
$error[] = ts('Password is not set in the Administer » System Settings » Payment Processors.');
}
}
+ if (!$this->_paymentProcessor['user_name']) {
+ $error[] = ts('User Name is not set in the Administer » System Settings » Payment Processors.');
+ }
if (!empty($error)) {
return implode('<p>', $error);
return parent::isSupported($method);
}
+ /**
+ * Paypal express replaces the submit button with it's own.
+ *
+ * @return bool
+ * Should the form button by suppressed?
+ */
+ public function isSuppressSubmitButtons() {
+ if ($this->_paymentProcessor['payment_processor_type'] == 'PayPal_Express') {
+ return TRUE;
+ }
+ return FALSE;
+ }
+
/**
* @param string $message
* @param array $params
return FALSE;
}
+ /**
+ * Process incoming notification.
+ *
+ * This is only supported for paypal pro at the moment & no specific plans to add this path to core
+ * for paypal standard as the goal must be to separate the 2.
+ *
+ * We don't need to handle paypal standard using this path as there has never been any historic support
+ * for paypal standard to call civicrm/payment/ipn as a path.
+ */
+ static public function handlePaymentNotification() {
+ $paypalIPN = new CRM_Core_Payment_PayPalProIPN($_REQUEST);
+ $paypalIPN->main();
+ }
+
/**
* @param string $message
* @param array $params
return FALSE;
}
+ /**
+ * Function to action pre-approval if supported
+ *
+ * @param array $params
+ * Parameters from the form
+ *
+ * @return array
+ * - 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) {
+ $token = $this->setExpressCheckOut($params);
+ return array(
+ 'pre_approval_parameters' => array('token' => $token),
+ 'redirect_url' => $this->_paymentProcessor['url_site'] . "/cgi-bin/webscr?cmd=_express-checkout&token=$token",
+ );
+ }
+
/**
* @param array $params
* @param string $component