Codeunit 30363 Shpfy Webhook Notification
src/Apps/W1/Shopify/App/src/Webhooks/Codeunits/ShpfyWebhookNotification.Codeunit.al68 lines, Copyright (c) Microsoft Corporation. MIT
// ------------------------------------------------------------------------------------------------// Copyright (c) Microsoft Corporation. All rights reserved.// Licensed under the MIT License. See License.txt in the project root for license information.// ------------------------------------------------------------------------------------------------namespace Microsoft.Integration.Shopify;using System.Integration;using System.Telemetry;codeunit 30363 "Shpfy Webhook Notification"{ TableNo = "Webhook Notification"; trigger OnRun() begin HandleOnShopifyWebhookNotificationInsert(Rec); end; var ShopNotFoundTxt: Label 'Shop is not found in company %1.', Comment = '%1 = Company name', Locked = true; ProcessingNotificationTxt: Label 'Processing notification in company %1.', Comment = '%1 = Company name', Locked = true; CategoryTok: Label 'Shopify Integration', Locked = true; local procedure HandleOnShopifyWebhookNotificationInsert(var WebhookNotification: Record "Webhook Notification") var Shop: Record "Shpfy Shop"; FeatureTelemetry: Codeunit "Feature Telemetry"; WebhooksMgt: Codeunit "Shpfy Webhooks Mgt."; begin Shop.SetRange(Enabled, true); Shop.SetRange("Shopify URL", GetShopUrl(WebhookNotification."Subscription ID")); if Shop.IsEmpty() then begin Shop.SetRange("Shopify URL", GetShopUrl(WebhookNotification."Subscription ID").TrimEnd('/')); if Shop.IsEmpty() then begin Session.LogMessage('0000K8I', StrSubstNo(ShopNotFoundTxt, CompanyName), Verbosity::Normal, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', CategoryTok); exit; end; end; Session.LogMessage('0000K8J', StrSubstNo(ProcessingNotificationTxt, CompanyName), Verbosity::Normal, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', CategoryTok); if Shop.FindSet() then repeat case WebhookNotification."Resource Type Name" of Format("Shpfy Webhook Topic"::ORDERS_CREATE): if Shop."Order Created Webhooks" then begin FeatureTelemetry.LogUptake('0000K8D', 'Shopify Webhooks', Enum::"Feature Uptake Status"::Used); FeatureTelemetry.LogUsage('0000K8F', 'Shopify Webhooks', 'Shopify sales order webhooks enabled.'); WebhooksMgt.ProcessOrderCreatedNotification(Shop); Commit(); end else Session.LogMessage('0000KUD', StrSubstNo(ShopNotFoundTxt, CompanyName), Verbosity::Normal, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', CategoryTok); Format("Shpfy Webhook Topic"::BULK_OPERATIONS_FINISH): begin WebhooksMgt.ProcessBulkOperationNotification(Shop, WebhookNotification); Commit(); end; end; until Shop.Next() = 0; end; local procedure GetShopUrl(ShopDomain: Text): Text begin exit('https://' + ShopDomain + '.myshopify.com/'); end;}