From ee1657f7c923036cbcb16e1ea368a359ac035683 Mon Sep 17 00:00:00 2001
From: Gundo Sifhufhi <sifhufhisg@gmail.com>
Date: Wed, 25 Jan 2023 10:25:39 +0200
Subject: [PATCH] Company info, extraction.

---
 Model/Carrier/Customshipping.php | 13 ++++---------
 Model/Carrier/uSubs.php          | 23 +++++++++++++++++++++++
 2 files changed, 27 insertions(+), 9 deletions(-)
 create mode 100644 Model/Carrier/uSubs.php

diff --git a/Model/Carrier/Customshipping.php b/Model/Carrier/Customshipping.php
index f0684dd..b22b4cb 100644
--- a/Model/Carrier/Customshipping.php
+++ b/Model/Carrier/Customshipping.php
@@ -108,6 +108,7 @@ class Customshipping extends AbstractCarrierOnline implements \Magento\Shipping\
      */
     protected JsonFactory $jsonFactory;
     private $cartRepository;
+    private uSubs $uSubs;
 
 
     /**
@@ -181,6 +182,7 @@ class Customshipping extends AbstractCarrierOnline implements \Magento\Shipping\
         );
         $this->jsonFactory = $jsonFactory;
         $this->curl = $curlFactory->create();
+        $this->uSubs = new uSubs();
     }
 
 
@@ -783,7 +785,7 @@ class Customshipping extends AbstractCarrierOnline implements \Magento\Shipping\
                 'activity' => $checkpoint['status'],
                 'deliverydate' => $this->formatDate($checkpoint['time']),
                 'deliverytime' => $this->formatTime($checkpoint['time']),
-                'deliverylocation' => 'Unavailable',
+                //'deliverylocation' => 'Unavailable',
             ];
         }
         return $result;
@@ -853,14 +855,7 @@ class Customshipping extends AbstractCarrierOnline implements \Magento\Shipping\
      */
     protected function getDestComp(): mixed
     {
-        $data = json_decode(file_get_contents('php://input'), true);
-
-        if (isset($data['address']['company'])) {
-            $destComp = $data['address']['company'];
-        } else {
-            $destComp = '';
-        }
-        return $destComp;
+        return $this->uSubs->getDestComp();
     }
 
     /**
diff --git a/Model/Carrier/uSubs.php b/Model/Carrier/uSubs.php
new file mode 100644
index 0000000..e3b75ae
--- /dev/null
+++ b/Model/Carrier/uSubs.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace uafrica\Customshipping\Model\Carrier;
+
+/** Get Company information if available from the Estimate Shipping Methods Request Body */
+class uSubs
+{
+
+    /**
+     * @return mixed|string
+     */
+    public function getDestComp(): mixed
+    {
+        $data = json_decode(file_get_contents('php://input'), true);
+
+        if (isset($data['address']['company'])) {
+            $destComp = $data['address']['company'];
+        } else {
+            $destComp = '';
+        }
+        return $destComp;
+    }
+}
-- 
GitLab