I am installing a webhook that will notifyadministrators
when they add new customers
.
The documentation is in Ruby but I am trying to do this in laravel.
This is what i have done:
CustomerInstallShopifyWebhook
web.php
Now, when I add a customer
, I still don't receive my notification.
Is my job correctly being dispatched?
CustomerInstallShopifyWebhook
class CustomerInstallShopifyWebhook implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $domain;
public $token;
public $store;
public function __construct($domain, $token, \App\Store $store)
{
$this->domain = $domain;
$this->token = $token;
$this->store = $store;
}
public function handle()
{
//
$shopify = \Shopify::retrieve($this->domain, $this->token);
$customerCreate = array
(
'webhook'=>array
(
'topic'=> 'customers/create',
'address'=> 'https://shopify.com/webhook/shopify/customer-created',
'format'=> 'json'
)
);
$customerCreate_webhook = $sc->call('POST', '/admin/webhooks.json', $customerCreate);
header('Content-type: application/json');
echo json_encode(array("state"=>"success", "customer_create"=>$customerCreate_webhook));
}
}
Route
Route::post('webhook/shopify/customer-created', function(\Illuminate\Http\Request $request) {
$query = "?key=**********&to=0501149794&msg=Testing Shopify App&sender_id=Shopify";
$final_uri = $baseurl.$query;
$response = file_get_contents($final_uri);
header ("Content-Type:text/xml");
})->middleware('webhook');