CRM-16808 standardisation of paypal express
[civicrm-core.git] / CRM / Contribute / BAO / Contribution / Utils.php
index 5f8a9e2ef125597d96ffdf333dd9a7bd0ff2d917..a92cda79435c14592497d46caf1da9e4dd2f695a 100644 (file)
@@ -184,29 +184,17 @@ class CRM_Contribute_BAO_Contribution_Utils {
         }
       }
     }
-    elseif ($form->_contributeMode == 'express') {
-      if ($form->_values['is_monetary'] && $form->_amount > 0.0) {
-        // determine if express + recurring and direct accordingly
-        if (!empty($paymentParams['is_recur']) && $paymentParams['is_recur'] == 1) {
-          if (is_object($payment)) {
-            $result = $payment->createRecurringPayments($paymentParams);
-          }
-          else {
-            CRM_Core_Error::fatal($paymentObjError);
-          }
+
+    elseif ($isPaymentTransaction && $form->_contributeMode) {
+      if ($form->_contributeMode == 'express' && !empty($paymentParams['is_recur']) && $paymentParams['is_recur'] == 1) {
+        if (is_object($payment)) {
+          $result = $payment->createRecurringPayments($paymentParams);
         }
         else {
-          if (is_object($payment)) {
-            $result = $payment->doExpressCheckout($paymentParams);
-          }
-          else {
-            CRM_Core_Error::fatal($paymentObjError);
-          }
+          CRM_Core_Error::fatal($paymentObjError);
         }
       }
-    }
-    elseif ($isPaymentTransaction) {
-      if ($form->_contributeMode == 'direct') {
+      else {
         $paymentParams['contactID'] = $contactID;
 
         // Fix for CRM-14354. If the membership is recurring, don't create a
@@ -284,14 +272,19 @@ class CRM_Contribute_BAO_Contribution_Utils {
       }
 
       $form->postProcessPremium($premiumParams, $contribution);
-      if (is_array($result) && !empty($result['trxn_id'])) {
-        $contribution->trxn_id = $result['trxn_id'];
+      if (is_array($result)) {
+        if (!empty($result['trxn_id'])) {
+          $contribution->trxn_id = $result['trxn_id'];
+        }
+        if (!empty($result['payment_status_id'])) {
+          $contribution->payment_status_id = $result['payment_status_id'];
+        }
       }
       $result['contribution'] = $contribution;
     }
     //Do not send an email if Recurring contribution is done via Direct Mode
     //We will send email once the IPN is received.
-    if ($form->_contributeMode == 'direct') {
+    if (!$isPayLater) {
       return $result;
     }