CRM-16993 avoid fatal when line items are created & then altered to completed
authoreileenmcnaugton <eileen@fuzion.co.nz>
Mon, 10 Aug 2015 04:17:01 +0000 (16:17 +1200)
committereileenmcnaugton <eileen@fuzion.co.nz>
Mon, 10 Aug 2015 11:04:41 +0000 (23:04 +1200)
CRM/Member/Form/Membership.php

index 17c4d81bf073bff988fdb2664a24f6736a33b883..2edfa77186d77b47d3bc69640e6020e958f50c9b 100644 (file)
@@ -1423,9 +1423,9 @@ WHERE   id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )';
 
       // if the payment processor returns a contribution_status_id -> use it!
       if (isset($result['contribution_status_id'])) {
-        $params['contribution_status_id'] = $result['contribution_status_id'];
+        $result['payment_status_id'] = $result['contribution_status_id'];
       }
-      elseif (isset($result['payment_status_id'])) {
+      if (isset($result['payment_status_id'])) {
         // CRM-16737 $result['contribution_status_id'] is deprecated in favour
         // of payment_status_id as the payment processor only knows whether the payment is complete
         // not whether payment completes the contribution
@@ -1492,6 +1492,10 @@ WHERE   id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )';
         if (!empty($softParams) && empty($paymentParams['is_recur'])) {
           $membershipParams['soft_credit'] = $softParams;
         }
+        if (!empty($paymentParams['is_recur']) && CRM_Utils_Array::value('payment_status_id', $result) == 1) {
+          // CRM-16993 we have a situation where line items have already been created.
+          unset($membershipParams['lineItems']);
+        }
         $membership = CRM_Member_BAO_Membership::create($membershipParams, $ids);
         $params['contribution'] = CRM_Utils_Array::value('contribution', $membershipParams);
         unset($params['lineItems']);