Merge remote-tracking branch 'upstream/4.6' into 4.6-master-2015-10-14-11-04-09
[civicrm-core.git] / CRM / Core / Payment / PayPalImpl.php
index a811b096758ec8723ad2d4ed4bf298c76d2bfe7c..0aa2061ea6c2630839c32d33b2a9b13e5695cc0d 100644 (file)
@@ -25,6 +25,8 @@
  +--------------------------------------------------------------------+
  */
 
+use Civi\Payment\Exception\PaymentProcessorException;
+
 /**
  *
  * @package CRM
@@ -88,7 +90,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment {
    * @return bool
    */
   protected function supportsPreApproval() {
-    if ($this->_processorName == ts('PayPal Express')) {
+    if ($this->_processorName == ts('PayPal Express') || $this->_processorName == ts('PayPal Pro')) {
       return TRUE;
     }
     return FALSE;
@@ -226,7 +228,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment {
    * @return array
    */
   public function getPreApprovalDetails($storedDetails) {
-    return $this->getExpressCheckoutDetails($storedDetails['token']);
+    return empty($storedDetails['token']) ? array() : $this->getExpressCheckoutDetails($storedDetails['token']);
   }
 
   /**
@@ -427,7 +429,9 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment {
    * @throws \Civi\Payment\Exception\PaymentProcessorException
    */
   public function doPayment(&$params, $component = 'contribute') {
-    if ($this->_paymentProcessor['payment_processor_type'] != 'PayPal_Express') {
+    if ($this->_paymentProcessor['payment_processor_type'] != 'PayPal_Express'
+    && (!empty($params['credit_card_number']) && empty($params['token']))
+    ) {
       return parent::doPayment($params, $component);
     }
     $this->_component = $component;
@@ -549,6 +553,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment {
     $result = $this->invokeAPI($args);
     return array(
       'fee_amount' => $result['feeamt'],
+      'net_amount' => $params['gross_amount'] - $result['feeamt'],
     );
   }
 
@@ -571,7 +576,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment {
         $error[] = ts('Password is not set in the Administer » System Settings » Payment Processors.');
       }
     }
-    if (!$this->_paymentProcessor['user_name']) {
+    if (empty($this->_paymentProcessor['user_name'])) {
       $error[] = ts('User Name is not set in the Administer » System Settings » Payment Processors.');
     }
 
@@ -741,6 +746,9 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment {
    *   - redirect_url (if set the browser will be redirected to this.
    */
   public function doPreApproval(&$params) {
+    if (!isset($params['button']) || !stristr($params['button'], 'express')) {
+      return array();
+    }
     $this->_component = $params['component'];
     $token = $this->setExpressCheckOut($params);
     return array(