From 415b80f6935eeeaef09233e1c6a333de7a31b018 Mon Sep 17 00:00:00 2001 From: vishal gohil Date: Sat, 2 Apr 2022 12:43:18 +0530 Subject: [PATCH 1/6] added the support for AWS EventBridge Shopify Webhook, used eventBridgeWebhookSubscriptionCreate GraphQL --- src/Services/ApiHelper.php | 49 +++++++++++++++++++--------- src/resources/config/shopify-app.php | 16 +++++++++ 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/Services/ApiHelper.php b/src/Services/ApiHelper.php index 3ef65ee9..55a64589 100644 --- a/src/Services/ApiHelper.php +++ b/src/Services/ApiHelper.php @@ -366,26 +366,44 @@ public function getWebhooks(array $params = []): ResponseAccess */ public function createWebhook(array $payload): ResponseAccess { - $query = ' - mutation webhookSubscriptionCreate( - $topic: WebhookSubscriptionTopic!, - $webhookSubscription: WebhookSubscriptionInput! - ) { - webhookSubscriptionCreate( - topic: $topic - webhookSubscription: $webhookSubscription - ) { - userErrors { - field + + $address_type = Util::getShopifyConfig('webhook_address_type'); + if($address_type === "arn"){ + $query = ' + mutation eventBridgeWebhookSubscriptionCreate($topic: WebhookSubscriptionTopic!, $webhookSubscription: EventBridgeWebhookSubscriptionInput!) { + eventBridgeWebhookSubscriptionCreate(topic: $topic, webhookSubscription: $webhookSubscription) { + userErrors { message - } - webhookSubscription { + } + webhookSubscription { id topic + } + } + } + '; + }else{ + $query = ' + mutation webhookSubscriptionCreate( + $topic: WebhookSubscriptionTopic!, + $webhookSubscription: WebhookSubscriptionInput! + ) { + webhookSubscriptionCreate( + topic: $topic + webhookSubscription: $webhookSubscription + ) { + userErrors { + field + message + } + webhookSubscription { + id + topic + } } } + '; } - '; // Change REST-format topics ("resource/event") // to GraphQL-format topics ("RESOURCE_EVENT"), for pre-v17 compatibility @@ -393,13 +411,12 @@ public function createWebhook(array $payload): ResponseAccess $variables = [ 'topic' => $topic, 'webhookSubscription' => [ - 'callbackUrl' => $payload['address'], + $address_type => $payload['address'], 'format' => 'JSON', ], ]; $response = $this->doRequestGraphQL($query, $variables); - return $response['body']; } diff --git a/src/resources/config/shopify-app.php b/src/resources/config/shopify-app.php index 13338313..32b4ec77 100644 --- a/src/resources/config/shopify-app.php +++ b/src/resources/config/shopify-app.php @@ -326,6 +326,22 @@ 'billing_redirect' => env('SHOPIFY_BILLING_REDIRECT', '/billing/process'), + /* + |-------------------------------------------------------------------------- + | Shopify Webhooks Address Type + |-------------------------------------------------------------------------- + | + | This option is for defining webhooks type. + | `callbackUrl` it's use https:// route. + | `arn` it's use arn route. + | + | This documentation will helps you + | https://shopify.dev/apps/webhooks/configuration/eventbridge + | + */ + + 'webhook_address_type' => env('SHOPIFY_WEBHOOK_ADDRESS_TYPE', 'arn'), + /* |-------------------------------------------------------------------------- | Shopify Webhooks From 5184241e7432fa5a9a11ef2239b321c3c47ed1ce Mon Sep 17 00:00:00 2001 From: vishal gohil Date: Sat, 2 Apr 2022 12:55:58 +0530 Subject: [PATCH 2/6] minor fix --- src/Services/ApiHelper.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Services/ApiHelper.php b/src/Services/ApiHelper.php index 55a64589..0dcc32f8 100644 --- a/src/Services/ApiHelper.php +++ b/src/Services/ApiHelper.php @@ -366,13 +366,13 @@ public function getWebhooks(array $params = []): ResponseAccess */ public function createWebhook(array $payload): ResponseAccess { - - $address_type = Util::getShopifyConfig('webhook_address_type'); - if($address_type === "arn"){ + $addressType = Util::getShopifyConfig('webhook_address_type'); + if($addressType === "arn"){ $query = ' mutation eventBridgeWebhookSubscriptionCreate($topic: WebhookSubscriptionTopic!, $webhookSubscription: EventBridgeWebhookSubscriptionInput!) { eventBridgeWebhookSubscriptionCreate(topic: $topic, webhookSubscription: $webhookSubscription) { userErrors { + field message } webhookSubscription { @@ -411,12 +411,13 @@ public function createWebhook(array $payload): ResponseAccess $variables = [ 'topic' => $topic, 'webhookSubscription' => [ - $address_type => $payload['address'], + $addressType => $payload['address'], 'format' => 'JSON', ], ]; $response = $this->doRequestGraphQL($query, $variables); + return $response['body']; } From 2b94b085a44da14923a26744669b3a2dbbc99f8a Mon Sep 17 00:00:00 2001 From: vishal Date: Sat, 9 Apr 2022 16:21:48 +0530 Subject: [PATCH 3/6] Update shopify-app.php Change default value to `callbackUrl` for webhook_address_type --- src/resources/config/shopify-app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/config/shopify-app.php b/src/resources/config/shopify-app.php index 32b4ec77..d0dd6200 100644 --- a/src/resources/config/shopify-app.php +++ b/src/resources/config/shopify-app.php @@ -340,7 +340,7 @@ | */ - 'webhook_address_type' => env('SHOPIFY_WEBHOOK_ADDRESS_TYPE', 'arn'), + 'webhook_address_type' => env('SHOPIFY_WEBHOOK_ADDRESS_TYPE', 'callbackUrl'), /* |-------------------------------------------------------------------------- From 1edf3640c601e500a00f25e9a6dc94d5a0a29f86 Mon Sep 17 00:00:00 2001 From: vishal Date: Tue, 12 Apr 2022 23:47:13 +0530 Subject: [PATCH 4/6] Update ApiHelper.php format the code --- src/Services/ApiHelper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Services/ApiHelper.php b/src/Services/ApiHelper.php index 0dcc32f8..5e000275 100644 --- a/src/Services/ApiHelper.php +++ b/src/Services/ApiHelper.php @@ -367,7 +367,7 @@ public function getWebhooks(array $params = []): ResponseAccess public function createWebhook(array $payload): ResponseAccess { $addressType = Util::getShopifyConfig('webhook_address_type'); - if($addressType === "arn"){ + if ($addressType === "arn") { $query = ' mutation eventBridgeWebhookSubscriptionCreate($topic: WebhookSubscriptionTopic!, $webhookSubscription: EventBridgeWebhookSubscriptionInput!) { eventBridgeWebhookSubscriptionCreate(topic: $topic, webhookSubscription: $webhookSubscription) { @@ -382,7 +382,7 @@ public function createWebhook(array $payload): ResponseAccess } } '; - }else{ + } else { $query = ' mutation webhookSubscriptionCreate( $topic: WebhookSubscriptionTopic!, From 58cd37c741a9957971ea0cb32fa994b65d4daac3 Mon Sep 17 00:00:00 2001 From: vishal Date: Tue, 12 Apr 2022 23:51:46 +0530 Subject: [PATCH 5/6] Update ApiHelper.php replace double quote with single quote --- src/Services/ApiHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/ApiHelper.php b/src/Services/ApiHelper.php index 5e000275..6f211203 100644 --- a/src/Services/ApiHelper.php +++ b/src/Services/ApiHelper.php @@ -367,7 +367,7 @@ public function getWebhooks(array $params = []): ResponseAccess public function createWebhook(array $payload): ResponseAccess { $addressType = Util::getShopifyConfig('webhook_address_type'); - if ($addressType === "arn") { + if ($addressType === 'arn') { $query = ' mutation eventBridgeWebhookSubscriptionCreate($topic: WebhookSubscriptionTopic!, $webhookSubscription: EventBridgeWebhookSubscriptionInput!) { eventBridgeWebhookSubscriptionCreate(topic: $topic, webhookSubscription: $webhookSubscription) { From c91c3d6be69934aa1d4b3bf4209573615068daa0 Mon Sep 17 00:00:00 2001 From: vishal Date: Thu, 28 Apr 2022 20:17:08 +0530 Subject: [PATCH 6/6] Update ApiHelper.php Fix spacing issue --- src/Services/ApiHelper.php | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/Services/ApiHelper.php b/src/Services/ApiHelper.php index 6f211203..300b0130 100644 --- a/src/Services/ApiHelper.php +++ b/src/Services/ApiHelper.php @@ -369,19 +369,25 @@ public function createWebhook(array $payload): ResponseAccess $addressType = Util::getShopifyConfig('webhook_address_type'); if ($addressType === 'arn') { $query = ' - mutation eventBridgeWebhookSubscriptionCreate($topic: WebhookSubscriptionTopic!, $webhookSubscription: EventBridgeWebhookSubscriptionInput!) { - eventBridgeWebhookSubscriptionCreate(topic: $topic, webhookSubscription: $webhookSubscription) { - userErrors { - field - message - } - webhookSubscription { - id - topic - } + mutation eventBridgeWebhookSubscriptionCreate( + $topic: WebhookSubscriptionTopic!, + $webhookSubscription: EventBridgeWebhookSubscriptionInput! + ) { + eventBridgeWebhookSubscriptionCreate( + topic: $topic, + webhookSubscription: $webhookSubscription + ) { + userErrors { + field + message + } + webhookSubscription { + id + topic + } } - } - '; + } + '; } else { $query = ' mutation webhookSubscriptionCreate(