diff --git a/src/Services/ApiHelper.php b/src/Services/ApiHelper.php index 3ef65ee9..300b0130 100644 --- a/src/Services/ApiHelper.php +++ b/src/Services/ApiHelper.php @@ -366,26 +366,50 @@ public function getWebhooks(array $params = []): ResponseAccess */ public function createWebhook(array $payload): ResponseAccess { - $query = ' - mutation webhookSubscriptionCreate( - $topic: WebhookSubscriptionTopic!, - $webhookSubscription: WebhookSubscriptionInput! - ) { - webhookSubscriptionCreate( - topic: $topic - webhookSubscription: $webhookSubscription + $addressType = Util::getShopifyConfig('webhook_address_type'); + if ($addressType === 'arn') { + $query = ' + mutation eventBridgeWebhookSubscriptionCreate( + $topic: WebhookSubscriptionTopic!, + $webhookSubscription: EventBridgeWebhookSubscriptionInput! ) { - userErrors { - field - message + eventBridgeWebhookSubscriptionCreate( + topic: $topic, + webhookSubscription: $webhookSubscription + ) { + userErrors { + field + message + } + webhookSubscription { + id + topic + } } - 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,7 +417,7 @@ public function createWebhook(array $payload): ResponseAccess $variables = [ 'topic' => $topic, 'webhookSubscription' => [ - 'callbackUrl' => $payload['address'], + $addressType => $payload['address'], 'format' => 'JSON', ], ]; diff --git a/src/resources/config/shopify-app.php b/src/resources/config/shopify-app.php index 13338313..d0dd6200 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', 'callbackUrl'), + /* |-------------------------------------------------------------------------- | Shopify Webhooks