SendEditOrderMail.php (Before) SendEditOrderMail.php (After)
<?php <?php
namespace App\Jobs; namespace App\Jobs;
   
// use Illuminate\Bus\Queueable; // use Illuminate\Bus\Queueable;
// use Illuminate\Queue\InteractsWithQueue; // use Illuminate\Queue\InteractsWithQueue;
// use Illuminate\Contracts\Queue\ShouldQueue; // use Illuminate\Contracts\Queue\ShouldQueue;
use App\Model\IterableApi; use App\Model\IterableApi;
use Log; use Log;
use Osiset\BasicShopifyAPI\BasicShopifyAPI; use Osiset\BasicShopifyAPI\BasicShopifyAPI;
use Osiset\BasicShopifyAPI\Options; use Osiset\BasicShopifyAPI\Options;
use Osiset\BasicShopifyAPI\Session; use Osiset\BasicShopifyAPI\Session;
   
class SendEditOrderMail extends Job class SendEditOrderMail extends Job
{ {
   // use InteractsWithQueue, Queueable;    // use InteractsWithQueue, Queueable;
   
   private $data;    private $data;
   private $hmacHeader;    private $hmacHeader;
   private $api;    private $api;
   
   /**    /**
    * Create a new job instance.     * Create a new job instance.
    *     *
    * @return void     * @return void
    */      */ 
   // public function __construct($requestData, $hmacHeader)    // public function __construct($requestData, $hmacHeader)
   public function __construct($data)    public function __construct($data)
   {    {
       $this->data = $data->data;        $this->data = $data->data;
   }    }
   
   public function handle()    public function handle()
   {    {
       $this->iterableObj = new IterableApi();        $this->iterableObj = new IterableApi();
   
       $options = new Options();        $options = new Options();
       $options->setVersion(env('SHOPIFY_API_VER_DEV'));        $options->setVersion(env('SHOPIFY_API_VER_DEV'));
   
       $this->api = new BasicShopifyAPI($options);        $this->api = new BasicShopifyAPI($options);
   
       $this->api->setSession(new Session(env('SHOPIFY_URL_DEV'), env('SHOPIFY_API_PASSWORD_DEV')));        $this->api->setSession(new Session(env('SHOPIFY_URL_DEV'), env('SHOPIFY_API_PASSWORD_DEV')));
   
       //$verified = $this->verifyWebhook($this->data, $this->hmacHeader);        //$verified = $this->verifyWebhook($this->data, $this->hmacHeader);
       $verified = true;        $verified = true;
   
       if ($verified) {        if ($verified) {
           $orderData = json_decode($this->data);            $orderData = json_decode($this->data);
   
           $orderId = $orderData->id;            $orderId = $orderData->id;
           Log::info("Processing order - " . $orderId);            Log::info("Processing order - " . $orderId);
   
           $emailId = $orderData->email;            $emailId = $orderData->email;
           $orderName = $orderData->name;            $orderName = $orderData->name;
   
           $noteAttributes = $this->formatData($orderData->note_attributes);            $noteAttributes = $this->formatData($orderData->note_attributes);
   
           foreach ($orderData->line_items as $orderLineItem) {            foreach ($orderData->line_items as $orderLineItem) {
   
               if (!isset($webhook[$orderLineItem->variant_id])) {                if (!isset($webhook[$orderLineItem->variant_id])) {
   
                   $webhook[$orderLineItem->variant_id]['product_title'] = $orderLineItem->title;                    $webhook[$orderLineItem->variant_id]['product_title'] = $orderLineItem->title;
                   $webhook[$orderLineItem->variant_id]['variant_title'] = $orderLineItem->variant_title;                    $webhook[$orderLineItem->variant_id]['variant_title'] = $orderLineItem->variant_title;
                   $webhook[$orderLineItem->variant_id]['quantity'] = $orderLineItem->quantity;                    $webhook[$orderLineItem->variant_id]['quantity'] = $orderLineItem->quantity;
                   $webhook[$orderLineItem->variant_id]['variant_id'] = $orderLineItem->variant_id;                    $webhook[$orderLineItem->variant_id]['variant_id'] = $orderLineItem->variant_id;
                   $webhook[$orderLineItem->variant_id]['price'] = $orderLineItem->price;                    $webhook[$orderLineItem->variant_id]['price'] = $orderLineItem->price;
                   $webhook[$orderLineItem->variant_id]['product_id'] = $orderLineItem->product_id;                    $webhook[$orderLineItem->variant_id]['product_id'] = $orderLineItem->product_id;
   
               }                }
           }            }
   
           $res = $this->getOrderFulfillment($orderId);            $res = $this->getOrderFulfillment($orderId);
           $count = count($res);            $count = count($res);
           $request = array();            $request = array();
   
           foreach ($res[$count - 1]['line_items'] as $lineItem) {            foreach ($res[$count - 1]['line_items'] as $lineItem) {
   
               if (!isset($currentOrder[$lineItem['variant_id']])) {                if (!isset($currentOrder[$lineItem['variant_id']])) {
.                       
                   $variantName = isset($webhook[$lineItem['variant_id']]) ? $webhook[$lineItem['variant_id']]['variant_title'] : '';                    $variantName = isset($webhook[$lineItem['variant_id']]) ? $webhook[$lineItem['variant_id']]['variant_title'] : '';
.                      
                   $productName = isset($webhook[$lineItem['variant_id']]) ? $webhook[$lineItem['variant_id']]['product_title'] : '';                    $productName = isset($webhook[$lineItem['variant_id']]) ? $webhook[$lineItem['variant_id']]['product_title'] : '';
   
                   $currentOrder[$lineItem['variant_id']]['variant_id'] = $lineItem['variant_id'];                    $currentOrder[$lineItem['variant_id']]['variant_id'] = $lineItem['variant_id'];
                   $currentOrder[$lineItem['variant_id']]['quantity'] = $lineItem['quantity'];                    $currentOrder[$lineItem['variant_id']]['quantity'] = $lineItem['quantity'];
                   $currentOrder[$lineItem['variant_id']]['variant_title'] = $variantName;                    $currentOrder[$lineItem['variant_id']]['variant_title'] = $variantName;
                   $currentOrder[$lineItem['variant_id']]['product_title'] = $productName;                    $currentOrder[$lineItem['variant_id']]['product_title'] = $productName;
   
                   $temp = [];                    $temp = [];
                   $temp['name'] = "Final : " . $variantName;                    $temp['name'] = "Final : " . $variantName;
                   $temp['value'] = $lineItem['quantity'];                    $temp['value'] = $lineItem['quantity'];
                   $request[] = $temp;                    $request[] = $temp;
               }                }
           }            }
   
           foreach ($res[0]['line_items'] as $Item) {            foreach ($res[0]['line_items'] as $Item) {
   
.                if (!isset($initalOrder[$Item['variant_id']])) {                if (!isset($initialOrder[$Item['variant_id']])) {
   
.                    $initalOrder[$Item['variant_id']]['variant_id'] = $Item['variant_id'];                    $initialOrder[$Item['variant_id']]['variant_id'] = $Item['variant_id'];
                   $initalOrder[$Item['variant_id']]['quantity'] = $Item['quantity'];                    $initialOrder[$Item['variant_id']]['quantity'] = $Item['quantity'];
               }                }
           }            }
   
           $lastUpdate = $this->formatLastUpdate($currentOrder);            $lastUpdate = $this->formatLastUpdate($currentOrder);
.             $isRefund = false;
   
.            if (count($initalOrder) !== count($currentOrder)) {            if (count($initialOrder) !== count($currentOrder)) {
               // need to send mail                // need to send mail
               // if remove product from order                // if remove product from order
   
.                if (!isset($noteAttributes['noteAttributes'])) {                if (empty($noteAttributes['noteAttributes'])) {
                   Log::info('need to send mail');                    Log::info('need to send mail');
.                    $this->sendEditMail($webhook, $initalOrder, $currentOrder, $orderData);                    $this->sendEditMail($webhook, $initialOrder, $currentOrder, $orderData);
                   $this->updateNoteAttributes($orderData, $noteAttributes['fullNoteAttributes'], $lastUpdate);                    $this->updateNoteAttributes($orderData, $noteAttributes['fullNoteAttributes'], $lastUpdate);
               } else {                } else {
.   
   
                     $lastUpdateFormat = $this->arrangeLastUpdate($lastUpdate);
   
                   $sendMail = false;                    $sendMail = false;
                   foreach ($noteAttributes['noteAttributes'] as $name => $value) {                    foreach ($noteAttributes['noteAttributes'] as $name => $value) {
.                        if (isset($lastUpdate[$name]) && $value !== $lastUpdate[$name]) {     
                         if(!in_array($name, array_keys($lastUpdateFormat))){ 
                             $sendMail = true; 
                             break; 
                         } 
      
                         if (isset($lastUpdateFormat[$name]) && $value !== $lastUpdateFormat[$name]) {
                           $sendMail = true;                            $sendMail = true;
                           break;                            break;
                       }                        }
.      
                          
                   }                    }
   
                   if ($sendMail) {                    if ($sendMail) {
                       // send mail                        // send mail
   
                       Log::info('send mail');                        Log::info('send mail');
                       $this->updateNoteAttributes($orderData, $noteAttributes['fullNoteAttributes'], $lastUpdate);                        $this->updateNoteAttributes($orderData, $noteAttributes['fullNoteAttributes'], $lastUpdate);
.                        $this->sendEditMail($webhook, $initalOrder, $currentOrder, $orderData);                        $this->sendEditMail($webhook, $initialOrder, $currentOrder, $orderData);
                       die('send mail => some value changes');                        die('send mail => some value changes');
   
                   }                    }
               }                }
.   
               die;  
           } else {            } else {
.                // check codition  and send mail                // check condition  and send mail
   
.                Log::info('check codition  and send mail');                Log::info('check condition  and send mail');
               $sendMail = false;                $sendMail = false;
   
.                if (!isset($noteAttributes['noteAttributes'])) {                if (empty($noteAttributes['noteAttributes'])) {
   
.                    foreach ($initalOrder as $variantId => $value) {                    foreach ($initialOrder as $variantId => $value) {
                       if ($value['quantity'] != $lastUpdate[$variantId]['quantity']) {                        if ($value['quantity'] != $lastUpdate[$variantId]['quantity']) {
                           $sendMail = true;                            $sendMail = true;
                           break;                            break;
                       }                        }
                   }                    }
.   
                     $refundData = $orderData->refunds;
                     if(!empty($refundData)){
                         $refundLineItems = $orderData->refunds[0]->refund_line_items;
      
                         foreach ($initialOrder as $variantId => $value) {
          
                             foreach($refundLineItems as $refundDetails){
                                 if ($refundDetails->line_item->variant_id == $variantId &&
                                     $refundDetails->line_item->quantity == $value['quantity']) {
                                     $isRefund = true;  
                                     $sendMail = true;
                                     break;
                                 }
                             }
                          
                         }
                     }
               } else {                } else {
.                    foreach ($noteAttributes['noteAttributes'] as $name => $value) {   
                       if (isset($lastUpdate[$name]) && $value !== $lastUpdate[$name]) {   
                     foreach ($lastUpdate as $variantId => $valueDetails) { 
   
                         $prodName = $valueDetails['productTitle']; 
                         $prodQty = $valueDetails['quantity']; 
      
                         if (isset($noteAttributes['noteAttributes'][$prodName]) && $noteAttributes['noteAttributes'][$prodName] !== $prodQty) { 
                          
                           $sendMail = true;                            $sendMail = true;
                           break;                            break;
                       }                        }
                   }                    }
               }                }
   
           }            }
   
           if ($sendMail) {            if ($sendMail) {
               // send mail                // send mail
   
               Log::info('send mail');                Log::info('send mail');
               $this->updateNoteAttributes($orderData, $noteAttributes['fullNoteAttributes'], $lastUpdate);                $this->updateNoteAttributes($orderData, $noteAttributes['fullNoteAttributes'], $lastUpdate);
.                $this->sendEditMail($webhook, $initalOrder, $currentOrder, $orderData);                  
                 if($isRefund == true) { 
                     $currentOrder = []; 
                 } 
      
                 $this->sendEditMail($webhook, $initialOrder, $currentOrder, $orderData); 
   
               die('send mail => some value changes');                die('send mail => some value changes');
   
           } else {            } else {
               Log::info('send mail => no need');                Log::info('send mail => no need');
               die('send mail => no need');                die('send mail => no need');
           }            }
   
           die;            die;
       }        }
   }    }
   
.    public function formatLastUpdate($currentOrder)     function formatLastUpdate($currentOrder){
   {  
   
       $returnArray = array();        $returnArray = array();
.        if (!empty($currentOrder)) {        if(!empty($currentOrder)){
           foreach ($currentOrder as $orderID => $orderDetails) {            foreach($currentOrder as $orderID => $orderDetails) {
               $returnArray[$orderDetails['product_title']] = $orderDetails['quantity'];                 
                 $returnArray[$orderDetails['variant_id']] = array( 
                     "quantity" => $orderDetails['quantity'], 
                     "variantId" => $orderDetails['variant_id'], 
                     "productTitle" => $orderDetails['product_title'] 
                 );
           }            }
       }        }
   
       return $returnArray;        return $returnArray;
   }    }
   
.     function arrangeLastUpdate($lastUpdate){
   
   
         $returnData = [];
   
         if(!empty($lastUpdate)) {
             foreach($lastUpdate as $key => $value) {
                 $prodName = $value['productTitle'];
                 $prodQty = $value['quantity'];
                 $returnData[$prodName] = $prodQty;
             }
         }
   
         return $returnData;
     }
   
   public function formatData($noteAttributes)    public function formatData($noteAttributes)
   {    {
       $returnArray = [];        $returnArray = [];
       $fullNoteAttributes = [];        $fullNoteAttributes = [];
       if (!empty($noteAttributes)) {        if (!empty($noteAttributes)) {
           foreach ($noteAttributes as $attributes) {            foreach ($noteAttributes as $attributes) {
               $name = $attributes->name;                $name = $attributes->name;
               $value = $attributes->value;                $value = $attributes->value;
   
               if (strpos($attributes->name, "Final : ") !== false) {                if (strpos($attributes->name, "Final : ") !== false) {
                   $name = str_replace("Final : ", "", $attributes->name);                    $name = str_replace("Final : ", "", $attributes->name);
                   $returnArray[$name] = $value;                    $returnArray[$name] = $value;
               }                }
               $fullNoteAttributes[$name] = $value;                $fullNoteAttributes[$name] = $value;
           }            }
       }        }
   
       return [        return [
           "noteAttributes" => $returnArray,            "noteAttributes" => $returnArray,
           "fullNoteAttributes" => $fullNoteAttributes,            "fullNoteAttributes" => $fullNoteAttributes,
       ];        ];
   }    }
   
.    public function updateNoteAttributes($data, $noteAttributes, $updatedData)     public function updateNoteAttributes($data, $noteAttributes, $updatedData) {
   {  
   
       $orderId = $data->id;        $orderId = $data->id;
       $orderTag = $data->tags;        $orderTag = $data->tags;
.        $orderNoteAttributes = $data->note_attributes;         $orderNoteAttributesObject = $data->note_attributes; 
         $orderNoteAttributes = []; 
         if(!empty($orderNoteAttributesObject)){ 
             foreach($orderNoteAttributesObject as $object){ 
                 $temp['name'] = $object->name; 
                 $temp['value'] = $object->value; 
                 $orderNoteAttributes[] = $temp; 
             } 
         } 
   
       $noteRequest = [];        $noteRequest = [];
   
       // update note attributes        // update note attributes
.        if (!empty($updatedData)) {        if(!empty($updatedData)) {
           foreach ($updatedData as $name => $value) {            foreach($updatedData as $variantId => $variantIdDetails) {
   
.                if (!empty($orderNoteAttributes)) {                 $variantQty = $variantIdDetails['quantity'];
                   foreach ($orderNoteAttributes as $key => $noteValues) {                 $name = $variantIdDetails['productTitle']; 
                       $noteName = isset($noteValues->name) ? $noteValues->name : '';  
                       $noteQty = isset($noteValues->value) ? $noteValues->value : '';   
   
                       $checkName = str_replace("Final : ", "", $noteName);   
   
.                        if (strpos($noteName, $name) !== false) {                 if(!empty($orderNoteAttributes)) { 
                           $noteQty = $value;     
                           $orderNoteAttributes[$key]->value = $noteQty;                    foreach($orderNoteAttributes as $key => $noteValues) { 
                          
                         if(!is_array($noteValues)) { 
                             $noteValues = (array)$noteValues;
                       }                        }
   
.                        // if(!array_key_exists($checkName, $updatedData)) {                         $noteName = $noteValues['name']; 
                         $noteQty  = $noteValues['value']; 
   
.                        //     unset($orderNoteAttributes[$key]);                        // $noteName = $noteValues->name; 
                       // }                         // $noteQty  = $noteValues->value; 
      
                         $checkName = str_replace("Final : ", "", $noteName); 
      
                         if(strpos($noteName, $name) !== false) { 
                             $noteQty = $variantQty; 
                  
                             $orderNoteAttributes[$key]['value'] = $noteQty;
                             // $orderNoteAttributes[$key]->value = $noteQty; 
                         } 
                      
                   }                    }
               }                }
   
.                if (!array_key_exists($name, $noteAttributes)) {                if(!array_key_exists($name, $noteAttributes)){
                   $temp['name'] = "Final : " . $name;                    $temp['name'] = "Final : ".$name;
                   $temp['value'] = $value;                    $temp['value'] = $variantQty;
                   $orderNoteAttributes[] = $temp;                    $orderNoteAttributes[] = $temp;
.                }                 }   
           }            }
       }        }
   
.        $newAttributes = (array) $orderNoteAttributes;        $newAttributes = (array)$orderNoteAttributes;
   
       $request['order']['id'] = $orderId;        $request['order']['id'] = $orderId;
       $request['order']['note_attributes'] = $newAttributes;        $request['order']['note_attributes'] = $newAttributes;
   
       $result = $this->api->rest(        $result = $this->api->rest(
           'PUT',            'PUT',
.            '/admin/api/' . env('SHOPIFY_API_VER_DEV') . '/orders/' . $orderId . '.json',            '/admin/api/'.env('SHOPIFY_API_VER_DEV').'/orders/'.$orderId.'.json',
           $request            $request
       );        );
.          
       if (isset($result->errors) && $result->errors == true) {        if (isset($result->errors) && $result->errors == true) {
   
           echo "error";            echo "error";
.            Log::info("Error in updating the order");  
           Log::info(json_encode($result));  
   
           return null;            return null;
       } else {        } else {
.            Log::info("Success in order updates");   
           $updatedOrder = $result['body']->container['order'];            $updatedOrder = $result['body']->container['order'];
       }        }
   }    }
   
   public function getOrderFulfillment($orderId)    public function getOrderFulfillment($orderId)
   {    {
   
       $result = $this->api->rest(        $result = $this->api->rest(
           'GET',            'GET',
           '/admin/api/' . env('SHOPIFY_API_VER_DEV') . '/orders/' . $orderId . '/fulfillment_orders.json',            '/admin/api/' . env('SHOPIFY_API_VER_DEV') . '/orders/' . $orderId . '/fulfillment_orders.json',
           null            null
       );        );
   
       if (isset($result->errors) && $result->errors == true) {        if (isset($result->errors) && $result->errors == true) {
           return null;            return null;
       } else {        } else {
   
           $fulfillmentDetails = $result['body']->container['fulfillment_orders'];            $fulfillmentDetails = $result['body']->container['fulfillment_orders'];
       }        }
   
       return $fulfillmentDetails;        return $fulfillmentDetails;
   }    }
   
   public function getImageUrl($productId)    public function getImageUrl($productId)
   {    {
   
       $imageUrl = '';        $imageUrl = '';
       if (!empty($productId)) {        if (!empty($productId)) {
           $result = $this->api->rest(            $result = $this->api->rest(
               'GET',                'GET',
               '/admin/api/' . env('SHOPIFY_API_VER_DEV') . '/products/' . $productId . '.json',                '/admin/api/' . env('SHOPIFY_API_VER_DEV') . '/products/' . $productId . '.json',
               null                null
           );            );
   
           if (isset($result->errors) && $result->errors == true) {            if (isset($result->errors) && $result->errors == true) {
               return null;                return null;
           } else {            } else {
   
               $imageDetails = $result['body']->container['product']['images'];                $imageDetails = $result['body']->container['product']['images'];
               $imageUrl = isset($imageDetails[0]['src']) ? $imageDetails[0]['src'] : "";                $imageUrl = isset($imageDetails[0]['src']) ? $imageDetails[0]['src'] : "";
           }            }
   
           return $imageUrl;            return $imageUrl;
       }        }
   }    }
.    public function setLineItemDetails($webhook, $initalOrder, $currentOrder, $orderData)    public function setLineItemDetails($webhook, $initialOrder, $currentOrder, $orderData)
   {    {
   
       $lineItemContent = '';        $lineItemContent = '';
       foreach ($currentOrder as $variantId => $variantDetails) {        foreach ($currentOrder as $variantId => $variantDetails) {
.              
           $productName = '';            $productName = '';
           $variantName = '';            $variantName = '';
           $oldQty = '';            $oldQty = '';
           $newQty = '';            $newQty = '';
           $imageUrl = $this->getImageUrl($webhook[$variantDetails['variant_id']]['product_id']);            $imageUrl = $this->getImageUrl($webhook[$variantDetails['variant_id']]['product_id']);
   
.            if (isset($initalOrder[$variantId])) {            if (isset($initialOrder[$variantId])) {
               $productName = $variantDetails['product_title'];                $productName = $variantDetails['product_title'];
               $variantName = $variantDetails['variant_title'];                $variantName = $variantDetails['variant_title'];
.                  
               $productQty = $variantDetails['quantity'];                $productQty = $variantDetails['quantity'];
.                $oldQty = $initalOrder[$variantId]['quantity'];                $oldQty = $initialOrder[$variantId]['quantity'];
               $newQty = $currentOrder[$variantId]['quantity'];                $newQty = $currentOrder[$variantId]['quantity'];
               $price = isset($webhook[$variantId]) ? $webhook[$variantId]['price'] : '0.00';                $price = isset($webhook[$variantId]) ? $webhook[$variantId]['price'] : '0.00';
               $total = $price * $productQty;                $total = $price * $productQty;
   
               $lineItemContent .= '<tr class="order-list__item" style="width: 100%;">                $lineItemContent .= '<tr class="order-list__item" style="width: 100%;">
               <td class="order-list__item__cell"                 <td class="order-list__item__cell" 
               style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif; padding-bottom: 15px;">                style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif; padding-bottom: 15px;">
               <table style="border-spacing: 0; border-collapse: collapse;">                <table style="border-spacing: 0; border-collapse: collapse;">
               <tbody>                <tbody>
               <tr>                <tr>
               <td                <td
               style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif;">                style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif;">
               <img align="left" alt="" class="order-list__product-image" height="60"                 <img align="left" alt="" class="order-list__product-image" height="60" 
               src="' . $imageUrl . '"                 src="' . $imageUrl . '" 
               style="margin-right: 15px; border-radius: 8px; border: 1px solid #e5e5e5;" width="60" />                style="margin-right: 15px; border-radius: 8px; border: 1px solid #e5e5e5;" width="60" />
               </td>                </td>
               <td class="order-list__product-description-cell"                 <td class="order-list__product-description-cell" 
               style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif; width: 100%;">                style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif; width: 100%;">
               <span class="order-list__item-title"                 <span class="order-list__item-title" 
               style="font-size: 16px; font-weight: 600; line-height: 1.4; color: #555;">' . $productName . '&nbsp;×&nbsp;' . $newQty . '</span>                style="font-size: 16px; font-weight: 600; line-height: 1.4; color: #555;">' . $productName . '&nbsp;×&nbsp;' . $newQty . '</span>
               <br />                <br />
               <span class="order-list__item-variant" style="font-size: 14px; color: #999;">' . $variantName . '</span>                <span class="order-list__item-variant" style="font-size: 14px; color: #999;">' . $variantName . '</span>
               </td>                </td>
               <td class="order-list__price-cell"                 <td class="order-list__price-cell" 
               style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif; white-space: nowrap;">                style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif; white-space: nowrap;">
               <p align="right" class="order-list__item-price"                 <p align="right" class="order-list__item-price" 
               style="color: #555; line-height: 150%; font-size: 16px; font-weight: 600; margin: 0 0 0 15px;">                style="color: #555; line-height: 150%; font-size: 16px; font-weight: 600; margin: 0 0 0 15px;">
               $' . $total . '                 $' . $total . ' 
               </p>                </p>
               </td>                </td>
               </tr>                </tr>
               </tbody>                </tbody>
               </table>                </table>
               </td>                </td>
               </tr>';                </tr>';
   
           } else {            } else {
   
               $productName = $variantDetails['product_title'];                $productName = $variantDetails['product_title'];
               $variantName = $variantDetails['variant_title'];                $variantName = $variantDetails['variant_title'];
               $productQty = $variantDetails['quantity'];                $productQty = $variantDetails['quantity'];
               $price = isset($webhook[$variantId]) ? $webhook[$variantId]['price'] : '0.00';                $price = isset($webhook[$variantId]) ? $webhook[$variantId]['price'] : '0.00';
               $total = $price * $productQty;                $total = $price * $productQty;
   
               $lineItemContent .= '<tr class="order-list__item" style="width: 100%;">                $lineItemContent .= '<tr class="order-list__item" style="width: 100%;">
               <td class="order-list__item__cell"                 <td class="order-list__item__cell" 
               style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif; padding-bottom: 15px;">                style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif; padding-bottom: 15px;">
               <table style="border-spacing: 0; border-collapse: collapse;">                <table style="border-spacing: 0; border-collapse: collapse;">
               <tbody>                <tbody>
               <tr>                <tr>
               <td                <td
               style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif;">                style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif;">
               <img align="left" alt="" class="order-list__product-image" height="60"                 <img align="left" alt="" class="order-list__product-image" height="60" 
               src="https://cdn.shopify.com/s/files/1/0066/7569/3639/products/NM2844L600VITD3GUMMIESfront_compact_cropped.jpg?v=1588875151"                 src="https://cdn.shopify.com/s/files/1/0066/7569/3639/products/NM2844L600VITD3GUMMIESfront_compact_cropped.jpg?v=1588875151" 
               style="margin-right: 15px; border-radius: 8px; border: 1px solid #e5e5e5;" width="60" />                style="margin-right: 15px; border-radius: 8px; border: 1px solid #e5e5e5;" width="60" />
               </td>                </td>
               <td class="order-list__product-description-cell"                 <td class="order-list__product-description-cell" 
               style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif; width: 100%;">                style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif; width: 100%;">
               <span class="order-list__item-title"                 <span class="order-list__item-title" 
               style="font-size: 16px; font-weight: 600; line-height: 1.4; color: #555;">' . $productName . '&nbsp;×&nbsp;' . $productQty . '</span>                style="font-size: 16px; font-weight: 600; line-height: 1.4; color: #555;">' . $productName . '&nbsp;×&nbsp;' . $productQty . '</span>
               <br />                <br />
               <span class="order-list__item-variant" style="font-size: 14px; color: #999;">' . $variantName . '</span>                <span class="order-list__item-variant" style="font-size: 14px; color: #999;">' . $variantName . '</span>
               </td>                </td>
               <td class="order-list__price-cell"                 <td class="order-list__price-cell" 
               style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif; white-space: nowrap;">                style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif; white-space: nowrap;">
               <p align="right" class="order-list__item-price"                 <p align="right" class="order-list__item-price" 
               style="color: #555; line-height: 150%; font-size: 16px; font-weight: 600; margin: 0 0 0 15px;">                style="color: #555; line-height: 150%; font-size: 16px; font-weight: 600; margin: 0 0 0 15px;">
               $' . $total . '                 $' . $total . ' 
               </p>                </p>
               </td>                </td>
               </tr>                </tr>
               </tbody>                </tbody>
               </table>                </table>
               </td>                </td>
               </tr>';                </tr>';
           }            }
       }        }
   
       return $lineItemContent;        return $lineItemContent;
   }    }
   
.    public function setRemovedLineItemsDetails($webhook, $initalOrder, $currentOrder)    public function setRemovedLineItemsDetails($webhook, $initialOrder, $currentOrder)
   {    {
.   
       $removedOrderSet = false;        $removedOrderSet = false;
       $removedOrders = '<table class="row section" style="width: 100%; border-spacing: 0; border-collapse: collapse; border-top-width: 1px; border-top-color: #e5e5e5; border-top-style: solid;">        $removedOrders = '<table class="row section" style="width: 100%; border-spacing: 0; border-collapse: collapse; border-top-width: 1px; border-top-color: #e5e5e5; border-top-style: solid;">
       <tbody>        <tbody>
         <tr>          <tr>
           <td class="section__cell" style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif; max-width: 500px; padding: 20px 0;">            <td class="section__cell" style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif; max-width: 500px; padding: 20px 0;">
             <center>              <center>
               <table class="container" style="width: 560px; text-align: left; border-spacing: 0; border-collapse: collapse; max-width: 500px; margin: 0 auto;">                <table class="container" style="width: 560px; text-align: left; border-spacing: 0; border-collapse: collapse; max-width: 500px; margin: 0 auto;">
                 <tbody>                  <tbody>
                   <tr>                    <tr>
                     <td style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif;">                      <td style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif;">
                       <h3 style="font-weight: normal; font-size: 20px; margin: 0 0 25px;">Removed Products                        <h3 style="font-weight: normal; font-size: 20px; margin: 0 0 25px;">Removed Products
                       </h3>                        </h3>
                     </td>                      </td>
                   </tr>                    </tr>
                 </tbody>                  </tbody>
               </table>                </table>
               <table class="container" style="width: 560px; text-align: left; border-spacing: 0; border-collapse: collapse; max-width: 500px; margin: 0 auto;">                <table class="container" style="width: 560px; text-align: left; border-spacing: 0; border-collapse: collapse; max-width: 500px; margin: 0 auto;">
               <tbody>                <tbody>
                 <tr>                  <tr>
                   <td style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif;">                    <td style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif;">
                     <table class="row" style="width: 100%; border-spacing: 0; border-collapse: collapse;">                      <table class="row" style="width: 100%; border-spacing: 0; border-collapse: collapse;">
                       <tbody>';                        <tbody>';
   
.        foreach ($initalOrder as $inital) {        foreach ($initialOrder as $initial) {
           $productName = $webhook[$inital['variant_id']]['product_title'];            $productName = $webhook[$initial['variant_id']]['product_title'];
           $variantName = $webhook[$inital['variant_id']]['variant_title'];            $variantName = $webhook[$initial['variant_id']]['variant_title'];
          
           $productQty = $webhook[$inital['variant_id']]['quantity'];            $productQty = $webhook[$initial['variant_id']]['quantity'];
           $price = isset($webhook[$inital['variant_id']]['price']) ? $webhook[$inital['variant_id']]['price'] : '0.00';            $price = isset($webhook[$initial['variant_id']]['price']) ? $webhook[$initial['variant_id']]['price'] : '0.00';
           $total = "$" . $price * $productQty;            $total = "$" . $price * $productQty;
.            $imageUrl = $this->getImageUrl($webhook[$inital['variant_id']]['product_id']);            $imageUrl = $this->getImageUrl($webhook[$initial['variant_id']]['product_id']);
                
           if (!isset($currentOrder[$inital['variant_id']])) {            if (!isset($currentOrder[$initial['variant_id']])) {
               $removedOrderSet = true;                $removedOrderSet = true;
               $removedOrders .= '                $removedOrders .= '
               <tr class="order-list__item" style="width: 100%;">                <tr class="order-list__item" style="width: 100%;">
                   <td class="order-list__item__cell" style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif; padding-bottom: 15px;">                    <td class="order-list__item__cell" style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif; padding-bottom: 15px;">
                       <table style="border-spacing: 0; border-collapse: collapse;">                        <table style="border-spacing: 0; border-collapse: collapse;">
                           <tbody>                            <tbody>
                               <tr>                                <tr>
                                   <td style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif;">                                    <td style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif;">
                                       <div style="width: 62px;border-radius: 8px;overflow: hidden;     background-image: url(https://cdn.shopify.com/s/files/1/0066/7569/3639/files/soldout.png?v=1602823461); background-repeat: no-repeat; background-size: 100% 100%; margin-right: 15px;"><img alt="" class="order-list__product-image" height="60" src="' . $imageUrl . '" style="border-radius: 8px; border: 1px solid #e5e5e5; opacity: 0.5;" width="60" />                                        <div style="width: 62px;border-radius: 8px;overflow: hidden;     background-image: url(https://cdn.shopify.com/s/files/1/0066/7569/3639/files/soldout.png?v=1602823461); background-repeat: no-repeat; background-size: 100% 100%; margin-right: 15px;"><img alt="" class="order-list__product-image" height="60" src="' . $imageUrl . '" style="border-radius: 8px; border: 1px solid #e5e5e5; opacity: 0.5;" width="60" />
                                       </div>                                        </div>
                                   </td>                                    </td>
                                   <td class="order-list__product-description-cell" style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif; width: 100%;"><span class="order-list__item-title" style="font-size: 16px; font-weight: 600; line-height: 1.4; color: #555;"><del style="opacity:0.5">' . $productName . '&nbsp;×&nbsp;' . $productQty . '</del></span>                                    <td class="order-list__product-description-cell" style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif; width: 100%;"><span class="order-list__item-title" style="font-size: 16px; font-weight: 600; line-height: 1.4; color: #555;"><del style="opacity:0.5">' . $productName . '&nbsp;×&nbsp;' . $productQty . '</del></span>
                                       <br />                                        <br />
                                       <span class="order-list__item-variant" style="font-size: 14px; color: #999;"><del style="opacity:0.5">' . $variantName . '</del></span>                                        <span class="order-list__item-variant" style="font-size: 14px; color: #999;"><del style="opacity:0.5">' . $variantName . '</del></span>
                                   </td>                                    </td>
                                   <td class="order-list__price-cell" style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif; white-space: nowrap;"><del class="order-list__item-original-price" style="font-size: 14px; display: block; text-align: right; color: #999; opacity: 0.5;"></del>                                    <td class="order-list__price-cell" style="font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;, &quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif; white-space: nowrap;"><del class="order-list__item-original-price" style="font-size: 14px; display: block; text-align: right; color: #999; opacity: 0.5;"></del>
                                       <p align="right" class="order-list__item-price" style="color: #555; line-height: 150%; font-size: 16px; font-weight: 600; margin: 0 0 0 15px;"><del style="opacity:0.5">' . $total . '</del>                                        <p align="right" class="order-list__item-price" style="color: #555; line-height: 150%; font-size: 16px; font-weight: 600; margin: 0 0 0 15px;"><del style="opacity:0.5">' . $total . '</del>
                                       </p>                                        </p>
                                   </td>                                    </td>
                               </tr>                                </tr>
                           </tbody>                            </tbody>
                       </table>                        </table>
                   </td>                    </td>
               </tr>';                </tr>';
           }            }
       }        }
   
       $removedOrders .= '        $removedOrders .= '
       </tbody>        </tbody>
           </table>            </table>
           </td>            </td>
       </tr>        </tr>
       </tbody>        </tbody>
       </table>        </table>
       </center>        </center>
       </td>        </td>
       </tr>        </tr>
       </tbody>        </tbody>
       </table>';        </table>';
   
       return ($removedOrderSet == true) ? $removedOrders : '';        return ($removedOrderSet == true) ? $removedOrders : '';
   }    }
   
.    public function sendEditMail($webhook, $initalOrder, $currentOrder, $orderData)     public function getRefundSubTotalTaxAmount($orderData){ 
         $refundTaxAmount = 0; 
         $refundSubtotalAmount = 0; 
   
         if(empty($orderData->refunds)) { 
             return [ 
                 "refundTaxAmount" => $refundTaxAmount, 
                 "refundSubtotalAmount" => $refundSubtotalAmount 
             ]; 
         } else { 
   
             if(isset($orderData->refunds[0]->refund_line_items)){ 
                 foreach($orderData->refunds[0]->refund_line_items as $refundData) { 
                     $refundTaxAmount += $refundData->total_tax; 
                     $refundSubtotalAmount += $refundData->subtotal; 
                 } 
             } 
         } 
   
         return [ 
             "refundTaxAmount" => $refundTaxAmount, 
             "refundSubtotalAmount" => $refundSubtotalAmount 
         ]; 
     } 
   
     public function sendEditMail($webhook, $initialOrder, $currentOrder, $orderData) 
   {    {
       $orderName = $orderData->name;        $orderName = $orderData->name;
.        $orderTotal = '$' . $orderData->total_price;  
       $subTotal = '$' . $orderData->subtotal_price;         $refundDetails = $this->getRefundSubTotalTaxAmount($orderData); 
   
         // $orderTotal = '$' . $orderData->total_price;
         $orderTotal = '$'.($orderData->total_price - $refundDetails['refundSubtotalAmount']); 
   
         // $subTotal = '$' . $orderData->subtotal_price; 
         $subTotal = '$'.($orderData->subtotal_price - $refundDetails['refundSubtotalAmount']); 
   
       $address = $this->getAddressContent($orderData);        $address = $this->getAddressContent($orderData);
.        $totalTax = '$' . $orderData->total_tax;          
         //$totalTax = '$' . $orderData->total_tax; 
         $totalTax = '$'.($orderData->total_tax - $refundDetails['refundTaxAmount']); 
   
       $currency = $orderData->currency;        $currency = $orderData->currency;
       $orderStatusUrl = $orderData->order_status_url;        $orderStatusUrl = $orderData->order_status_url;
       $paymentName = isset($orderData->payment_gateway_names[0]) ? $orderData->payment_gateway_names[0] : '';        $paymentName = isset($orderData->payment_gateway_names[0]) ? $orderData->payment_gateway_names[0] : '';
       $shippingName = isset($orderData->shipping_lines[0]->title) ? $orderData->shipping_lines[0]->title : '';        $shippingName = isset($orderData->shipping_lines[0]->title) ? $orderData->shipping_lines[0]->title : '';
.        $lineItemDetails = $this->setLineItemDetails($webhook, $initalOrder, $currentOrder, $orderData);        $lineItemDetails = $this->setLineItemDetails($webhook, $initialOrder, $currentOrder, $orderData);
       $removedDetails = $this->setRemovedLineItemsDetails($webhook, $initalOrder, $currentOrder);        $removedDetails = $this->setRemovedLineItemsDetails($webhook, $initialOrder, $currentOrder);
       $email = $orderData->email;        $email = $orderData->email;
.          
   
       $iterableMailRequest = array(        $iterableMailRequest = array(
   
           "campaignId" => intval(env('ITERABLE_CAMPAIGN_ID', true)),            "campaignId" => intval(env('ITERABLE_CAMPAIGN_ID', true)),
           "recipientEmail" => $email,            "recipientEmail" => $email,
           "dataFields" => array(            "dataFields" => array(
               "orderName" => $orderName,                "orderName" => $orderName,
               "totalPrice" => $orderTotal,                "totalPrice" => $orderTotal,
               "shippingAddress" => $address['shippingAddress'],                "shippingAddress" => $address['shippingAddress'],
               "billingAddress" => $address['billingAddress'],                "billingAddress" => $address['billingAddress'],
               "subTotal" => $subTotal,                "subTotal" => $subTotal,
               "totalTax" => $totalTax,                "totalTax" => $totalTax,
               "currency" => $currency,                "currency" => $currency,
               "shippingMethod" => $shippingName,                "shippingMethod" => $shippingName,
               "paymentMethod" => $paymentName,                "paymentMethod" => $paymentName,
               "lineItemDetails" => $lineItemDetails,                "lineItemDetails" => $lineItemDetails,
               "removedLineItemDetails" => $removedDetails,                "removedLineItemDetails" => $removedDetails,
               "orderStatusUrl" => $orderStatusUrl,                "orderStatusUrl" => $orderStatusUrl,
           ),            ),
       );        );
   
       $mailTriggerResponse = $this->iterableObj->sendMailFromIterable(json_encode($iterableMailRequest));        $mailTriggerResponse = $this->iterableObj->sendMailFromIterable(json_encode($iterableMailRequest));
   
       if (strtolower(trim($mailTriggerResponse->code)) == 'success') {        if (strtolower(trim($mailTriggerResponse->code)) == 'success') {
           echo "mail send....... ";            echo "mail send....... ";
           Log::info('mail send.......');            Log::info('mail send.......');
           $returnData = [            $returnData = [
               "mailStatus" => true,                "mailStatus" => true,
               "message" => "mail triggered successfully (" . $email . ")",                "message" => "mail triggered successfully (" . $email . ")",
           ];            ];
   
           return 'suceess';            return 'suceess';
   
       } else {        } else {
           echo "mail not send....... ";            echo "mail not send....... ";
           Log::info('mail  not send.......');            Log::info('mail  not send.......');
           Log::info(json_encode($mailTriggerResponse));            Log::info(json_encode($mailTriggerResponse));
           $error = $mailTriggerResponse->code;            $error = $mailTriggerResponse->code;
   
           if (empty($error)) {            if (empty($error)) {
   
               $returnData = [                $returnData = [
                   'error' => 'failed to send mail(' . $email . ')',                    'error' => 'failed to send mail(' . $email . ')',
               ];                ];
           } else {            } else {
   
               $returnData = [                $returnData = [
                   'error' => $error . ' (' . $email . ')',                    'error' => $error . ' (' . $email . ')',
               ];                ];
           }            }
           return 'Error';            return 'Error';
       }        }
   
   }    }
   
   public function getAddressContent($orderData)    public function getAddressContent($orderData)
   {    {
   
       $shippingAddress = isset($orderData->shipping_address) ? $orderData->shipping_address : '';        $shippingAddress = isset($orderData->shipping_address) ? $orderData->shipping_address : '';
       $billingAddress = isset($orderData->billing_address) ? $orderData->billing_address : '';        $billingAddress = isset($orderData->billing_address) ? $orderData->billing_address : '';
   
.        $shipingAddressContent = '';        $shippingAddressContent = '';
       $billingAddressContent = '';        $billingAddressContent = '';
   
       if (!empty($shippingAddress)) {        if (!empty($shippingAddress)) {
.            $shipingAddressContent .= '            $shippingAddressContent .= '
           <p style="color:#777777;font-size:16px;margin:0;line-height:150%;">' .            <p style="color:#777777;font-size:16px;margin:0;line-height:150%;">' .
           $shippingAddress->first_name . '  ' . $shippingAddress->last_name .            $shippingAddress->first_name . '  ' . $shippingAddress->last_name .
           '<br />' . $shippingAddress->company . '<br />' .            '<br />' . $shippingAddress->company . '<br />' .
           $shippingAddress->address1 . '<br />' . $shippingAddress->province .            $shippingAddress->address1 . '<br />' . $shippingAddress->province .
           '<br />' . $shippingAddress->country . '<br />' . $shippingAddress->zip . '</p>';            '<br />' . $shippingAddress->country . '<br />' . $shippingAddress->zip . '</p>';
       } else {        } else {
.            $shipingAddressContent .= '            $shippingAddressContent .= '
           <p style="color:#777777;font-size:16px;margin:0;line-height:150%;">' .            <p style="color:#777777;font-size:16px;margin:0;line-height:150%;">' .
               '  <br />  <br /> <br /> <br /> <br /> </p>';                '  <br />  <br /> <br /> <br /> <br /> </p>';
       }        }
   
       if (!empty($billingAddress)) {        if (!empty($billingAddress)) {
           $billingAddressContent .= '            $billingAddressContent .= '
           <p style="color:#777777;font-size:16px;margin:0;line-height:150%;">' .            <p style="color:#777777;font-size:16px;margin:0;line-height:150%;">' .
           $billingAddress->first_name . '  ' . $billingAddress->last_name .            $billingAddress->first_name . '  ' . $billingAddress->last_name .
           '<br />' . $billingAddress->company . '<br />' .            '<br />' . $billingAddress->company . '<br />' .
           $billingAddress->address1 . '<br />' . $billingAddress->province .            $billingAddress->address1 . '<br />' . $billingAddress->province .
           '<br />' . $billingAddress->country . '<br />' . $billingAddress->zip . '</p>';            '<br />' . $billingAddress->country . '<br />' . $billingAddress->zip . '</p>';
       } else {        } else {
           $billingAddressContent .= '            $billingAddressContent .= '
           <p style="color:#777777;font-size:16px;margin:0;line-height:150%;">' .            <p style="color:#777777;font-size:16px;margin:0;line-height:150%;">' .
               '  <br />  <br /> <br /> <br /> <br /> </p>';                '  <br />  <br /> <br /> <br /> <br /> </p>';
       }        }
   
       return [        return [
           "billingAddress" => $billingAddressContent,            "billingAddress" => $billingAddressContent,
.            "shippingAddress" => $shipingAddressContent,            "shippingAddress" => $shippingAddressContent,
       ];        ];
   
   }    }
} }
.