Refactor entityParams in Order.Create API so it is easier to understand/modify
authorMatthew Wire <mjw@mjwconsult.co.uk>
Fri, 21 Aug 2020 10:43:06 +0000 (11:43 +0100)
committerMatthew Wire <mjw@mjwconsult.co.uk>
Mon, 26 Oct 2020 21:00:01 +0000 (21:00 +0000)
api/v3/Order.php

index 5e9c07b81bac23ab7d71272d703db6a4b96a1aa6..0fc784e2f737afc4b14102cbec9b971c8798c5a3 100644 (file)
@@ -88,10 +88,25 @@ function civicrm_api3_order_create($params) {
         $item = reset($lineItems['line_item']);
         $entity = str_replace('civicrm_', '', $item['entity_table']);
       }
+
       if ($entityParams) {
-        if (in_array($entity, ['participant', 'membership'])) {
+        $supportedEntity = TRUE;
+        switch ($entity) {
+          case 'participant':
+            $entityParams['status_id'] = 'Pending from incomplete transaction';
+            break;
+
+          case 'membership':
+            $entityParams['status_id'] = 'Pending';
+            break;
+
+          default:
+            // Don't create any related entities. We might want to support eg. Pledge one day?
+            $supportedEntity = FALSE;
+            break;
+        }
+        if ($supportedEntity) {
           $entityParams['skipLineItem'] = TRUE;
-          $entityParams['status_id'] = ($entity === 'participant' ? 'Pending from incomplete transaction' : 'Pending');
           $entityResult = civicrm_api3($entity, 'create', $entityParams);
           $params['contribution_mode'] = $entity;
           $entityIds[] = $params[$entity . '_id'] = $entityResult['id'];
@@ -99,10 +114,8 @@ function civicrm_api3_order_create($params) {
             $items['entity_id'] = $entityResult['id'];
           }
         }
-        else {
-          // pledge payment
-        }
       }
+
       if (empty($priceSetID)) {
         $item = reset($lineItems['line_item']);
         $priceSetID = (int) civicrm_api3('PriceField', 'getvalue', [