From a1227ba4d67a1d30bdb14601af48a31a1c6a735e Mon Sep 17 00:00:00 2001
From: Francois Wilhelmy <francois.wilhelmy@getinfinity.com>
Date: Thu, 21 Sep 2023 12:29:58 -0400
Subject: [PATCH] ADDED: sendOrderInvoiceItem MODIFIED: getNotesForInvoiceItem
 to use new method

---
 src/Portal3cxApi.php | 42 ++++++++++++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/src/Portal3cxApi.php b/src/Portal3cxApi.php
index 16eaa7f..33ce21b 100644
--- a/src/Portal3cxApi.php
+++ b/src/Portal3cxApi.php
@@ -266,6 +266,33 @@ class Portal3cxApi
         return is_array($result) ?  $result["LicenseKeys"][0] : [];
     }
 
+    /**
+     * Order Item
+     *
+     * @param array $itemDetails
+     * @param bool  $readOnly
+     *
+     * @return mixed
+     */
+    public function sendOrderInvoiceItem(array $itemDetails, $readOnly = false)
+    {
+        $resellerId = $itemDetails["ResellerId"] ?: null;
+
+        switch ($itemDetails["Type"]) {
+            case "NewLicense":
+                $results = $this->orderNew("TEST", $resellerId, $itemDetails["Edition"], $itemDetails["SimultaneousCalls"], $readOnly, "");
+                break;
+            case "RenewAnnual":
+                $results = $this->renew("TEST", $resellerId, $itemDetails["UpgradeKey"], $readOnly, "");
+                break;
+            case "Upgrade":
+                $results = $this->upgrade("TEST", $resellerId, $itemDetails["UpgradeKey"], $itemDetails["Edition"], $itemDetails["SimultaneousCalls"], $readOnly, "");
+                break;
+        }
+
+        return $results;
+    }
+
     /**
      * Get invoice notes for item
      *
@@ -275,22 +302,9 @@ class Portal3cxApi
      */
     public function getNotesForInvoiceItem(array $itemDetails)
     {
-        // TODO : this could probably be used for the ini par of things, if so split in 2 methods
-        // One to get the "notes" the other to do a real transaction
         $note = "";
-        $resellerId = $itemDetails["ResellerId"] ?: null;
         try {
-            switch ($itemDetails["Type"]) {
-                case "NewLicense":
-                    $noteData = $this->orderNew("TEST", $resellerId, $itemDetails["Edition"], $itemDetails["SimultaneousCalls"], true, "");
-                    break;
-                case "RenewAnnual":
-                    $noteData = $this->renew("TEST", $resellerId, $itemDetails["UpgradeKey"], true, "");
-                    break;
-                case "Upgrade":
-                    $noteData = $this->upgrade("TEST", $resellerId, $itemDetails["UpgradeKey"], $itemDetails["Edition"], $itemDetails["SimultaneousCalls"], true, "");
-                    break;
-            }
+            $noteData = $this->sendOrderInvoiceItem($itemDetails, true);
             $note = $noteData["Items"][0]["ProductDescription"];
         } catch (\Exception $e) {
             // dump($e);
-- 
GitLab