OrderTaggingWebhookController.php (Before) OrderTaggingWebhookController.php (After)
<?php <?php
   
namespace App\Http\Controllers; namespace App\Http\Controllers;
   
use DB; use DB;
use Log; use Log;
use App\Users; use App\Users;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Http\ResponseHelper; use App\Http\ResponseHelper;
use App\Jobs\OrderTaggingJob; use App\Jobs\OrderTaggingJob;
use Config; use Config;
use OhMyBrew\BasicShopifyAPI; use OhMyBrew\BasicShopifyAPI;
   
class OrderTaggingWebhookController extends Controller class OrderTaggingWebhookController extends Controller
{ {
   
   private $helper;    private $helper;
   private $shopifyProductDao;    private $shopifyProductDao;
   private $sharedSecret;    private $sharedSecret;
   private $randomString;    private $randomString;
   private $shopify_api_version;    private $shopify_api_version;
   
   public function __construct()    public function __construct()
   {    {
       $this->helper = new ResponseHelper();        $this->helper = new ResponseHelper();
       $this->shopify_api_version = env('SHOPIFY_API_VERSION', true);        $this->shopify_api_version = env('SHOPIFY_API_VERSION', true);
   }    }
   
   function processWebhook()    function processWebhook()
   {          {      
   
.        $this->sharedSecret   = Config::get('shopify.secret');        $this->sharedSecret   = Config::get('shopify.secretOrderTag');
       $this->webhookContent = $this->webhook($this->sharedSecret);        $this->webhookContent = $this->webhook($this->sharedSecret);
   
       dispatch(new OrderTaggingJob($this->webhookContent));        dispatch(new OrderTaggingJob($this->webhookContent));
   
       return 'true';        return 'true';
                 
   }    }
   
   function webhook($my_shared_secret){    function webhook($my_shared_secret){
                 
       define('SHOPIFY_APP_SECRET', 'my_shared_secret');        define('SHOPIFY_APP_SECRET', 'my_shared_secret');
       $hmac_header = $_SERVER['HTTP_X_SHOPIFY_HMAC_SHA256'];        $hmac_header = $_SERVER['HTTP_X_SHOPIFY_HMAC_SHA256'];
       $data        = file_get_contents('php://input');        $data        = file_get_contents('php://input');
       $verified    = $this->verify_webhook($data, $hmac_header);        $verified    = $this->verify_webhook($data, $hmac_header);
       error_log('Webhook verified: '.var_export($verified, true));        error_log('Webhook verified: '.var_export($verified, true));
       return $data;        return $data;
   
   }    }
   
   function verify_webhook($data, $hmac_header){    function verify_webhook($data, $hmac_header){
   
       $calculated_hmac = base64_encode(hash_hmac('sha256', $data, SHOPIFY_APP_SECRET, true));        $calculated_hmac = base64_encode(hash_hmac('sha256', $data, SHOPIFY_APP_SECRET, true));
       return ($hmac_header==$calculated_hmac);        return ($hmac_header==$calculated_hmac);
   
   }        }    
   
} }
.