From d70b100f2420a3384c40c426abd23f9c9b5201bb Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Mon, 16 Sep 2024 10:01:01 +0200 Subject: [PATCH 01/31] EDocument Connector SignUp --- .../EDocConnectorEdit.PermissionSet.al | 4 +- .../EDocConnectorObjects.PermissionSet.al | 3 + .../EDocConnectorRead.PermissionSet.al | 4 +- .../app/src/SignUp/APIRequests.Codeunit.al | 224 +++++++ .../app/src/SignUp/Auth.Codeunit.al | 327 ++++++++++ .../app/src/SignUp/Connection.Codeunit.al | 105 ++++ .../app/src/SignUp/ConnectionAuth.Table.al | 57 ++ .../app/src/SignUp/ConnectionSetup.Table.al | 104 ++++ .../src/SignUp/ConnectionSetupCard.Page.al | 202 ++++++ .../app/src/SignUp/ErrorSensitive.Codeunit.al | 54 ++ .../app/src/SignUp/GetReadyStatus.Codeunit.al | 134 ++++ .../app/src/SignUp/Helpers.Codeunit.al | 63 ++ .../src/SignUp/IntegrationEnumExt.EnumExt.al | 16 + .../src/SignUp/IntegrationImpl.Codeunit.al | 59 ++ .../app/src/SignUp/PatchSent.Codeunit.al | 81 +++ .../app/src/SignUp/Processing.Codeunit.al | 573 ++++++++++++++++++ .../app/src/SignUp/SendMode.Enum.al | 19 + 17 files changed, 2027 insertions(+), 2 deletions(-) create mode 100644 Apps/W1/EDocumentsConnector/app/src/SignUp/APIRequests.Codeunit.al create mode 100644 Apps/W1/EDocumentsConnector/app/src/SignUp/Auth.Codeunit.al create mode 100644 Apps/W1/EDocumentsConnector/app/src/SignUp/Connection.Codeunit.al create mode 100644 Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionAuth.Table.al create mode 100644 Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetup.Table.al create mode 100644 Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al create mode 100644 Apps/W1/EDocumentsConnector/app/src/SignUp/ErrorSensitive.Codeunit.al create mode 100644 Apps/W1/EDocumentsConnector/app/src/SignUp/GetReadyStatus.Codeunit.al create mode 100644 Apps/W1/EDocumentsConnector/app/src/SignUp/Helpers.Codeunit.al create mode 100644 Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationEnumExt.EnumExt.al create mode 100644 Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationImpl.Codeunit.al create mode 100644 Apps/W1/EDocumentsConnector/app/src/SignUp/PatchSent.Codeunit.al create mode 100644 Apps/W1/EDocumentsConnector/app/src/SignUp/Processing.Codeunit.al create mode 100644 Apps/W1/EDocumentsConnector/app/src/SignUp/SendMode.Enum.al diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorEdit.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorEdit.PermissionSet.al index 88f0f656e6..b5d9dfe957 100644 --- a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorEdit.PermissionSet.al +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorEdit.PermissionSet.al @@ -11,5 +11,7 @@ permissionset 6361 "EDocConnector - Edit" IncludedPermissionSets = "EDocConnector - Read"; Permissions = tabledata "E-Doc. Ext. Connection Setup" = IM, - tabledata Microsoft.EServices.EDocumentConnector.Avalara."Connection Setup" = imd; + tabledata Microsoft.EServices.EDocumentConnector.Avalara."Connection Setup" = imd + tabledata SignUpConnectionSetup = IM, + tabledata SignUpConnectionAuth = IM; } \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorObjects.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorObjects.PermissionSet.al index f5fb6cb8e0..39a8d6e2b3 100644 --- a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorObjects.PermissionSet.al +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorObjects.PermissionSet.al @@ -10,7 +10,10 @@ permissionset 6363 "EDoc. Connector Objects" Assignable = false; Permissions = table "E-Doc. Ext. Connection Setup" = X, + table SignUpConnectionSetup = X, + table SignUpConnectionAuth = X, page "EDoc Ext Connection Setup Card" = X, + page SignUpConnectionSetupCard = X, codeunit "Pagero API Requests" = X, codeunit "Pagero Auth." = X, codeunit "Pagero Connection" = X, diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al index 07be9b89a6..1edcfb769e 100644 --- a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al @@ -11,5 +11,7 @@ permissionset 6362 "EDocConnector - Read" IncludedPermissionSets = "EDoc. Connector Objects"; Permissions = tabledata "E-Doc. Ext. Connection Setup" = R, - tabledata Microsoft.EServices.EDocumentConnector.Avalara."Connection Setup" = r; + tabledata Microsoft.EServices.EDocumentConnector.Avalara."Connection Setup" = r + tabledata SignUpConnectionSetup = R, + tabledata SignUpConnectionAuth = R; } \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/APIRequests.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/APIRequests.Codeunit.al new file mode 100644 index 0000000000..9081d37ac2 --- /dev/null +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/APIRequests.Codeunit.al @@ -0,0 +1,224 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.EServices.EDocumentConnector.SignUp; + +using Microsoft.EServices.EDocument; +using Microsoft.Foundation.Company; +using Microsoft.Sales.Customer; +using System.Security.Authentication; +using System.Text; +using System.Utilities; +using System.Xml; + +codeunit 6370 SignUpAPIRequests +{ + Access = Internal; + + // https:///api/Peppol + procedure SendFilePostRequest(var TempBlob: Codeunit "Temp Blob"; EDocument: Record "E-Document"; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean + var + SignUpConnectionSetup: Record SignUpConnectionSetup; + Payload: Text; + ContentHttpHeaders: HttpHeaders; + HttpContent: HttpContent; + ContentText: Text; + UriTemplateLbl: Label '%1/api/Peppol', Comment = '%1 = Service Url', Locked = true; + begin + InitRequest(SignUpConnectionSetup, HttpRequestMessage, HttpResponseMessage); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::POST, StrSubstNo(UriTemplateLbl, SignUpConnectionSetup.ServiceURL)); + + Payload := XmlToTxt(TempBlob); + if Payload = '' then + exit(false); + Clear(HttpContent); + ContentText := PrepareContentForSend(GetDocumentType(EDocument), SignUpConnectionSetup."Company Id", GetCustomerID(EDocument), GetSenderCountryCode(), Payload, SignUpConnectionSetup."Send Mode"); + HttpContent.WriteFrom(ContentText); + HttpContent.GetHeaders(ContentHttpHeaders); + if ContentHttpHeaders.Contains('Content-Type') then + ContentHttpHeaders.Remove('Content-Type'); + ContentHttpHeaders.Add('Content-Type', 'application/json'); + HttpRequestMessage.Content(HttpContent); + + exit(SendRequest(HttpRequestMessage, HttpResponseMessage)); + end; + + // https:///api/Peppol/status?peppolInstanceId= + procedure GetSentDocumentStatus(EDocument: Record "E-Document"; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean + var + SignUpConnectionSetup: Record SignUpConnectionSetup; + UriTemplateLbl: Label '%1/api/Peppol/status?peppolInstanceId=%2', Comment = '%1 = Service Url, %2 = Document ID', Locked = true; + begin + InitRequest(SignUpConnectionSetup, HttpRequestMessage, HttpResponseMessage); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::GET, StrSubstNo(UriTemplateLbl, SignUpConnectionSetup.ServiceURL, EDocument."Document Id")); + exit(SendRequest(HttpRequestMessage, HttpResponseMessage)); + end; + + // https:///api/Peppol/outbox?peppolInstanceId= + procedure PatchADocument(EDocument: Record "E-Document"; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean + var + SignUpConnectionSetup: Record SignUpConnectionSetup; + UriTemplateLbl: Label '%1/api/Peppol/outbox?peppolInstanceId=%2', Comment = '%1 = Service Url, %2 = Document ID', Locked = true; + begin + InitRequest(SignUpConnectionSetup, HttpRequestMessage, HttpResponseMessage); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::PATCH, StrSubstNo(UriTemplateLbl, SignUpConnectionSetup.ServiceURL, EDocument."Document Id")); + exit(SendRequest(HttpRequestMessage, HttpResponseMessage)); + end; + + // https:///api/Peppol/Inbox?peppolId= + procedure GetReceivedDocumentsRequest(var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage; Parameters: Dictionary of [Text, Text]): Boolean + var + SignUpConnectionSetup: Record SignUpConnectionSetup; + UriTemplateLbl: Label '%1/api/Peppol/Inbox?peppolId=%2', Comment = '%1 = Service Url, %2 = Peppol Identifier', Locked = true; + begin + InitRequest(SignUpConnectionSetup, HttpRequestMessage, HttpResponseMessage); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::GET, StrSubstNo(UriTemplateLbl, SignUpConnectionSetup.ServiceURL, GetSenderReceiverPrefix() + SignUpConnectionSetup."Company Id")); + exit(SendRequest(HttpRequestMessage, HttpResponseMessage)); + end; + + // https:///api/Peppol/inbox-document?peppolId= + procedure GetTargetDocumentRequest(DocumentId: Text; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean + var + SignUpConnectionSetup: Record SignUpConnectionSetup; + UriTemplateLbl: Label '%1/api/Peppol/inbox-document?peppolId=%2&peppolInstanceId=%3', Comment = '%1 = Service Url, %2 = Peppol Identifier, %3 = Peppol Gateway Instance', Locked = true; + begin + InitRequest(SignUpConnectionSetup, HttpRequestMessage, HttpResponseMessage); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::GET, StrSubstNo(UriTemplateLbl, SignUpConnectionSetup.ServiceURL, GetSenderReceiverPrefix() + SignUpConnectionSetup."Company Id", DocumentId)); + exit(SendRequest(HttpRequestMessage, HttpResponseMessage)); + end; + + // https:///api/Peppol/inbox?peppolInstanceId= + procedure PatchReceivedDocument(EDocument: Record "E-Document"; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean + var + SignUpConnectionSetup: Record SignUpConnectionSetup; + UriTemplateLbl: Label '%1/api/Peppol/inbox?peppolInstanceId=%2', Comment = '%1 = Service Url, %2 = Peppol Gateway Instance', Locked = true; + begin + InitRequest(SignUpConnectionSetup, HttpRequestMessage, HttpResponseMessage); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::PATCH, StrSubstNo(UriTemplateLbl, SignUpConnectionSetup.ServiceURL, EDocument."Document Id")); + exit(SendRequest(HttpRequestMessage, HttpResponseMessage)); + end; + + procedure GetMarketPlaceCredentials(var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean + var + SignUpConnectionSetup: Record SignUpConnectionSetup; + SignUpAuth: Codeunit SignUpAuth; + BaseUrlTxt: Label '%1/api/Registration/init?EntraTenantId=%2', Locked = true; + begin + InitRequest(SignUpConnectionSetup, HttpRequestMessage, HttpResponseMessage); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::POST, StrSubstNo(BaseUrlTxt, SignUpAuth.GetRootUrl(), SignUpAuth.GetBCInstanceIdentifier())); + exit(SendRequest(HttpRequestMessage, HttpResponseMessage, true)); + end; + + local procedure InitRequest(var SignUpConnectionSetup: Record SignUpConnectionSetup; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage) + begin + Clear(HttpRequestMessage); + Clear(HttpResponseMessage); + if not SignUpConnectionSetup.Get() then + Error(MissingSetupErr); + end; + + local procedure SendRequest(HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean + begin + SendRequest(HttpRequestMessage, HttpResponseMessage, false); + end; + + local procedure SendRequest(HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage; RootReequest: Boolean): Boolean + var + SignUpAuth: Codeunit SignUpAuth; + HttpClient: HttpClient; + HttpHeaders: HttpHeaders; + begin + HttpRequestMessage.GetHeaders(HttpHeaders); + if RootReequest then + HttpHeaders.Add('Authorization', SignUpAuth.GetRootBearerAuthText()) + else + HttpHeaders.Add('Authorization', SignUpAuth.GetBearerAuthText()); + exit(HttpClient.Send(HttpRequestMessage, HttpResponseMessage)); + end; + + local procedure PrepareRequestMsg(pHttpRequestType: Enum "Http Request Type"; Uri: Text) RequestMessage: HttpRequestMessage + var + Headers: HttpHeaders; + begin + RequestMessage.Method(Format(pHttpRequestType)); + RequestMessage.SetRequestUri(Uri); + RequestMessage.GetHeaders(Headers); + Headers.Add('Accept', '*/*'); + end; + + local procedure XmlToTxt(var TempBlob: Codeunit "Temp Blob"): Text + var + XMLDOMManagement: Codeunit "XML DOM Management"; + InStr: InStream; + Content: Text; + begin + TempBlob.CreateInStream(InStr, TextEncoding::UTF8); + XMLDOMManagement.TryGetXMLAsText(InStr, Content); + exit(Content); + end; + + local procedure GetDocumentType(EDocument: Record "E-Document"): Text + begin + if EDocument.Direction = EDocument.Direction::Incoming then + exit('ApplicationResponse'); + + case EDocument."Document Type" of + "E-Document Type"::"Sales Invoice", "E-Document Type"::"Sales Credit Memo", "E-Document Type"::"Service Invoice", "E-Document Type"::"Service Credit Memo": + exit('Invoice'); + "E-Document Type"::"Issued Finance Charge Memo", "E-Document Type"::"Issued Reminder": + exit('PaymentReminder'); + end; + end; + + local procedure GetCustomerID(EDocument: Record "E-Document"): Text[50] + var + Customer: Record Customer; + begin + if EDocument.Direction <> EDocument.Direction::Outgoing then + exit(''); + + Customer.Get(EDocument."Bill-to/Pay-to No."); + Customer.TestField("Service Participant Id"); + exit(Customer."Service Participant Id"); + end; + + local procedure GetSenderCountryCode(): Text + var + CompanyInformation: Record "Company Information"; + begin + CompanyInformation.Get(); + CompanyInformation.TestField("Country/Region Code"); + exit(CompanyInformation."Country/Region Code"); + end; + + local procedure PrepareContentForSend(DocumentType: Text; SendingCompanyID: Text; RecieverCompanyID: Text; SenderCountryCode: Text; Payload: Text; SendMode: Enum SignUpSendMode): Text + var + Base64Convert: Codeunit "Base64 Convert"; + SendJsonObject: JsonObject; + ContentText: Text; + begin + SendJsonObject.Add('documentType', DocumentType); + SendJsonObject.Add('receiver', GetSenderReceiverPrefix() + RecieverCompanyID); + SendJsonObject.Add('sender', GetSenderReceiverPrefix() + SendingCompanyID); + SendJsonObject.Add('senderCountryCode', SenderCountryCode); + SendJsonObject.Add('documentId', 'urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0::2.1'); + SendJsonObject.Add('documentIdScheme', 'busdox-docid-qns'); + SendJsonObject.Add('processId', 'urn:fdc:peppol.eu:2017:poacc:billing:01:1.0'); + SendJsonObject.Add('processIdScheme', 'cenbii-procid-ubl'); + SendJsonObject.Add('sendMode', Format(SendMode)); + SendJsonObject.Add('document', Base64Convert.ToBase64(Payload)); + SendJsonObject.WriteTo(ContentText); + exit(ContentText); + end; + + local procedure GetSenderReceiverPrefix(): Text + var + SenderReceiverPrefixLbl: Label 'iso6523-actorid-upis::', Locked = true; + begin + exit(SenderReceiverPrefixLbl); + end; + + var + MissingSetupErr: Label 'You must set up service integration in the E-Document service card.'; +} \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/Auth.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/Auth.Codeunit.al new file mode 100644 index 0000000000..401818638d --- /dev/null +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/Auth.Codeunit.al @@ -0,0 +1,327 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.EServices.EDocumentConnector.SignUp; + +using System.Azure.KeyVault; +using Microsoft.Sales.Customer; +using System.Environment; +using System.Reflection; + +codeunit 6371 SignUpAuth +{ + Access = Internal; + + procedure InitConnectionSetup() + var + lSignUpConnectionSetup: Record SignUpConnectionSetup; + begin + if lSignUpConnectionSetup.Get() then + exit; + lSignUpConnectionSetup."Authentication URL" := AuthURLTxt; + lSignUpConnectionSetup.ServiceURL := ProdServiceAPITxt; + StorageSet(lSignUpConnectionSetup."Client Tenant", ProdTenantIdTxt); + lSignUpConnectionSetup.Insert(); + end; + + procedure GetRootOnboardingUrl(): Text + var + UrlTxt: Label '%1/supm/landingpage?EntraTenantId=%2', Comment = '%1 = Root Market URL, %2 = BC Instance Identifier', Locked = true; + begin + exit(StrSubstNo(UrlTxt, GetRootUrl(), GetBCInstanceIdentifier())); + end; + + [NonDebuggable] + procedure CreateClientCredentials() + var + HttpRequestMessage: HttpRequestMessage; + HttpResponseMessage: HttpResponseMessage; + JText: Text; + ClientId: Text; + ClientSecret: SecretText; + ErrorUnableToCreateClientCredentialsLbl: Label 'Unable to create client credentials.'; + begin + if not GetClientCredentials(HttpRequestMessage, HttpResponseMessage) then + Error(ErrorUnableToCreateClientCredentialsLbl); + if HttpResponseMessage.Content.ReadAs(JText) then begin + ClientId := SignUpHelpers.GetJsonValueFromText(JText, 'clientId'); + ClientSecret := SignUpHelpers.GetJsonValueFromText(JText, 'clientSecret'); + if (ClientId <> '') and (not ClientSecret.IsEmpty()) then + SaveClientCredentials(ClientId, ClientSecret); + end; + end; + + [NonDebuggable] + local procedure GetClientCredentials(var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean + var + SignUpSignUpAPIRequests: Codeunit SignUpAPIRequests; + begin + SignUpSignUpAPIRequests.GetMarketPlaceCredentials(HttpRequest, HttpResponse); + if not HttpResponse.IsSuccessStatusCode then + exit(false); + exit(SignUpHelpers.ParseJsonString(HttpResponse.Content) <> ''); + end; + + procedure GetBearerAuthText(): SecretText; + begin + exit(secretStrSubstNo(BearerTxt, GetAuthBearerToken())); + end; + + procedure GetRootBearerAuthText(): SecretText; + begin + exit(secretStrSubstNo(BearerTxt, GetRootAuthBearerToken())); + end; + + procedure GetAuthBearerToken(): SecretText; + var + SignUpConnectionAuth: Record SignUpConnectionAuth; + HttpError: Text; + begin + SignUpConnectionAuth.GetRecordOnce(); + if SignUpConnectionAuth."Token Timestamp" < CurrentDateTime() + 60 * 1000 then + if not RefreshAccessToken(HttpError) then + Error(HttpError); + + exit(StorageGet(SignUpConnectionAuth."Access Token", DataScope::Company)); + end; + + procedure GetRootAuthBearerToken() ReturnValue: SecretText; + var + ErrorTokenLbl: Label 'Unable to fetch a root token.'; + begin + if not GetRootAccessToken(ReturnValue) then + Error(ErrorTokenLbl); + end; + + [NonDebuggable] + local procedure RefreshAccessToken(var HttpError: Text): Boolean; + var + SignUpConnectionAuth: Record SignUpConnectionAuth; + SecretToken: SecretText; + RefreshToken: SecretText; + begin + SignUpConnectionAuth.GetRecordOnce(); + if not GetClientAccessToken(SecretToken) then begin + HttpError := GetLastErrorText(); + exit(false); + end; + SignUpConnectionAuth."Token Timestamp" := CurrentDateTime(); + SaveTokens(SignUpConnectionAuth, DataScope::Company, SecretToken, RefreshToken); + SignUpConnectionAuth.Modify(); + exit(true); + end; + + [NonDebuggable] + local procedure GetRootAccessToken(var AccessToken: SecretText): Boolean + begin + exit(GetAccessToken(AccessToken, GetRootId(), GetRootSecret(), GetRootTenant())); + end; + + [NonDebuggable] + local procedure GetClientAccessToken(var AccessToken: SecretText): Boolean + begin + SignUpConnectionSetup.GetRecordOnce(); + exit(GetAccessToken( + AccessToken, + StorageGetText(SignUpConnectionSetup."Client ID", DataScope::Module), + StorageGet(SignUpConnectionSetup."Client Secret", DataScope::Module), + StorageGetText(SignUpConnectionSetup."Client Tenant", DataScope::Module))); + end; + + [NonDebuggable] + local procedure GetAccessToken(var AccessToken: SecretText; ClientId: Text; ClientSecret: SecretText; ClientTenant: Text): Boolean + var + TypeHelper: Codeunit "Type Helper"; + HttpClient: HttpClient; + HttpRequestMessage: HttpRequestMessage; + HttpResponseMessage: HttpResponseMessage; + HttpContent: HttpContent; + HttpHeaders: HttpHeaders; + ContentText: SecretText; + ContentTemplateTxt: Label 'grant_type=client_credentials&client_id=%1&client_secret=%2&resource=%3', Locked = true; + JText: Text; + begin + SignUpConnectionSetup.GetRecordOnce(); + SignUpConnectionSetup.TestField("Authentication URL"); + + ContentText := SecretStrSubstNo(ContentTemplateTxt, TypeHelper.UriEscapeDataString(ClientId), ClientSecret, TypeHelper.UriEscapeDataString(ClientId)); + + HttpContent.WriteFrom(ContentText); + + HttpContent.GetHeaders(HttpHeaders); + HttpHeaders.Remove('Content-Type'); + HttpHeaders.Add('Content-Type', 'application/x-www-form-urlencoded'); + + HttpRequestMessage.Method := 'POST'; + HttpRequestMessage.SetRequestUri(StrSubstNo(SignUpConnectionSetup."Authentication URL", ClientTenant)); + HttpRequestMessage.Content(HttpContent); + + Clear(AccessToken); + if HttpClient.Send(HttpRequestMessage, HttpResponseMessage) then + if HttpResponseMessage.IsSuccessStatusCode() then + if HttpResponseMessage.Content.ReadAs(JText) then + AccessToken := SignUpHelpers.GetJsonValueFromText(JText, 'access_token'); + exit(not AccessToken.IsEmpty()); + end; + + local procedure SaveTokens(var SignUpConnectionAuth: Record SignUpConnectionAuth; TokenDataScope: DataScope; AccessToken: SecretText; RefreshToken: SecretText) + begin + StorageSet(SignUpConnectionAuth."Access Token", AccessToken, TokenDataScope); + StorageSet(SignUpConnectionAuth."Refresh Token", RefreshToken, TokenDataScope); + end; + + procedure SaveClientCredentials(ClientId: Text; ClientSecret: SecretText) + begin + Clear(SignUpConnectionSetup); + SignUpConnectionSetup.GetRecordOnce(); + StorageSet(SignUpConnectionSetup."Client ID", ClientId); + StorageSet(SignUpConnectionSetup."Client Secret", ClientSecret); + SignUpConnectionSetup.Modify(); + Clear(SignUpConnectionSetup); + end; + + local procedure StorageGet(TokenKey: Text; TokenDataScope: DataScope) TokenValueAsSecret: SecretText + begin + if not StorageContains(TokenKey, TokenDataScope) then + exit(TokenValueAsSecret); + + IsolatedStorage.Get(TokenKey, TokenDataScope, TokenValueAsSecret); + end; + + [NonDebuggable] + local procedure StorageGetText(TokenKey: Text; TokenDataScope: DataScope) TokenValue: Text + begin + if not StorageContains(TokenKey, TokenDataScope) then + exit(TokenValue); + + IsolatedStorage.Get(TokenKey, TokenDataScope, TokenValue); + end; + + local procedure StorageContains(TokenKey: Text; TokenDataScope: DataScope): Boolean + begin + exit(IsolatedStorage.Contains(TokenKey, TokenDataScope)); + end; + + [NonDebuggable] + procedure StorageSet(var TokenKey: Guid; Value: Text) + begin + ValidateValueKey(TokenKey); + if Value = '' then begin + if IsolatedStorage.Contains(TokenKey, DataScope::Module) then + IsolatedStorage.Delete(TokenKey, DataScope::Module) + end else + IsolatedStorage.Set(TokenKey, Value, DataScope::Module); + end; + + procedure StorageSet(var TokenKey: Guid; Value: SecretText) + begin + ValidateValueKey(TokenKey); + if Value.IsEmpty() then begin + if IsolatedStorage.Contains(TokenKey, DataScope::Module) then + IsolatedStorage.Delete(TokenKey, DataScope::Module) + end else + IsolatedStorage.Set(TokenKey, Value, DataScope::Module); + end; + + procedure StorageSet(var TokenKey: Guid; Value: SecretText; TokenDataScope: DataScope) + begin + ValidateValueKey(TokenKey); + if Value.IsEmpty() then begin + if IsolatedStorage.Contains(TokenKey, TokenDataScope) then + IsolatedStorage.Delete(TokenKey, TokenDataScope) + end else + IsolatedStorage.Set(TokenKey, Value, TokenDataScope); + end; + + local procedure ValidateValueKey(var ValueKey: Guid) + begin + if IsNullGuid(ValueKey) then + ValueKey := CreateGuid(); + end; + + [NonDebuggable] + local procedure GetRootId() ReturnValue: Text + begin + if FetchSecretFromKeyVault('signup-root-id', ReturnValue) then + exit; + if SignUpConnectionSetup.GetRecordOnce() then begin + SignUpConnectionSetup.TestField("Root App ID"); + ReturnValue := StorageGetText(SignUpConnectionSetup."Root App ID", DataScope::Module); + end; + end; + + [NonDebuggable] + local procedure GetRootSecret() ReturnValue: Text + begin + if FetchSecretFromKeyVault('signup-root-secret', ReturnValue) then + exit; + if SignUpConnectionSetup.GetRecordOnce() then begin + SignUpConnectionSetup.TestField("Root Secret"); + ReturnValue := StorageGetText(SignUpConnectionSetup."Root Secret", DataScope::Module); + end; + end; + + [NonDebuggable] + local procedure GetRootTenant() ReturnValue: Text + begin + if FetchSecretFromKeyVault('signup-root-tenant', ReturnValue) then + exit; + if SignUpConnectionSetup.GetRecordOnce() then begin + SignUpConnectionSetup.TestField("Root Tenant"); + ReturnValue := StorageGetText(SignUpConnectionSetup."Root Tenant", DataScope::Module); + end; + end; + + [NonDebuggable] + procedure GetRootUrl() ReturnValue: Text + begin + if FetchSecretFromKeyVault('signup-root-url', ReturnValue) then + exit; + if SignUpConnectionSetup.GetRecordOnce() then begin + SignUpConnectionSetup.TestField("Root Market URL"); + ReturnValue := StorageGetText(SignUpConnectionSetup."Root Market URL", DataScope::Module); + end; + end; + + [NonDebuggable] + local procedure FetchSecretFromKeyVault(KeyName: Text; var KeyValue: Text): Boolean + var + AzureKeyVault: Codeunit "Azure Key Vault"; + EnvironmentInfo: Codeunit "Environment Information"; + begin + if EnvironmentInfo.IsSaaSInfrastructure() then + exit(AzureKeyVault.GetAzureKeyVaultSecret(KeyName, KeyValue)); + end; + + procedure GetBCInstanceIdentifier() Identifier: Text + var + AADTenantID, AADDomainName : Text; + begin + Identifier := '10000000-d8ef-4dfb-b761-ffb073057794'; // Hardcoded fake during testing only + if GetAADTenantInformation(AADTenantID, AADDomainName) then + Identifier := AADTenantID; + end; + + local procedure GetAADTenantInformation(var AADTenantID: Text; var AADDomainName: Text): Boolean + var + SignUpSignUpErrorSensitive: Codeunit SignUpErrorSensitive; + begin + Clear(SignUpSignUpErrorSensitive); + SignUpSignUpErrorSensitive.SetParameter('AADDETAILS'); + Commit(); + if SignUpSignUpErrorSensitive.Run() then begin + AADTenantID := SignUpSignUpErrorSensitive.GetFirstResult(); + AADDomainName := SignUpSignUpErrorSensitive.GetSecondResult(); + exit(true); + end; + end; + + var + SignUpConnectionSetup: Record SignUpConnectionSetup; + SignUpHelpers: Codeunit SignUpHelpers; + BearerTxt: Label 'Bearer %1', Comment = '%1 = text value', Locked = true; + AuthURLTxt: Label 'https://login.microsoftonline.com/%1/oauth2/token', Comment = '%1 Entra Tenant Id', Locked = true; + ProdTenantIdTxt: Label '0d725623-dc26-484f-a090-b09d2003d092', Locked = true; + ProdServiceAPITxt: Label 'https://edoc.exflow.io', Locked = true; +} \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/Connection.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/Connection.Codeunit.al new file mode 100644 index 0000000000..46836c8e1d --- /dev/null +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/Connection.Codeunit.al @@ -0,0 +1,105 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.EServices.EDocumentConnector.SignUp; + +using Microsoft.EServices.EDocument; +using Microsoft.Purchases.Document; +using Microsoft.Purchases.Posting; +using System.Utilities; + +codeunit 6372 SignUpConnection +{ + Access = Internal; + Permissions = tabledata "E-Document" = m; + + procedure HandleSendFilePostRequest(var TempBlob: Codeunit "Temp Blob"; var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage; Retry: Boolean): Boolean + begin + if not SignUpAPIRequests.SendFilePostRequest(TempBlob, EDocument, HttpRequest, HttpResponse) then + if Retry then + SignUpAPIRequests.SendFilePostRequest(TempBlob, EDocument, HttpRequest, HttpResponse); + + exit(CheckIfSuccessfulRequest(EDocument, HttpResponse)); + end; + + procedure CheckDocumentStatus(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage; Retry: Boolean): Boolean + begin + if not SignUpAPIRequests.GetSentDocumentStatus(EDocument, HttpRequest, HttpResponse) then + if Retry then + SignUpAPIRequests.GetSentDocumentStatus(EDocument, HttpRequest, HttpResponse); + + exit(CheckIfSuccessfulRequest(EDocument, HttpResponse)); + end; + + procedure GetReceivedDocuments(var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage; Retry: Boolean): Boolean + var + Parameters: Dictionary of [Text, Text]; + begin + if not SignUpAPIRequests.GetReceivedDocumentsRequest(HttpRequest, HttpResponse, Parameters) then + if Retry then + SignUpAPIRequests.GetReceivedDocumentsRequest(HttpRequest, HttpResponse, Parameters); + + if not HttpResponse.IsSuccessStatusCode then + exit(false); + + exit(SignUpHelpers.ParseJsonString(HttpResponse.Content) <> ''); + end; + + procedure HandleGetTargetDocumentRequest(DocumentId: Text; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage; Retry: Boolean): Boolean + begin + if not SignUpAPIRequests.GetTargetDocumentRequest(DocumentId, HttpRequest, HttpResponse) then + if Retry then + SignUpAPIRequests.GetTargetDocumentRequest(DocumentId, HttpRequest, HttpResponse); + + exit(HttpResponse.IsSuccessStatusCode); + end; + + procedure RemoveDocumentFromReceived(EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage; Retry: Boolean): Boolean + begin + if not SignUpAPIRequests.PatchReceivedDocument(EDocument, HttpRequest, HttpResponse) then + if Retry then + SignUpAPIRequests.PatchReceivedDocument(EDocument, HttpRequest, HttpResponse); + exit(HttpResponse.IsSuccessStatusCode); + end; + + local procedure CheckIfSuccessfulRequest(EDocument: Record "E-Document"; HttpResponse: HttpResponseMessage): Boolean + var + EDocumentErrorHelper: Codeunit "E-Document Error Helper"; + begin + if HttpResponse.IsSuccessStatusCode then + exit(true); + + if HttpResponse.IsBlockedByEnvironment then + EDocumentErrorHelper.LogSimpleErrorMessage(EDocument, EnvironmentBlocksErr) + else + EDocumentErrorHelper.LogSimpleErrorMessage(EDocument, StrSubstNo(UnsuccessfulResponseErr, HttpResponse.HttpStatusCode, HttpResponse.ReasonPhrase)); + end; + + [EventSubscriber(ObjectType::Codeunit, Codeunit::"Purch.-Post", 'OnAfterCheckAndUpdate', '', false, false)] + local procedure CheckOnPosting(var PurchaseHeader: Record "Purchase Header"; CommitIsSuppressed: Boolean; PreviewMode: Boolean) + var + EDocument: Record "E-Document"; + EDocumentService: Record "E-Document Service"; + EDocumentServiceStatus: Record "E-Document Service Status"; + begin + EDocument.SetRange("Document Record ID", PurchaseHeader.RecordId); + if not EDocument.FindFirst() then + exit; + + EDocumentService.SetRange("Service Integration", EDocumentService."Service Integration"::"ExFlow E-Invoicing"); + if EDocumentService.FindFirst() then; + EDocumentServiceStatus.SetRange("E-Document Entry No", EDocument."Entry No"); + EDocumentServiceStatus.SetRange("E-Document Service Code", EDocumentService.Code); + if EDocumentServiceStatus.FindSet() then + repeat + EDocumentServiceStatus.TestField(EDocumentServiceStatus.Status, EDocumentServiceStatus.Status::Approved); + until EDocumentServiceStatus.Next() = 0; + end; + + var + SignUpAPIRequests: Codeunit SignUpAPIRequests; + SignUpHelpers: Codeunit SignUpHelpers; + UnsuccessfulResponseErr: Label 'There was an error sending the request. Response code: %1 and error message: %2', Comment = '%1 - http response status code, e.g. 400, %2- error message'; + EnvironmentBlocksErr: Label 'The request to send documents has been blocked. To resolve the problem, enable outgoing HTTP requests for the E-Document apps on the Extension Management page.'; +} \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionAuth.Table.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionAuth.Table.al new file mode 100644 index 0000000000..b363f7fd2f --- /dev/null +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionAuth.Table.al @@ -0,0 +1,57 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.EServices.EDocumentConnector.SignUp; + +table 6370 SignUpConnectionAuth +{ + Access = Internal; + + fields + { + field(1; PK; Code[10]) + { + DataClassification = CustomerContent; + } + field(2; "Access Token"; Guid) + { + Caption = 'Access Token'; + DataClassification = CustomerContent; + } + field(3; "Refresh Token"; Guid) + { + Caption = 'Refresh Token'; + DataClassification = CustomerContent; + } + field(30; "Token Timestamp"; DateTime) + { + Caption = 'Token Timestamp'; + DataClassification = CustomerContent; + } + } + + keys + { + key(Key1; PK) + { + Clustered = true; + } + } + + var + RecordHasBeenRead: Boolean; + + procedure GetRecordOnce(): Boolean + begin + if RecordHasBeenRead then + exit(RecordHasBeenRead); + Clear(Rec); + RecordHasBeenRead := Get(); + if not RecordHasBeenRead then begin + Insert(); + RecordHasBeenRead := Get(); + end; + exit(RecordHasBeenRead); + end; +} \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetup.Table.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetup.Table.al new file mode 100644 index 0000000000..a1e2891bfd --- /dev/null +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetup.Table.al @@ -0,0 +1,104 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.EServices.EDocumentConnector.SignUp; + +table 6371 SignUpConnectionSetup +{ + Access = Internal; + DataPerCompany = false; + + fields + { + field(1; PK; Code[10]) + { + DataClassification = CustomerContent; + } + field(4; "Authentication URL"; Text[250]) + { + Caption = 'Authentication URL'; + DataClassification = CustomerContent; + } + field(9; "Company Id"; Text[100]) + { + Caption = 'Company ID'; + DataClassification = CustomerContent; + } + field(10; "Client ID"; Guid) + { + Caption = 'Client ID'; + DataClassification = EndUserIdentifiableInformation; + } + field(11; "Client Secret"; Guid) + { + Caption = 'Client Secret'; + DataClassification = EndUserIdentifiableInformation; + } + field(12; "Send Mode"; Enum SignUpSendMode) + { + Caption = 'Send Mode'; + DataClassification = CustomerContent; + } + field(13; ServiceURL; Text[250]) + { + Caption = 'Service URL'; + DataClassification = CustomerContent; + } + field(20; "Root App ID"; Guid) + { + Caption = 'Root App ID'; + DataClassification = CustomerContent; + } + field(21; "Root Secret"; Guid) + { + Caption = 'Root App Secret'; + DataClassification = CustomerContent; + } + field(22; "Root Tenant"; Guid) + { + Caption = 'Root App Tenant'; + DataClassification = CustomerContent; + } + field(23; "Root Market URL"; Guid) + { + Caption = 'Root Market URL'; + DataClassification = CustomerContent; + } + field(24; "Client Tenant"; Guid) + { + Caption = 'Client App Tenant'; + DataClassification = CustomerContent; + } // "Access Token Due DateTime" + field(30; "Client Token Due DateTime"; DateTime) + { + Caption = 'Client Token Timestamp'; + DataClassification = SystemMetadata; + } + field(31; "Root Token Due DateTime"; DateTime) + { + Caption = 'Root Token Timestamp'; + DataClassification = SystemMetadata; + } + } + + keys + { + key(Key1; PK) + { + Clustered = true; + } + } + + var + RecordHasBeenRead: Boolean; + + procedure GetRecordOnce(): Boolean + begin + if RecordHasBeenRead then + exit(RecordHasBeenRead); + Clear(Rec); + RecordHasBeenRead := Get(); + exit(RecordHasBeenRead); + end; +} \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al new file mode 100644 index 0000000000..cd3d3c5f87 --- /dev/null +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al @@ -0,0 +1,202 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.EServices.EDocumentConnector.SignUp; + +using System.Telemetry; + +page 6370 SignUpConnectionSetupCard +{ + PageType = Card; + SourceTable = SignUpConnectionSetup; + ApplicationArea = Basic, Suite; + UsageCategory = None; + Caption = 'E-Document External Connection Setup'; + Extensible = false; + + layout + { + area(Content) + { + group(General) + { + field(ClientID; ClientID) + { + Caption = 'Client ID'; + ToolTip = 'Specifies the client ID token.'; + ApplicationArea = Basic, Suite; + ExtendedDatatype = Masked; + ShowMandatory = true; + + trigger OnValidate() + begin + SignUpAuth.StorageSet(Rec."Client ID", ClientID); + end; + } + field(ClientSecret; ClientSecret) + { + Caption = 'Client Secret'; + ToolTip = 'Specifies the client secret token.'; + ApplicationArea = Basic, Suite; + ExtendedDatatype = Masked; + ShowMandatory = true; + + trigger OnValidate() + begin + SignUpAuth.StorageSet(Rec."Client Secret", ClientSecret); + end; + } + field(ClientTenant; ClientTenant) + { + Caption = 'Client Tenant ID'; + ToolTip = 'Specifies the client tenant id token.'; + ApplicationArea = Basic, Suite; + ExtendedDatatype = Masked; + Visible = false; + + trigger OnValidate() + begin + SignUpAuth.StorageSet(Rec."Client Tenant", ClientTenant); + end; + } + field(RootID; RootID) + { + Caption = 'Root App ID'; + ToolTip = 'Specifies the root app id token.'; + ApplicationArea = Basic, Suite; + ExtendedDatatype = Masked; + Visible = false; + + trigger OnValidate() + begin + SignUpAuth.StorageSet(Rec."Root App ID", RootID); + end; + } + field(RootSecret; RootSecret) + { + Caption = 'Root Secret'; + ToolTip = 'Specifies the root secret token.'; + ApplicationArea = Basic, Suite; + ExtendedDatatype = Masked; + Visible = false; + + trigger OnValidate() + begin + SignUpAuth.StorageSet(Rec."Root Secret", RootSecret); + end; + } + field(RootTenant; RootTenant) + { + Caption = 'Root Tenant ID'; + ToolTip = 'Specifies the root tenant id token.'; + ApplicationArea = Basic, Suite; + ExtendedDatatype = Masked; + Visible = false; + + trigger OnValidate() + begin + SignUpAuth.StorageSet(Rec."Root Tenant", RootTenant); + end; + } + field(RootUrl; RootUrl) + { + Caption = 'Root Url'; + ToolTip = 'Specifies the root url token.'; + ApplicationArea = Basic, Suite; + ExtendedDatatype = Masked; + Visible = false; + + trigger OnValidate() + begin + SignUpAuth.StorageSet(Rec."Root Market URL", RootUrl); + end; + } + field("Authentication URL"; Rec."Authentication URL") + { + ApplicationArea = Basic, Suite; + ToolTip = 'Specifies the URL to connect Microsoft Entra.'; + } + field(ServiceURL; Rec.ServiceURL) + { + ApplicationArea = Basic, Suite; + ToolTip = 'Specifies the service URL.'; + } + field("Company Id"; Rec."Company Id") + { + ApplicationArea = Basic, Suite; + ToolTip = 'Specifies the company ID.'; + ShowMandatory = true; + } + field("Send Mode"; Rec."Send Mode") + { + ApplicationArea = Basic, Suite; + ToolTip = 'Specifies the send mode.'; + ShowMandatory = true; + } + } + } + } + + actions + { + area(processing) + { + action(InitOnboarding01) + { + ApplicationArea = Basic, Suite; + Caption = 'Open Onboarding'; + Image = Setup; + Promoted = true; + PromotedCategory = Process; + PromotedOnly = true; + ToolTip = 'Create client credentials and open the onboarding process in a web browser.'; + + trigger OnAction() + begin + SignUpAuth.CreateClientCredentials(); + CurrPage.Update(); + SetPageVariables(); + Hyperlink(SignUpAuth.GetRootOnboardingUrl()); + FeatureTelemetry.LogUptake('', ExternalServiceTok, Enum::"Feature Uptake Status"::"Set up"); + end; + } + } + } + + trigger OnOpenPage() + begin + SignUpAuth.InitConnectionSetup(); + if Rec.Get() then + ; + SetPageVariables(); + FeatureTelemetry.LogUptake('', ExternalServiceTok, Enum::"Feature Uptake Status"::Discovered); + end; + + local procedure SetPageVariables() + begin + if not IsNullGuid(Rec."Client ID") then + ClientID := '*'; + if not IsNullGuid(Rec."Client Secret") then + ClientSecret := '*'; + if not IsNullGuid(Rec."Client Tenant") then + ClientTenant := '*'; + if not IsNullGuid(Rec."Root App ID") then + RootID := '*'; + if not IsNullGuid(Rec."Root Secret") then + RootSecret := '*'; + if not IsNullGuid(Rec."Root Tenant") then + RootTenant := '*'; + if not IsNullGuid(Rec."Root Market URL") then + RootUrl := '*'; + end; + + var + SignUpAuth: Codeunit SignUpAuth; + FeatureTelemetry: Codeunit "Feature Telemetry"; + [NonDebuggable] + ClientID, ClientSecret, ClientTenant, ClientUrl, RootID, RootSecret, RootTenant, RootUrl : Text; + ExternalServiceTok: Label 'ExternalServiceConnector', Locked = true; + + +} diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/ErrorSensitive.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/ErrorSensitive.Codeunit.al new file mode 100644 index 0000000000..3303e277aa --- /dev/null +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/ErrorSensitive.Codeunit.al @@ -0,0 +1,54 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.EServices.EDocumentConnector.SignUp; + +using System.Azure.Identity; + +codeunit 6373 SignUpErrorSensitive +{ + Access = Internal; + Description = 'Create functions to run sensitive code that may fail out of your control but you need to keep the code going'; + + trigger OnRun() + begin + case gParameter of + 'AADDETAILS': + TryGetAADDetails(); + end; + end; + + // + // Error prone function(s) + // + local procedure TryGetAADDetails() + begin + gResult1 := AzureADTenant.GetAadTenantId(); + gResult2 := AzureADTenant.GetAadTenantDomainName(); + end; + + // + // Generic Get/Set methods to communicate before and after try-catch + // + procedure SetParameter(Parameter: Text) + begin + gParameter := Parameter; + end; + + procedure GetFirstResult(): Text; + begin + exit(gResult1); + end; + + procedure GetSecondResult(): Text; + begin + exit(gResult2); + end; + + var + AzureADTenant: Codeunit "Azure AD Tenant"; + gParameter: Text; + gResult1: Text; + gResult2: Text; +} diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/GetReadyStatus.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/GetReadyStatus.Codeunit.al new file mode 100644 index 0000000000..07df54d9c0 --- /dev/null +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/GetReadyStatus.Codeunit.al @@ -0,0 +1,134 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.EServices.EDocumentConnector.SignUp; + +using System.Telemetry; +using System.Threading; +using Microsoft.EServices.EDocument; + +codeunit 6374 SignUpGetReadyStatus +{ + TableNo = "Job Queue Entry"; + Access = Internal; + + trigger OnRun() + var + BlankRecordId: RecordId; + begin + if not IsEDocumentStatusSent() then + exit; + + ProcessSentDocuments(); + + if IsEDocumentStatusSent() then + ScheduleEDocumentJob(Codeunit::SignUpGetReadyStatus, BlankRecordId, 300000); + end; + + local procedure ProcessSentDocuments() + var + EDocumentServiceStatus: Record "E-Document Service Status"; + EDocumentService: Record "E-Document Service"; + EDocument: Record "E-Document"; + begin + EDocumentServiceStatus.SetRange(Status, EDocumentServiceStatus.Status::Sent); + if EDocumentServiceStatus.FindSet() then + repeat + FetchEDocumentAndService(EDocument, EDocumentService, EDocumentServiceStatus); + HandleResponse(EDocument, EDocumentService, EDocumentServiceStatus); + FetchEDocumentAndService(EDocument, EDocumentService, EDocumentServiceStatus); + until EDocumentServiceStatus.Next() = 0; + end; + + local procedure FetchEDocumentAndService(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; var EDocumentServiceStatus: Record "E-Document Service Status") + begin + EDocumentService.Get(EDocumentServiceStatus."E-Document Service Code"); + EDocument.Get(EDocumentServiceStatus."E-Document Entry No"); + end; + + local procedure HandleResponse(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; var EDocumentServiceStatus: Record "E-Document Service Status") + var + SignUpProcessing: Codeunit SignUpProcessing; + BlankRecordId: RecordId; + HttpResponse: HttpResponseMessage; + HttpRequest: HttpRequestMessage; + begin + if GetResponse(EDocumentServiceStatus, HttpRequest, HttpResponse) then begin + SignUpProcessing.InsertLogWithIntegration(EDocument, EDocumentService, Enum::"E-Document Service Status"::Approved, 0, HttpRequest, HttpResponse); + ScheduleEDocumentJob(Codeunit::SignUpPatchSent, BlankRecordId, 300000); + end; + + end; + + local procedure GetResponse(var EDocumentServiceStatus: Record "E-Document Service Status"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) ReturnStatus: Boolean + var + EDocument: Record "E-Document"; + SignUpProcessing: Codeunit SignUpProcessing; + TelemetryDimensions: Dictionary of [Text, Text]; + begin + // Commit before create document with error handling + Commit(); + Telemetry.LogMessage('', EDocTelemetryGetResponseScopeStartLbl, Verbosity::Normal, DataClassification::OrganizationIdentifiableInformation, TelemetryScope::All, TelemetryDimensions); + + EDocument.Get(EDocumentServiceStatus."E-Document Entry No"); + + if SignUpProcessing.GetDocumentSentResponse(EDocument, HttpRequest, HttpResponse) then + ReturnStatus := true; + + Telemetry.LogMessage('', EDocTelemetryGetResponseScopeEndLbl, Verbosity::Normal, DataClassification::OrganizationIdentifiableInformation, TelemetryScope::All); + end; + + local procedure IsEDocumentStatusSent(): Boolean + var + EdocumentServiceStatus: Record "E-Document Service Status"; + begin + EdocumentServiceStatus.SetRange(Status, EdocumentServiceStatus.Status::Sent); + exit(not EdocumentServiceStatus.IsEmpty()); + end; + + procedure ScheduleEDocumentJob(CodeunitId: Integer; JobRecordId: RecordId; EarliestStartDateTime: Integer): Guid + var + JobQueueEntry: Record "Job Queue Entry"; + TelemetryDimensions: Dictionary of [Text, Text]; + begin + if IsJobQueueScheduled(CodeunitId) then + exit; + + JobQueueEntry.Init(); + JobQueueEntry."Object Type to Run" := JobQueueEntry."Object Type to Run"::Codeunit; + JobQueueEntry."Object ID to Run" := CodeunitId; + JobQueueEntry."Record ID to Process" := JobRecordId; + JobQueueEntry."User Session ID" := SessionId(); + JobQueueEntry."Job Queue Category Code" := JobQueueCategoryTok; + JobQueueEntry."No. of Attempts to Run" := 0; + JobQueueEntry."Earliest Start Date/Time" := CurrentDateTime + EarliestStartDateTime; + + TelemetryDimensions.Add('Job Queue Id', JobQueueEntry.ID); + TelemetryDimensions.Add('Codeunit Id', Format(CodeunitId)); + TelemetryDimensions.Add('Record Id', Format(JobRecordId)); + TelemetryDimensions.Add('User Session ID', Format(JobQueueEntry."User Session ID")); + TelemetryDimensions.Add('Earliest Start Date/Time', Format(JobQueueEntry."Earliest Start Date/Time")); + Telemetry.LogMessage('', EDocumentJobTelemetryLbl, Verbosity::Normal, DataClassification::OrganizationIdentifiableInformation, TelemetryScope::All, TelemetryDimensions); + Codeunit.Run(Codeunit::"Job Queue - Enqueue", JobQueueEntry); + exit(JobQueueEntry.ID); + end; + + local procedure IsJobQueueScheduled(CodeunitId: Integer): Boolean + var + JobQueueEntry: Record "Job Queue Entry"; + begin + JobQueueEntry.SetRange("Object Type to Run", JobQueueEntry."Object Type to Run"::Codeunit); + JobQueueEntry.SetRange("Object ID to Run", CodeunitId); + JobQueueEntry.SetFilter(Status, '%1|%2', JobQueueEntry.Status::Ready, JobQueueEntry.Status::"In Process"); + if not JobQueueEntry.IsEmpty() then + exit(true); + end; + + var + Telemetry: Codeunit Telemetry; + EDocTelemetryGetResponseScopeStartLbl: Label 'E-Document Get Response: Start Scope', Locked = true; + EDocTelemetryGetResponseScopeEndLbl: Label 'E-Document Get Response: End Scope', Locked = true; + JobQueueCategoryTok: Label 'EDocument', Locked = true, Comment = 'Max Length 10'; + EDocumentJobTelemetryLbl: Label 'E-Document Background Job Scheduled', Locked = true; +} \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/Helpers.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/Helpers.Codeunit.al new file mode 100644 index 0000000000..26f82a5eb9 --- /dev/null +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/Helpers.Codeunit.al @@ -0,0 +1,63 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.EServices.EDocumentConnector.SignUp; + +using System.Text; + +codeunit 6375 SignUpHelpers +{ + Access = Internal; + + [NonDebuggable] + procedure ParseJsonString(HttpContentResponse: HttpContent): Text + var + ResponseJObject: JsonObject; + ResponseJson: Text; + Result: Text; + IsJsonResponse: Boolean; + begin + HttpContentResponse.ReadAs(Result); + IsJsonResponse := ResponseJObject.ReadFrom(Result); + if IsJsonResponse then + ResponseJObject.WriteTo(ResponseJson) + else + exit(''); + + if not TryInitJson(ResponseJson) then + exit(''); + + exit(Result); + end; + + [TryFunction] + [NonDebuggable] + local procedure TryInitJson(JsonTxt: Text) + var + JsonManagement: Codeunit "JSON Management"; + begin + JSONManagement.InitializeObject(JsonTxt); + end; + + [NonDebuggable] + procedure GetJsonValueFromText(JsonText: Text; Path: Text) return: Text + var + JObject: JsonObject; + JToken: JsonToken; + begin + if JObject.ReadFrom(JsonText) then + if JObject.SelectToken(Path, JToken) then + return := GetJsonValue(JToken.AsValue()); + end; + + [NonDebuggable] + procedure GetJsonValue(JValue: JsonValue): Text + begin + if JValue.IsNull then + exit(''); + if JValue.IsUndefined then + exit(''); + exit(JValue.AsText()); + end; +} \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationEnumExt.EnumExt.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationEnumExt.EnumExt.al new file mode 100644 index 0000000000..6566ecaf0c --- /dev/null +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationEnumExt.EnumExt.al @@ -0,0 +1,16 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.EServices.EDocumentConnector.SignUp; + +using Microsoft.EServices.EDocument; + +enumextension 6370 SignUpIntegrationEnumExt extends "E-Document Integration" +{ + value(6370; "ExFlow E-Invoicing") + { + Caption = 'ExFlow E-Invoicing'; + Implementation = "E-Document Integration" = SignUpIntegrationImpl; + } +} \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationImpl.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationImpl.Codeunit.al new file mode 100644 index 0000000000..2f36aff0f6 --- /dev/null +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationImpl.Codeunit.al @@ -0,0 +1,59 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.EServices.EDocumentConnector.SignUp; + +using System.Utilities; +using Microsoft.EServices.EDocument; + +codeunit 6376 SignUpIntegrationImpl implements "E-Document Integration" +{ + Access = Internal; + + procedure Send(var EDocument: Record "E-Document"; var TempBlob: Codeunit "Temp Blob"; var IsAsync: Boolean; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) + var + begin + SignUpProcessing.SendEDocument(EDocument, TempBlob, IsAsync, HttpRequest, HttpResponse); + end; + + procedure SendBatch(var EDocuments: Record "E-Document"; var TempBlob: Codeunit "Temp Blob"; var IsAsync: Boolean; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) + begin + IsAsync := false; + Error('Batch sending is not supported in this version'); + end; + + procedure GetResponse(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean + begin + exit(SignUpProcessing.GetDocumentResponse(EDocument, HttpRequest, HttpResponse)); + end; + + procedure GetApproval(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean + begin + exit(SignUpProcessing.GetDocumentApproval(EDocument, HttpRequest, HttpResponse)); + end; + + procedure Cancel(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean + begin + Error('Cancel is not supported in this version'); + end; + + procedure ReceiveDocument(var TempBlob: Codeunit "Temp Blob"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) + begin + SignUpProcessing.ReceiveDocument(TempBlob, HttpRequest, HttpResponse); + end; + + procedure GetDocumentCountInBatch(var TempBlob: Codeunit "Temp Blob"): Integer + begin + exit(SignUpProcessing.GetDocumentCountInBatch(TempBlob)); + end; + + procedure GetIntegrationSetup(var SetupPage: Integer; var SetupTable: Integer) + begin + SetupPage := Page::SignUpConnectionSetupCard; + SetupTable := Database::SignUpConnectionSetup; + end; + + var + SignUpProcessing: Codeunit SignUpProcessing; +} \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/PatchSent.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/PatchSent.Codeunit.al new file mode 100644 index 0000000000..0dd968b139 --- /dev/null +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/PatchSent.Codeunit.al @@ -0,0 +1,81 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.EServices.EDocumentConnector.SignUp; + +using System.Threading; +using Microsoft.EServices.EDocument; + +codeunit 6377 SignUpPatchSent +{ + TableNo = "Job Queue Entry"; + Access = Internal; + + trigger OnRun() + var + SignUpGetReadyStatus: Codeunit SignUpGetReadyStatus; + BlankRecordId: RecordId; + begin + if not IsEDocumentApproved() then + exit; + + ProcessApprovedDocuments(); + + if IsEDocumentApproved() then + SignUpGetReadyStatus.ScheduleEDocumentJob(Codeunit::SignUpPatchSent, BlankRecordId, 300000); + end; + + local procedure ProcessApprovedDocuments() + var + EDocumentServiceStatus: Record "E-Document Service Status"; + EDocumentService: Record "E-Document Service"; + EDocumentIntegrationLog: Record "E-Document Integration Log"; + EDocument: Record "E-Document"; + SignUpAPIRequests: Codeunit SignUpAPIRequests; + SignUpProcessing: Codeunit SignUpProcessing; + HttpResponse: HttpResponseMessage; + HttpRequest: HttpRequestMessage; + begin + EDocumentServiceStatus.SetRange(Status, EDocumentServiceStatus.Status::Approved); + if EDocumentServiceStatus.FindSet() then + repeat + FetchEDocumentAndService(EDocument, EDocumentService, EDocumentServiceStatus); + + EDocumentIntegrationLog.Reset(); + EDocumentIntegrationLog.SetRange("E-Doc. Entry No", EDocument."Entry No"); + EDocumentIntegrationLog.SetRange("Response Status", 204); + EDocumentIntegrationLog.SetRange(Method, 'PATCH'); + if EDocumentIntegrationLog.IsEmpty then + if SignUpAPIRequests.PatchADocument(EDocument, HttpRequest, HttpResponse) then + SignUpProcessing.InsertIntegrationLog(EDocument, EDocumentService, HttpRequest, HttpResponse); + until EDocumentServiceStatus.Next() = 0; + end; + + local procedure FetchEDocumentAndService(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; var EDocumentServiceStatus: Record "E-Document Service Status") + begin + EDocumentService.Get(EDocumentServiceStatus."E-Document Service Code"); + EDocument.Get(EDocumentServiceStatus."E-Document Entry No"); + end; + + local procedure IsEDocumentApproved(): Boolean + var + EdocumentServiceStatus: Record "E-Document Service Status"; + EDocumentIntegrationLog: Record "E-Document Integration Log"; + HasRecords: Boolean; + begin + EdocumentServiceStatus.SetRange(Status, EdocumentServiceStatus.Status::Approved); + if EdocumentServiceStatus.FindSet() then + repeat + EDocumentIntegrationLog.Reset(); + EDocumentIntegrationLog.SetRange("E-Doc. Entry No", EdocumentServiceStatus."E-Document Entry No"); + EDocumentIntegrationLog.SetRange("Response Status", 204); + EDocumentIntegrationLog.SetRange(Method, 'PATCH'); + if EDocumentIntegrationLog.IsEmpty then + HasRecords := true; + + until (EdocumentServiceStatus.Next() = 0) or (HasRecords); + + exit(HasRecords); + end; +} \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/Processing.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/Processing.Codeunit.al new file mode 100644 index 0000000000..b6fe6e0888 --- /dev/null +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/Processing.Codeunit.al @@ -0,0 +1,573 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.EServices.EDocumentConnector.SignUp; + +using Microsoft.EServices.EDocument; +using System.Telemetry; +using System.Text; +using System.Utilities; + +codeunit 6378 SignUpProcessing +{ + Access = Internal; + Permissions = tabledata "E-Document" = m, + tabledata "E-Document Service Status" = m; + + procedure SendEDocument(var EDocument: Record "E-Document"; var TempBlob: Codeunit "Temp Blob"; var IsAsync: Boolean; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) + var + EDocumentServiceStatus: Record "E-Document Service Status"; + EdocumentService: Record "E-Document Service"; + FeatureTelemetry: Codeunit "Feature Telemetry"; + begin + IsAsync := true; + + EDocumentHelper.GetEdocumentService(EDocument, EdocumentService); + EDocumentServiceStatus.Get(EDocument."Entry No", EdocumentService.Code); + + case EDocumentServiceStatus.Status of + EDocumentServiceStatus.Status::Exported: + SendEDocument(EDocument, TempBlob, HttpRequest, HttpResponse); + EDocumentServiceStatus.Status::"Sending Error": + if EDocument."Document Id" = '' then + SendEDocument(EDocument, TempBlob, HttpRequest, HttpResponse); + end; + + FeatureTelemetry.LogUptake('', ExternalServiceTok, Enum::"Feature Uptake Status"::Used); + end; + + procedure GetDocumentResponse(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean + var + begin + if not CheckIfDocumentStatusSuccessful(EDocument, HttpRequest, HttpResponse) then + exit(false); + + exit(true); + end; + + procedure GetDocumentSentResponse(EDocument: Record "E-Document"; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean + var + EDocumentService: Record "E-Document Service"; + EDocumentServiceStatus: Record "E-Document Service Status"; + SignUpAPIRequests: Codeunit SignUpAPIRequests; + SignUpProcessing: Codeunit SignUpProcessing; + HttpContentResponse: HttpContent; + Status, StatusDescription : Text; + begin + EDocumentHelper.GetEdocumentService(EDocument, EdocumentService); + EDocumentServiceStatus.Get(EDocument."Entry No", EdocumentService.Code); + SignUpAPIRequests.GetSentDocumentStatus(EDocument, HttpRequestMessage, HttpResponseMessage); + HttpContentResponse := HttpResponseMessage.Content; + if ParseGetADocumentApprovalResponse(HttpContentResponse, Status, StatusDescription) then + case Status of + 'Ready': + exit(true); + 'Failed': + begin + if StatusDescription <> '' then + EDocumentErrorHelper.LogSimpleErrorMessage(EDocument, 'Reason: ' + StatusDescription); + SignUpProcessing.InsertLogWithIntegration(EDocument, EDocumentService, Enum::"E-Document Service Status"::Rejected, 0, HttpRequestMessage, HttpResponseMessage); + exit(false); + end; + end; + exit(false); + end; + + procedure GetDocumentApproval(EDocument: Record "E-Document"; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean + var + EDocumentService: Record "E-Document Service"; + EDocumentServiceStatus: Record "E-Document Service Status"; + SignUpAPIRequests: Codeunit SignUpAPIRequests; + SignUpGetReadyStatus: Codeunit SignUpGetReadyStatus; + SignUpProcessing: Codeunit SignUpProcessing; + BlankRecordId: RecordId; + HttpContentResponse: HttpContent; + Status, StatusDescription : Text; + begin + EDocumentHelper.GetEdocumentService(EDocument, EdocumentService); + EDocumentServiceStatus.Get(EDocument."Entry No", EdocumentService.Code); + if not (EDocumentServiceStatus.Status in [EDocumentServiceStatus.Status::Sent, EDocumentServiceStatus.Status::"Pending Response"]) then + Error(GetApprovalCheckStatusErr, EDocumentServiceStatus.Status); + + SignUpAPIRequests.GetSentDocumentStatus(EDocument, HttpRequestMessage, HttpResponseMessage); + HttpContentResponse := HttpResponseMessage.Content; + if ParseGetADocumentApprovalResponse(HttpContentResponse, Status, StatusDescription) then + case Status of + 'Ready': + begin + if EDocumentServiceStatus.Status = EDocumentServiceStatus.Status::Approved then + SignUpGetReadyStatus.ScheduleEDocumentJob(Codeunit::SignUpPatchSent, BlankRecordId, 300000) + else + SignUpGetReadyStatus.ScheduleEDocumentJob(Codeunit::SignUpGetReadyStatus, BlankRecordId, 300000); + exit(true); + end; + 'Failed': + begin + if StatusDescription <> '' then + EDocumentErrorHelper.LogSimpleErrorMessage(EDocument, 'Reason: ' + StatusDescription); + SignUpProcessing.InsertLogWithIntegration(EDocument, EDocumentService, Enum::"E-Document Service Status"::Rejected, 0, HttpRequestMessage, HttpResponseMessage); + exit(false); + end; + end; + exit(false); + end; + + procedure ReceiveDocument(var TempBlob: Codeunit "Temp Blob"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) + var + ContentData: Text; + OutStream: OutStream; + begin + if not SignUpConnection.GetReceivedDocuments(HttpRequest, HttpResponse, true) then + exit; + + HttpResponse.Content.ReadAs(ContentData); + + TempBlob.CreateOutStream(OutStream, TextEncoding::UTF8); + OutStream.WriteText(ContentData); + end; + + procedure GetDocumentCountInBatch(var TempBlob: Codeunit "Temp Blob"): Integer + var + ResponseInstream: InStream; + ResponseTxt: Text; + begin + TempBlob.CreateInStream(ResponseInstream); + ResponseInstream.ReadText(ResponseTxt); + + exit(GetNumberOfReceivedDocuments(ResponseTxt)); + end; + + local procedure SendEDocument(EDocument: Record "E-Document"; TempBlob: Codeunit "Temp Blob"; HttpRequest: HttpRequestMessage; HttpResponse: HttpResponseMessage); + var + HttpContentResponse: HttpContent; + begin + SignUpConnection.HandleSendFilePostRequest(TempBlob, EDocument, HttpRequest, HttpResponse, true); + HttpContentResponse := HttpResponse.Content; + SetEDocumentFileID(EDocument."Entry No", ParseSendFileResponse(HttpContentResponse)); + end; + + local procedure ParseReceivedDocument(InputTxt: Text; Index: Integer; var DocumentId: Text): Boolean + var + JsonManagement: Codeunit "JSON Management"; + JsonManagement2: Codeunit "JSON Management"; + IncrementalTable: Text; + Value: Text; + begin + if not JsonManagement.InitializeFromString(InputTxt) then + exit(false); + + JsonManagement.GetArrayPropertyValueAsStringByName('inbox', Value); + JsonManagement.InitializeCollection(Value); + + if Index = 0 then + Index := 1; + + if Index > JsonManagement.GetCollectionCount() then + exit(false); + + JsonManagement.GetObjectFromCollectionByIndex(IncrementalTable, Index - 1); + JsonManagement2.InitializeObject(IncrementalTable); + JsonManagement2.GetArrayPropertyValueAsStringByName('instanceId', DocumentId); + exit(true); + end; + + local procedure GetNumberOfReceivedDocuments(InputTxt: Text): Integer + var + JsonManagement: Codeunit "JSON Management"; + Value: Text; + begin + InputTxt := LeaveJustNewLine(InputTxt); + + if not JsonManagement.InitializeFromString(InputTxt) then + exit(0); + + JsonManagement.GetArrayPropertyValueAsStringByName('inbox', Value); + JsonManagement.InitializeCollection(Value); + + exit(JsonManagement.GetCollectionCount()); + end; + + local procedure CheckIfDocumentStatusSuccessful(EDocument: Record "E-Document"; var HttpRequestMessage: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean + var + ErrorDescription: Text; + begin + if not SignUpConnection.CheckDocumentStatus(EDocument, HttpRequestMessage, HttpResponse, true) then + exit(false); + + if DocumentHasErrorOrProcessing(EDocument, HttpResponse, ErrorDescription) then + exit(false); + + exit(true); + end; + + local procedure ParseSendFileResponse(HttpContentResponse: HttpContent): Text + var + JsonManagement: Codeunit "JSON Management"; + Result: Text; + Value: Text; + begin + Result := SignUpHelpers.ParseJsonString(HttpContentResponse); + if Result = '' then + exit(''); + + if not JsonManagement.InitializeFromString(Result) then + exit(''); + + JsonManagement.GetStringPropertyValueByName('peppolInstanceId', Value); + exit(Value); + end; + + local procedure SetEDocumentFileID(EDocEntryNo: Integer; FileId: Text) + var + EDocument: Record "E-Document"; + begin + if FileId = '' then + exit; + if not EDocument.Get(EDocEntryNo) then + exit; + + EDocument."Document Id" := CopyStr(FileId, 1, MaxStrLen(EDocument."Document Id")); + EDocument.Modify(); + end; + + local procedure DocumentHasErrorOrProcessing(EDocument: Record "E-Document"; HttpResponse: HttpResponseMessage; var ErrorDescription: Text): Boolean + var + EDocumentService: Record "E-Document Service"; + EDocumentServiceStatus: Record "E-Document Service Status"; + JsonManagement: Codeunit "JSON Management"; + SignUpGetReadyStatus: Codeunit SignUpGetReadyStatus; + BlankRecordId: RecordId; + HttpContentResponse: HttpContent; + Result, Value : Text; + begin + HttpContentResponse := HttpResponse.Content; + Result := SignUpHelpers.ParseJsonString(HttpContentResponse); + if Result = '' then + exit(true); + + if not JsonManagement.InitializeFromString(Result) then + exit(true); + + JsonManagement.GetArrayPropertyValueAsStringByName('status', Value); + + if Value in ['Sent'] then begin + SignUpGetReadyStatus.ScheduleEDocumentJob(Codeunit::SignUpGetReadyStatus, BlankRecordId, 120000); + exit(false); + end; + + if Value in ['Ready'] then begin + EDocumentHelper.GetEdocumentService(EDocument, EDocumentService); + EDocumentServiceStatus.Get(EDocument."Entry No", EdocumentService.Code); + if EDocumentServiceStatus.Status = EDocumentServiceStatus.Status::Approved then + SignUpGetReadyStatus.ScheduleEDocumentJob(Codeunit::SignUpPatchSent, BlankRecordId, 180000) + else + SignUpGetReadyStatus.ScheduleEDocumentJob(Codeunit::SignUpGetReadyStatus, BlankRecordId, 120000); + exit(false); + end; + + if Value = 'Failed' then begin + JsonManagement.GetArrayPropertyValueAsStringByName('description', ErrorDescription); + exit(false); + end; + + JsonManagement.GetArrayPropertyValueAsStringByName('description', ErrorDescription); + exit(true); + end; + + procedure ParseGetADocumentApprovalResponse(HttpContentResponse: HttpContent; var Status: Text; var StatusDescription: Text): Boolean + var + JsonManagement: Codeunit "JSON Management"; + Result: Text; + begin + Result := SignUpHelpers.ParseJsonString(HttpContentResponse); + if Result = '' then + exit(false); + + if not JsonManagement.InitializeFromString(Result) then + exit(false); + + JsonManagement.GetArrayPropertyValueAsStringByName('status', Status); + + if Status in ['Ready', 'Sent'] then + exit(true); + + if Status = 'Failed' then begin + JsonManagement.GetArrayPropertyValueAsStringByName('description', StatusDescription); + exit(true); + end; + + exit(false); + end; + + [EventSubscriber(ObjectType::Codeunit, Codeunit::"E-Doc. Integration Management", 'OnGetEDocumentApprovalReturnsFalse', '', false, false)] + local procedure OnGetEDocumentApprovalReturnsFalse(EDocuments: Record "E-Document"; EDocumentService: Record "E-Document Service"; HttpRequest: HttpRequestMessage; HttpResponse: HttpResponseMessage; var IsHandled: Boolean) + var + HttpContentResponse: HttpContent; + Status, StatusDescription : Text; + begin + HttpContentResponse := HttpResponse.Content; + if not ParseGetADocumentApprovalResponse(HttpContentResponse, Status, StatusDescription) then + IsHandled := true; + end; + + [EventSubscriber(ObjectType::Codeunit, Codeunit::"E-Doc. Import", 'OnAfterInsertImportedEdocument', '', false, false)] + local procedure OnAfterInsertEdocument(var EDocument: Record "E-Document"; EDocumentService: Record "E-Document Service"; var TempBlob: Codeunit "Temp Blob"; EDocCount: Integer; HttpRequest: HttpRequestMessage; HttpResponse: HttpResponseMessage) + var + LocalHttpRequest: HttpRequestMessage; + LocalHttpResponse: HttpResponseMessage; + DocumentOutStream: OutStream; + ContentData, DocumentId : Text; + begin + + if EDocumentService."Service Integration" <> EDocumentService."Service Integration"::"ExFlow E-Invoicing" then + exit; + + HttpResponse.Content.ReadAs(ContentData); + + ContentData := LeaveJustNewLine(ContentData); + + if not ParseReceivedDocument(ContentData, EDocument."Index In Batch", DocumentId) then begin + EDocumentErrorHelper.LogSimpleErrorMessage(EDocument, DocumentIdNotFoundErr); + exit; + end; + + SignUpConnection.HandleGetTargetDocumentRequest(DocumentId, LocalHttpRequest, LocalHttpResponse, false); + EDocumentLogHelper.InsertIntegrationLog(EDocument, EDocumentService, LocalHttpRequest, LocalHttpResponse); + + LocalHttpResponse.Content.ReadAs(ContentData); + + if not ParseContentData(ContentData) then + ContentData := ''; + + if ContentData = '' then + EDocumentErrorHelper.LogSimpleErrorMessage(EDocument, StrSubstNo(CouldNotRetrieveDocumentErr, DocumentId)); + + Clear(TempBlob); + TempBlob.CreateOutStream(DocumentOutStream, TextEncoding::UTF8); + DocumentOutStream.WriteText(ContentData); + EDocument."Document Id" := CopyStr(DocumentId, 1, MaxStrLen(EDocument."Document Id")); + EDocumentLogHelper.InsertLog(EDocument, EDocumentService, TempBlob, "E-Document Service Status"::Imported); + SignUpConnection.RemoveDocumentFromReceived(EDocument, LocalHttpRequest, LocalHttpResponse, true); + EDocumentLogHelper.InsertIntegrationLog(EDocument, EDocumentService, LocalHttpRequest, LocalHttpResponse); + end; + + + internal procedure InsertIntegrationLog(EDocument: Record "E-Document"; EDocumentService: Record "E-Document Service"; HttpRequest: HttpRequestMessage; HttpResponse: HttpResponseMessage) + var + EDocumentIntegrationLog: Record "E-Document Integration Log"; + EDocumentIntegrationLogRecRef: RecordRef; + RequestTxt: Text; + begin + if EDocumentService."Service Integration" = EDocumentService."Service Integration"::"No Integration" then + exit; + + EDocumentIntegrationLog.Validate("E-Doc. Entry No", EDocument."Entry No"); + EDocumentIntegrationLog.Validate("Service Code", EDocumentService.Code); + EDocumentIntegrationLog.Validate("Response Status", HttpResponse.HttpStatusCode()); + EDocumentIntegrationLog.Validate(URL, HttpRequest.GetRequestUri()); + EDocumentIntegrationLog.Validate(Method, HttpRequest.Method()); + EDocumentIntegrationLog.Insert(); + + EDocumentIntegrationLogRecRef.GetTable(EDocumentIntegrationLog); + + if HttpRequest.Content.ReadAs(RequestTxt) then begin + InsertIntegrationBlob(EDocumentIntegrationLogRecRef, RequestTxt, EDocumentIntegrationLog.FieldNo(EDocumentIntegrationLog."Request Blob")); + EDocumentIntegrationLogRecRef.Modify(); + end; + + if HttpResponse.Content.ReadAs(RequestTxt) then begin + InsertIntegrationBlob(EDocumentIntegrationLogRecRef, RequestTxt, EDocumentIntegrationLog.FieldNo(EDocumentIntegrationLog."Response Blob")); + EDocumentIntegrationLogRecRef.Modify(); + end; + end; + + + internal procedure InsertLog(EDocument: Record "E-Document"; EDocumentService: Record "E-Document Service"; EDocDataStorageEntryNo: Integer; EDocumentServiceStatus: Enum "E-Document Service Status"): Integer + var + EDocumentLog: Record "E-Document Log"; + begin + if EDocumentService.Code <> '' then + UpdateServiceStatus(EDocument, EDocumentService, EDocumentServiceStatus); + + EDocumentLog.Validate("Document Type", EDocument."Document Type"); + EDocumentLog.Validate("Document No.", EDocument."Document No."); + EDocumentLog.Validate("E-Doc. Entry No", EDocument."Entry No"); + EDocumentLog.Validate(Status, EDocumentServiceStatus); + EDocumentLog.Validate("Service Integration", EDocumentService."Service Integration"); + EDocumentLog.Validate("Service Code", EDocumentService.Code); + EDocumentLog.Validate("Document Format", EDocumentService."Document Format"); + EDocumentLog.Validate("E-Doc. Data Storage Entry No.", EDocDataStorageEntryNo); + + EDocumentLog.Insert(); + exit(EDocumentLog."Entry No."); + end; + + internal procedure UpdateServiceStatus(EDocument: Record "E-Document"; EDocumentService: Record "E-Document Service"; EDocumentStatus: Enum "E-Document Service Status") + var + EDocumentServiceStatus: Record "E-Document Service Status"; + Exists: Boolean; + begin + EDocument.Get(EDocument."Entry No"); + Exists := EDocumentServiceStatus.Get(EDocument."Entry No", EDocumentService.Code); + EDocumentServiceStatus.Validate(Status, EDocumentStatus); + if Exists then + EDocumentServiceStatus.Modify() + else begin + EDocumentServiceStatus.Validate("E-Document Entry No", EDocument."Entry No"); + EDocumentServiceStatus.Validate("E-Document Service Code", EDocumentService.Code); + EDocumentServiceStatus.Validate(Status, EDocumentStatus); + EDocumentServiceStatus.Insert(); + end; + + UpdateEDocumentStatus(EDocument); + end; + + local procedure UpdateEDocumentStatus(var EDocument: Record "E-Document") + var + IsHandled: Boolean; + begin + if IsHandled then + exit; + + if EDocumentHasErrors(EDocument) then + exit; + + SetDocumentStatus(EDocument); + end; + + local procedure EDocumentHasErrors(var EDocument: Record "E-Document"): Boolean + var + EDocumentServiceStatus: Record "E-Document Service Status"; + begin + EDocumentServiceStatus.SetRange("E-Document Entry No", EDocument."Entry No"); + EDocumentServiceStatus.SetFilter(Status, '%1|%2|%3|%4|%5', + EDocumentServiceStatus.Status::"Sending Error", + EDocumentServiceStatus.Status::"Export Error", + EDocumentServiceStatus.Status::"Cancel Error", + EDocumentServiceStatus.Status::"Imported Document Processing Error", + EDocumentServiceStatus.Status::Rejected); + + if EDocumentServiceStatus.IsEmpty() then + exit(false); + + EDocument.Validate(Status, EDocument.Status::Error); + EDocument.Modify(); + exit(true); + end; + + local procedure InsertIntegrationBlob(var EDocumentIntegrationLogRecRef: RecordRef; Data: Text; FieldNo: Integer) + var + TempBlob: Codeunit "Temp Blob"; + OutStreamObj: OutStream; + begin + TempBlob.CreateOutStream(OutStreamObj); + OutStreamObj.WriteText(Data); + + TempBlob.ToRecordRef(EDocumentIntegrationLogRecRef, FieldNo); + end; + + local procedure SetDocumentStatus(var EDocument: Record "E-Document") + var + EDocumentServiceStatus: Record "E-Document Service Status"; + EDocServiceCount: Integer; + begin + EDocumentServiceStatus.SetRange("E-Document Entry No", EDocument."Entry No"); + EDocServiceCount := EDocumentServiceStatus.Count; + + EDocumentServiceStatus.SetFilter(Status, '%1|%2|%3|%4|%5', + EDocumentServiceStatus.Status::Exported, + EDocumentServiceStatus.Status::"Imported Document Created", + EDocumentServiceStatus.Status::"Journal Line Created", + EDocumentServiceStatus.Status::Approved, + EDocumentServiceStatus.Status::Canceled); + if EDocumentServiceStatus.Count = EDocServiceCount then + EDocument.Status := EDocument.Status::Processed + else + EDocument.Status := EDocument.Status::"In Progress"; + + EDocument.Modify(); + end; + + internal procedure InsertLogWithIntegration(EDocument: Record "E-Document"; EDocumentService: Record "E-Document Service"; EDocumentServiceStatus: Enum "E-Document Service Status"; EDocDataStorageEntryNo: Integer; + HttpRequest: HttpRequestMessage; + HttpResponse: HttpResponseMessage) + begin + InsertLog(EDocument, EDocumentService, EDocDataStorageEntryNo, EDocumentServiceStatus); + if (HttpRequest.GetRequestUri() <> '') and (HttpResponse.Headers.Keys().Count > 0) then + InsertIntegrationLog(EDocument, EDocumentService, HttpRequest, HttpResponse); + end; + + local procedure LeaveJustNewLine(InputText: Text): Text + var + InputJson: JsonObject; + InputJsonArray: JsonArray; + InputJsonToken: JsonToken; + DocumentJsonToken: JsonToken; + OutputDocumentJsonArray: JsonArray; + OutputDocumentJsonObject: JsonObject; + OutputJsonObject: JsonObject; + OutputText: text; + DocumentList: List of [Text]; + i: Integer; + begin + OutputText := InputText; + InputJson.ReadFrom(InputText); + if InputJson.Contains('inbox') then begin + InputJson.Get('inbox', InputJsonToken); + InputJsonArray := InputJsonToken.AsArray(); + foreach InputJsonToken in InputJsonArray do + if InputJsonToken.AsObject().Get('status', DocumentJsonToken) then + if DocumentJsonToken.AsValue().AsText() = 'New' then begin + InputJsonToken.AsObject().Get('instanceId', DocumentJsonToken); + DocumentList.Add(DocumentJsonToken.AsValue().AsText()); + end; + + for i := 1 to DocumentList.Count do begin + Clear(OutputDocumentJsonObject); + OutputDocumentJsonObject.Add('instanceId', DocumentList.Get(i)); + OutputDocumentJsonArray.Add(OutputDocumentJsonObject); + end; + + OutputJsonObject.Add('inbox', OutputDocumentJsonArray); + OutputJsonObject.WriteTo(OutputText) + + end; + exit(OutputText); + end; + + local procedure ParseContentData(var InputText: Text): Boolean + var + JsonManagement: Codeunit "JSON Management"; + Base64Convert: Codeunit "Base64 Convert"; + Value: Text; + ParsePosition: Integer; + begin + if not JsonManagement.InitializeFromString(InputText) then + exit(false); + + JsonManagement.GetArrayPropertyValueAsStringByName('document', Value); + InputText := Base64Convert.FromBase64(Value); + ParsePosition := StrPos(InputText, ''); + if ParsePosition > 0 then begin + InputText := CopyStr(InputText, parsePosition, StrLen(InputText)); + ParsePosition := StrPos(InputText, ''); + InputText := CopyStr(InputText, 1, parsePosition - 1); + end; + + exit(true); + end; + + var + SignUpConnection: Codeunit SignUpConnection; + SignUpHelpers: Codeunit SignUpHelpers; + EDocumentHelper: Codeunit "E-Document Helper"; + EDocumentLogHelper: Codeunit "E-Document Log Helper"; + EDocumentErrorHelper: Codeunit "E-Document Error Helper"; + GetApprovalCheckStatusErr: Label 'You cannot ask for approval with the E-Document in this current status %1. You can request for approval when E-document status is Sent or Pending Response.', Comment = '%1 - Status'; + CouldNotRetrieveDocumentErr: Label 'Could not retrieve document with id: %1 from the service', Comment = '%1 - Document ID'; + DocumentIdNotFoundErr: Label 'Document ID not found in response'; + ExternalServiceTok: Label 'ExternalServiceConnector', Locked = true; +} \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/SendMode.Enum.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/SendMode.Enum.al new file mode 100644 index 0000000000..7ca9775a4c --- /dev/null +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/SendMode.Enum.al @@ -0,0 +1,19 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.EServices.EDocumentConnector.SignUp; + +enum 6370 SignUpSendMode +{ + Access = Internal; + + value(0; Production) + { + Caption = 'Production', Locked = true; + } + value(1; Test) + { + Caption = 'Test', Locked = true; + } +} \ No newline at end of file From 758acd2436bacd182e2856710230f6388be40fd6 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Tue, 17 Sep 2024 09:57:32 +0200 Subject: [PATCH 02/31] Change obsolete field reference --- .../EDocumentsConnector/app/src/SignUp/Processing.Codeunit.al | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/Processing.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/Processing.Codeunit.al index b6fe6e0888..2f29f05c04 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/Processing.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/Processing.Codeunit.al @@ -365,7 +365,7 @@ codeunit 6378 SignUpProcessing EDocumentIntegrationLog.Validate("E-Doc. Entry No", EDocument."Entry No"); EDocumentIntegrationLog.Validate("Service Code", EDocumentService.Code); EDocumentIntegrationLog.Validate("Response Status", HttpResponse.HttpStatusCode()); - EDocumentIntegrationLog.Validate(URL, HttpRequest.GetRequestUri()); + EDocumentIntegrationLog.Validate("Request URL", HttpRequest.GetRequestUri()); EDocumentIntegrationLog.Validate(Method, HttpRequest.Method()); EDocumentIntegrationLog.Insert(); From 013d1a7b072b4ca9209b2a9a83ef722a0a4ab9de Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Tue, 17 Sep 2024 10:22:44 +0200 Subject: [PATCH 03/31] Use IsSaaSInfrastructure to make fields visible if not in SaaS Sandbox or production. To be populated manually. --- .../app/src/SignUp/ConnectionSetupCard.Page.al | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al index cd3d3c5f87..bb7e1b5f34 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al @@ -5,6 +5,7 @@ namespace Microsoft.EServices.EDocumentConnector.SignUp; using System.Telemetry; +using System.Environment; page 6370 SignUpConnectionSetupCard { @@ -27,6 +28,7 @@ page 6370 SignUpConnectionSetupCard ToolTip = 'Specifies the client ID token.'; ApplicationArea = Basic, Suite; ExtendedDatatype = Masked; + Visible = not IsSaaSInfrastructure; ShowMandatory = true; trigger OnValidate() @@ -40,6 +42,7 @@ page 6370 SignUpConnectionSetupCard ToolTip = 'Specifies the client secret token.'; ApplicationArea = Basic, Suite; ExtendedDatatype = Masked; + Visible = not IsSaaSInfrastructure; ShowMandatory = true; trigger OnValidate() @@ -53,7 +56,7 @@ page 6370 SignUpConnectionSetupCard ToolTip = 'Specifies the client tenant id token.'; ApplicationArea = Basic, Suite; ExtendedDatatype = Masked; - Visible = false; + Visible = not IsSaaSInfrastructure; trigger OnValidate() begin @@ -66,7 +69,7 @@ page 6370 SignUpConnectionSetupCard ToolTip = 'Specifies the root app id token.'; ApplicationArea = Basic, Suite; ExtendedDatatype = Masked; - Visible = false; + Visible = not IsSaaSInfrastructure; trigger OnValidate() begin @@ -79,7 +82,7 @@ page 6370 SignUpConnectionSetupCard ToolTip = 'Specifies the root secret token.'; ApplicationArea = Basic, Suite; ExtendedDatatype = Masked; - Visible = false; + Visible = not IsSaaSInfrastructure; trigger OnValidate() begin @@ -92,7 +95,7 @@ page 6370 SignUpConnectionSetupCard ToolTip = 'Specifies the root tenant id token.'; ApplicationArea = Basic, Suite; ExtendedDatatype = Masked; - Visible = false; + Visible = not IsSaaSInfrastructure; trigger OnValidate() begin @@ -105,7 +108,7 @@ page 6370 SignUpConnectionSetupCard ToolTip = 'Specifies the root url token.'; ApplicationArea = Basic, Suite; ExtendedDatatype = Masked; - Visible = false; + Visible = not IsSaaSInfrastructure; trigger OnValidate() begin @@ -165,7 +168,10 @@ page 6370 SignUpConnectionSetupCard } trigger OnOpenPage() + var + EnvironmentInfo: Codeunit "Environment Information"; begin + IsSaaSInfrastructure := EnvironmentInfo.IsSaaSInfrastructure(); SignUpAuth.InitConnectionSetup(); if Rec.Get() then ; @@ -196,6 +202,7 @@ page 6370 SignUpConnectionSetupCard FeatureTelemetry: Codeunit "Feature Telemetry"; [NonDebuggable] ClientID, ClientSecret, ClientTenant, ClientUrl, RootID, RootSecret, RootTenant, RootUrl : Text; + IsSaaSInfrastructure: Boolean; ExternalServiceTok: Label 'ExternalServiceConnector', Locked = true; From 5d3ad670b8e355f11f131577f47f32c60b614ed0 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Tue, 17 Sep 2024 10:32:42 +0200 Subject: [PATCH 04/31] Push forward object id range by 10 due to Avalara addition --- Apps/W1/EDocumentsConnector/app/app.json | 2 +- .../app/src/SignUp/APIRequests.Codeunit.al | 2 +- Apps/W1/EDocumentsConnector/app/src/SignUp/Auth.Codeunit.al | 2 +- .../EDocumentsConnector/app/src/SignUp/Connection.Codeunit.al | 2 +- .../app/src/SignUp/ConnectionAuth.Table.al | 2 +- .../app/src/SignUp/ConnectionSetup.Table.al | 4 ++-- .../app/src/SignUp/ConnectionSetupCard.Page.al | 2 +- .../app/src/SignUp/ErrorSensitive.Codeunit.al | 2 +- .../app/src/SignUp/GetReadyStatus.Codeunit.al | 2 +- .../W1/EDocumentsConnector/app/src/SignUp/Helpers.Codeunit.al | 2 +- .../app/src/SignUp/IntegrationEnumExt.EnumExt.al | 4 ++-- .../app/src/SignUp/IntegrationImpl.Codeunit.al | 2 +- .../EDocumentsConnector/app/src/SignUp/PatchSent.Codeunit.al | 2 +- .../EDocumentsConnector/app/src/SignUp/Processing.Codeunit.al | 2 +- Apps/W1/EDocumentsConnector/app/src/SignUp/SendMode.Enum.al | 2 +- 15 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Apps/W1/EDocumentsConnector/app/app.json b/Apps/W1/EDocumentsConnector/app/app.json index 301840542b..30fafc9597 100644 --- a/Apps/W1/EDocumentsConnector/app/app.json +++ b/Apps/W1/EDocumentsConnector/app/app.json @@ -31,7 +31,7 @@ "idRanges": [ { "from": 6360, - "to": 6379 + "to": 6389 } ], "resourceExposurePolicy": { diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/APIRequests.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/APIRequests.Codeunit.al index 9081d37ac2..1ea08656e5 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/APIRequests.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/APIRequests.Codeunit.al @@ -12,7 +12,7 @@ using System.Text; using System.Utilities; using System.Xml; -codeunit 6370 SignUpAPIRequests +codeunit 6380 SignUpAPIRequests { Access = Internal; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/Auth.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/Auth.Codeunit.al index 401818638d..1a2167f901 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/Auth.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/Auth.Codeunit.al @@ -9,7 +9,7 @@ using Microsoft.Sales.Customer; using System.Environment; using System.Reflection; -codeunit 6371 SignUpAuth +codeunit 6381 SignUpAuth { Access = Internal; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/Connection.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/Connection.Codeunit.al index 46836c8e1d..833cec05a2 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/Connection.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/Connection.Codeunit.al @@ -9,7 +9,7 @@ using Microsoft.Purchases.Document; using Microsoft.Purchases.Posting; using System.Utilities; -codeunit 6372 SignUpConnection +codeunit 6382 SignUpConnection { Access = Internal; Permissions = tabledata "E-Document" = m; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionAuth.Table.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionAuth.Table.al index b363f7fd2f..d735de2598 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionAuth.Table.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionAuth.Table.al @@ -4,7 +4,7 @@ // ------------------------------------------------------------------------------------------------ namespace Microsoft.EServices.EDocumentConnector.SignUp; -table 6370 SignUpConnectionAuth +table 6380 SignUpConnectionAuth { Access = Internal; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetup.Table.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetup.Table.al index a1e2891bfd..69964f235f 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetup.Table.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetup.Table.al @@ -4,7 +4,7 @@ // ------------------------------------------------------------------------------------------------ namespace Microsoft.EServices.EDocumentConnector.SignUp; -table 6371 SignUpConnectionSetup +table 6381 SignUpConnectionSetup { Access = Internal; DataPerCompany = false; @@ -69,7 +69,7 @@ table 6371 SignUpConnectionSetup { Caption = 'Client App Tenant'; DataClassification = CustomerContent; - } // "Access Token Due DateTime" + } field(30; "Client Token Due DateTime"; DateTime) { Caption = 'Client Token Timestamp'; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al index bb7e1b5f34..97fb1a8dbc 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al @@ -7,7 +7,7 @@ namespace Microsoft.EServices.EDocumentConnector.SignUp; using System.Telemetry; using System.Environment; -page 6370 SignUpConnectionSetupCard +page 6380 SignUpConnectionSetupCard { PageType = Card; SourceTable = SignUpConnectionSetup; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/ErrorSensitive.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/ErrorSensitive.Codeunit.al index 3303e277aa..a1f3c22ea8 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/ErrorSensitive.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/ErrorSensitive.Codeunit.al @@ -6,7 +6,7 @@ namespace Microsoft.EServices.EDocumentConnector.SignUp; using System.Azure.Identity; -codeunit 6373 SignUpErrorSensitive +codeunit 6383 SignUpErrorSensitive { Access = Internal; Description = 'Create functions to run sensitive code that may fail out of your control but you need to keep the code going'; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/GetReadyStatus.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/GetReadyStatus.Codeunit.al index 07df54d9c0..36cf672292 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/GetReadyStatus.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/GetReadyStatus.Codeunit.al @@ -8,7 +8,7 @@ using System.Telemetry; using System.Threading; using Microsoft.EServices.EDocument; -codeunit 6374 SignUpGetReadyStatus +codeunit 6384 SignUpGetReadyStatus { TableNo = "Job Queue Entry"; Access = Internal; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/Helpers.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/Helpers.Codeunit.al index 26f82a5eb9..f97642792e 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/Helpers.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/Helpers.Codeunit.al @@ -6,7 +6,7 @@ namespace Microsoft.EServices.EDocumentConnector.SignUp; using System.Text; -codeunit 6375 SignUpHelpers +codeunit 6385 SignUpHelpers { Access = Internal; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationEnumExt.EnumExt.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationEnumExt.EnumExt.al index 6566ecaf0c..63f5c5c08f 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationEnumExt.EnumExt.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationEnumExt.EnumExt.al @@ -6,9 +6,9 @@ namespace Microsoft.EServices.EDocumentConnector.SignUp; using Microsoft.EServices.EDocument; -enumextension 6370 SignUpIntegrationEnumExt extends "E-Document Integration" +enumextension 6380 SignUpIntegrationEnumExt extends "E-Document Integration" { - value(6370; "ExFlow E-Invoicing") + value(6380; "ExFlow E-Invoicing") { Caption = 'ExFlow E-Invoicing'; Implementation = "E-Document Integration" = SignUpIntegrationImpl; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationImpl.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationImpl.Codeunit.al index 2f36aff0f6..577c4fe44c 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationImpl.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationImpl.Codeunit.al @@ -7,7 +7,7 @@ namespace Microsoft.EServices.EDocumentConnector.SignUp; using System.Utilities; using Microsoft.EServices.EDocument; -codeunit 6376 SignUpIntegrationImpl implements "E-Document Integration" +codeunit 6386 SignUpIntegrationImpl implements "E-Document Integration" { Access = Internal; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/PatchSent.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/PatchSent.Codeunit.al index 0dd968b139..66f637d269 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/PatchSent.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/PatchSent.Codeunit.al @@ -7,7 +7,7 @@ namespace Microsoft.EServices.EDocumentConnector.SignUp; using System.Threading; using Microsoft.EServices.EDocument; -codeunit 6377 SignUpPatchSent +codeunit 6387 SignUpPatchSent { TableNo = "Job Queue Entry"; Access = Internal; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/Processing.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/Processing.Codeunit.al index 2f29f05c04..52f9e1f2a8 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/Processing.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/Processing.Codeunit.al @@ -9,7 +9,7 @@ using System.Telemetry; using System.Text; using System.Utilities; -codeunit 6378 SignUpProcessing +codeunit 6388 SignUpProcessing { Access = Internal; Permissions = tabledata "E-Document" = m, diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/SendMode.Enum.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/SendMode.Enum.al index 7ca9775a4c..22915cce76 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/SendMode.Enum.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/SendMode.Enum.al @@ -4,7 +4,7 @@ // ------------------------------------------------------------------------------------------------ namespace Microsoft.EServices.EDocumentConnector.SignUp; -enum 6370 SignUpSendMode +enum 6380 SignUpSendMode { Access = Internal; From 74c785bc2b1f9666442e068297487163c514ef22 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Tue, 17 Sep 2024 11:45:49 +0200 Subject: [PATCH 05/31] Menu item Open Onboarding only available in SaaS --- .../app/src/SignUp/ConnectionSetupCard.Page.al | 1 + 1 file changed, 1 insertion(+) diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al index 97fb1a8dbc..cb3c40ba2c 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al @@ -153,6 +153,7 @@ page 6380 SignUpConnectionSetupCard Promoted = true; PromotedCategory = Process; PromotedOnly = true; + Visible = IsSaaSInfrastructure; ToolTip = 'Create client credentials and open the onboarding process in a web browser.'; trigger OnAction() From 1042f9f431d0c07e28b9c85dca13640e45530fc2 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Wed, 18 Sep 2024 15:09:17 +0200 Subject: [PATCH 06/31] Change permission structure. Correct spelling. Adjust broken file ending --- .../EDocConnectorEdit.PermissionSet.al | 8 +++---- .../EDocConnectorObjects.PermissionSet.al | 4 +--- .../EDocConnectorRead.PermissionSet.al | 7 +++--- .../SignUpEDocEdit.PermissionSet.al | 15 +++++++++++++ .../SignUpEDocObjects.PermissionSet.al | 22 +++++++++++++++++++ .../SignUpEDocRead.PermissionSet.al | 15 +++++++++++++ .../app/src/SignUp/APIRequests.Codeunit.al | 4 ++-- .../src/SignUp/ConnectionSetupCard.Page.al | 3 ++- .../app/src/SignUp/ErrorSensitive.Codeunit.al | 2 +- 9 files changed, 65 insertions(+), 15 deletions(-) create mode 100644 Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocEdit.PermissionSet.al create mode 100644 Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocObjects.PermissionSet.al create mode 100644 Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocRead.PermissionSet.al diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorEdit.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorEdit.PermissionSet.al index b5d9dfe957..eb8795c0da 100644 --- a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorEdit.PermissionSet.al +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorEdit.PermissionSet.al @@ -8,10 +8,10 @@ permissionset 6361 "EDocConnector - Edit" { Access = Public; Assignable = true; - IncludedPermissionSets = "EDocConnector - Read"; + IncludedPermissionSets = "EDocConnector - Read", + Microsoft.EServices.EDocumentConnector.SignUp.SignUpEDocEdit; + Permissions = tabledata "E-Doc. Ext. Connection Setup" = IM, - tabledata Microsoft.EServices.EDocumentConnector.Avalara."Connection Setup" = imd - tabledata SignUpConnectionSetup = IM, - tabledata SignUpConnectionAuth = IM; + tabledata Microsoft.EServices.EDocumentConnector.Avalara."Connection Setup" = imd; } \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorObjects.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorObjects.PermissionSet.al index 39a8d6e2b3..61ff8046b5 100644 --- a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorObjects.PermissionSet.al +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorObjects.PermissionSet.al @@ -8,12 +8,10 @@ permissionset 6363 "EDoc. Connector Objects" { Access = Public; Assignable = false; + IncludedPermissionSets = Microsoft.EServices.EDocumentConnector.SignUp.SignUpEDocObjects; Permissions = table "E-Doc. Ext. Connection Setup" = X, - table SignUpConnectionSetup = X, - table SignUpConnectionAuth = X, page "EDoc Ext Connection Setup Card" = X, - page SignUpConnectionSetupCard = X, codeunit "Pagero API Requests" = X, codeunit "Pagero Auth." = X, codeunit "Pagero Connection" = X, diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al index 1edcfb769e..8f5d3e035d 100644 --- a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al @@ -8,10 +8,9 @@ permissionset 6362 "EDocConnector - Read" { Access = Public; Assignable = true; - IncludedPermissionSets = "EDoc. Connector Objects"; + IncludedPermissionSets = "EDoc. Connector Objects", + Microsoft.EServices.EDocumentConnector.SignUp.SignUpEDocRead; Permissions = tabledata "E-Doc. Ext. Connection Setup" = R, - tabledata Microsoft.EServices.EDocumentConnector.Avalara."Connection Setup" = r - tabledata SignUpConnectionSetup = R, - tabledata SignUpConnectionAuth = R; + tabledata Microsoft.EServices.EDocumentConnector.Avalara."Connection Setup" = r; } \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocEdit.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocEdit.PermissionSet.al new file mode 100644 index 0000000000..d6bc51215c --- /dev/null +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocEdit.PermissionSet.al @@ -0,0 +1,15 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.EServices.EDocumentConnector.SignUp; + +permissionset 6382 SignUpEDocEdit +{ + Access = Internal; + Assignable = false; + IncludedPermissionSets = SignUpEDocRead; + + Permissions = tabledata SignUpConnectionSetup = IM, + tabledata SignUpConnectionAuth = IM; +} \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocObjects.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocObjects.PermissionSet.al new file mode 100644 index 0000000000..35cd908ae2 --- /dev/null +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocObjects.PermissionSet.al @@ -0,0 +1,22 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.EServices.EDocumentConnector.SignUp; + +permissionset 6380 SignUpEDocObjects +{ + Access = Internal; + Assignable = false; + + Permissions = table SignUpConnectionSetup = X, + table SignUpConnectionAuth = X, + page SignUpConnectionSetupCard = X, + codeunit SignUpIntegrationImpl = X, + codeunit SignUpProcessing = X, + codeunit SignUpAuth = X, + codeunit SignUpAPIRequests = X, + codeunit SignUpConnection = X, + codeunit SignUpPatchSent = X, + codeunit SignUpGetReadyStatus = X; +} \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocRead.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocRead.PermissionSet.al new file mode 100644 index 0000000000..85c62e581f --- /dev/null +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocRead.PermissionSet.al @@ -0,0 +1,15 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.EServices.EDocumentConnector.SignUp; + +permissionset 6381 SignUpEDocRead +{ + Access = Internal; + Assignable = false; + IncludedPermissionSets = SignUpEDocObjects; + + Permissions = tabledata SignUpConnectionSetup = R, + tabledata SignUpConnectionAuth = R; +} \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/APIRequests.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/APIRequests.Codeunit.al index 1ea08656e5..f33d29d208 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/APIRequests.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/APIRequests.Codeunit.al @@ -123,14 +123,14 @@ codeunit 6380 SignUpAPIRequests SendRequest(HttpRequestMessage, HttpResponseMessage, false); end; - local procedure SendRequest(HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage; RootReequest: Boolean): Boolean + local procedure SendRequest(HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage; RootRequest: Boolean): Boolean var SignUpAuth: Codeunit SignUpAuth; HttpClient: HttpClient; HttpHeaders: HttpHeaders; begin HttpRequestMessage.GetHeaders(HttpHeaders); - if RootReequest then + if RootRequest then HttpHeaders.Add('Authorization', SignUpAuth.GetRootBearerAuthText()) else HttpHeaders.Add('Authorization', SignUpAuth.GetBearerAuthText()); diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al index cb3c40ba2c..b4499623f4 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al @@ -198,6 +198,7 @@ page 6380 SignUpConnectionSetupCard RootUrl := '*'; end; + var SignUpAuth: Codeunit SignUpAuth; FeatureTelemetry: Codeunit "Feature Telemetry"; @@ -207,4 +208,4 @@ page 6380 SignUpConnectionSetupCard ExternalServiceTok: Label 'ExternalServiceConnector', Locked = true; -} +} \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/ErrorSensitive.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/ErrorSensitive.Codeunit.al index a1f3c22ea8..bc11430480 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/ErrorSensitive.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/ErrorSensitive.Codeunit.al @@ -51,4 +51,4 @@ codeunit 6383 SignUpErrorSensitive gParameter: Text; gResult1: Text; gResult2: Text; -} +} \ No newline at end of file From 69453b64c043643021f42189a956b2d208bb5122 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Thu, 19 Sep 2024 08:13:23 +0200 Subject: [PATCH 07/31] Change to using instead of full namespace path --- .../app/src/Permissions/EDocConnectorEdit.PermissionSet.al | 4 +++- .../app/src/Permissions/EDocConnectorObjects.PermissionSet.al | 4 +++- .../app/src/Permissions/EDocConnectorRead.PermissionSet.al | 4 +++- .../app/src/SignUp/ConnectionSetupCard.Page.al | 1 - 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorEdit.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorEdit.PermissionSet.al index eb8795c0da..0cb8967ece 100644 --- a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorEdit.PermissionSet.al +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorEdit.PermissionSet.al @@ -4,12 +4,14 @@ // ------------------------------------------------------------------------------------------------ namespace Microsoft.EServices.EDocumentConnector; +using Microsoft.EServices.EDocumentConnector.SignUp; + permissionset 6361 "EDocConnector - Edit" { Access = Public; Assignable = true; IncludedPermissionSets = "EDocConnector - Read", - Microsoft.EServices.EDocumentConnector.SignUp.SignUpEDocEdit; + SignUpEDocEdit; Permissions = tabledata "E-Doc. Ext. Connection Setup" = IM, diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorObjects.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorObjects.PermissionSet.al index 61ff8046b5..3712c9bccb 100644 --- a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorObjects.PermissionSet.al +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorObjects.PermissionSet.al @@ -4,11 +4,13 @@ // ------------------------------------------------------------------------------------------------ namespace Microsoft.EServices.EDocumentConnector; +using Microsoft.EServices.EDocumentConnector.SignUp; + permissionset 6363 "EDoc. Connector Objects" { Access = Public; Assignable = false; - IncludedPermissionSets = Microsoft.EServices.EDocumentConnector.SignUp.SignUpEDocObjects; + IncludedPermissionSets = SignUpEDocObjects; Permissions = table "E-Doc. Ext. Connection Setup" = X, page "EDoc Ext Connection Setup Card" = X, diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al index 8f5d3e035d..8a233ea4d5 100644 --- a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al @@ -4,12 +4,14 @@ // ------------------------------------------------------------------------------------------------ namespace Microsoft.EServices.EDocumentConnector; +using Microsoft.EServices.EDocumentConnector.SignUp; + permissionset 6362 "EDocConnector - Read" { Access = Public; Assignable = true; IncludedPermissionSets = "EDoc. Connector Objects", - Microsoft.EServices.EDocumentConnector.SignUp.SignUpEDocRead; + SignUpEDocRead; Permissions = tabledata "E-Doc. Ext. Connection Setup" = R, tabledata Microsoft.EServices.EDocumentConnector.Avalara."Connection Setup" = r; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al index b4499623f4..5227c39da9 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al @@ -198,7 +198,6 @@ page 6380 SignUpConnectionSetupCard RootUrl := '*'; end; - var SignUpAuth: Codeunit SignUpAuth; FeatureTelemetry: Codeunit "Feature Telemetry"; From ebdb7257e10b197fe1331825895521d727d3d9f3 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Fri, 20 Sep 2024 11:02:16 +0200 Subject: [PATCH 08/31] Refactor (MS) - Prefix Removal, Error Raise on Missing Config, Parameter Name, Fully Qualify Perm.Sets --- .../EDocConnectorEdit.PermissionSet.al | 5 +- .../EDocConnectorObjects.PermissionSet.al | 4 +- .../EDocConnectorRead.PermissionSet.al | 4 +- .../SignUpEDocEdit.PermissionSet.al | 8 +- .../SignUpEDocObjects.PermissionSet.al | 22 ++-- .../SignUpEDocRead.PermissionSet.al | 8 +- .../app/src/SignUp/APIRequests.Codeunit.al | 67 +++++----- .../app/src/SignUp/Auth.Codeunit.al | 119 +++++++++--------- .../app/src/SignUp/Connection.Codeunit.al | 28 ++--- .../app/src/SignUp/ConnectionAuth.Table.al | 2 +- .../app/src/SignUp/ConnectionSetup.Table.al | 8 +- .../src/SignUp/ConnectionSetupCard.Page.al | 26 ++-- .../app/src/SignUp/ErrorSensitive.Codeunit.al | 2 +- .../app/src/SignUp/GetReadyStatus.Codeunit.al | 14 +-- .../app/src/SignUp/Helpers.Codeunit.al | 2 +- .../src/SignUp/IntegrationEnumExt.EnumExt.al | 4 +- .../src/SignUp/IntegrationImpl.Codeunit.al | 18 +-- .../app/src/SignUp/PatchSent.Codeunit.al | 14 +-- .../app/src/SignUp/Processing.Codeunit.al | 52 ++++---- .../app/src/SignUp/SendMode.Enum.al | 2 +- 20 files changed, 199 insertions(+), 210 deletions(-) diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorEdit.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorEdit.PermissionSet.al index 0cb8967ece..a55382fbf8 100644 --- a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorEdit.PermissionSet.al +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorEdit.PermissionSet.al @@ -4,15 +4,12 @@ // ------------------------------------------------------------------------------------------------ namespace Microsoft.EServices.EDocumentConnector; -using Microsoft.EServices.EDocumentConnector.SignUp; - permissionset 6361 "EDocConnector - Edit" { Access = Public; Assignable = true; IncludedPermissionSets = "EDocConnector - Read", - SignUpEDocEdit; - + Microsoft.EServices.EDocumentConnector.SignUp."SignUpEDoc. - Edit"; Permissions = tabledata "E-Doc. Ext. Connection Setup" = IM, tabledata Microsoft.EServices.EDocumentConnector.Avalara."Connection Setup" = imd; diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorObjects.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorObjects.PermissionSet.al index 3712c9bccb..0a1e7a24aa 100644 --- a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorObjects.PermissionSet.al +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorObjects.PermissionSet.al @@ -4,13 +4,11 @@ // ------------------------------------------------------------------------------------------------ namespace Microsoft.EServices.EDocumentConnector; -using Microsoft.EServices.EDocumentConnector.SignUp; - permissionset 6363 "EDoc. Connector Objects" { Access = Public; Assignable = false; - IncludedPermissionSets = SignUpEDocObjects; + IncludedPermissionSets = Microsoft.EServices.EDocumentConnector.SignUp."SignUpEDoc. - Objects"; Permissions = table "E-Doc. Ext. Connection Setup" = X, page "EDoc Ext Connection Setup Card" = X, diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al index 8a233ea4d5..0086239cfa 100644 --- a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al @@ -4,14 +4,12 @@ // ------------------------------------------------------------------------------------------------ namespace Microsoft.EServices.EDocumentConnector; -using Microsoft.EServices.EDocumentConnector.SignUp; - permissionset 6362 "EDocConnector - Read" { Access = Public; Assignable = true; IncludedPermissionSets = "EDoc. Connector Objects", - SignUpEDocRead; + Microsoft.EServices.EDocumentConnector.SignUp."SignUpEDoc. - Read"; Permissions = tabledata "E-Doc. Ext. Connection Setup" = R, tabledata Microsoft.EServices.EDocumentConnector.Avalara."Connection Setup" = r; diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocEdit.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocEdit.PermissionSet.al index d6bc51215c..eac95d8021 100644 --- a/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocEdit.PermissionSet.al +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocEdit.PermissionSet.al @@ -4,12 +4,12 @@ // ------------------------------------------------------------------------------------------------ namespace Microsoft.EServices.EDocumentConnector.SignUp; -permissionset 6382 SignUpEDocEdit +permissionset 6382 "SignUpEDoc. - Edit" { Access = Internal; Assignable = false; - IncludedPermissionSets = SignUpEDocRead; + IncludedPermissionSets = "SignUpEDoc. - Read"; - Permissions = tabledata SignUpConnectionSetup = IM, - tabledata SignUpConnectionAuth = IM; + Permissions = tabledata ConnectionSetup = IM, + tabledata ConnectionAuth = IM; } \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocObjects.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocObjects.PermissionSet.al index 35cd908ae2..9dad400f69 100644 --- a/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocObjects.PermissionSet.al +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocObjects.PermissionSet.al @@ -4,19 +4,19 @@ // ------------------------------------------------------------------------------------------------ namespace Microsoft.EServices.EDocumentConnector.SignUp; -permissionset 6380 SignUpEDocObjects +permissionset 6380 "SignUpEDoc. - Objects" { Access = Internal; Assignable = false; - Permissions = table SignUpConnectionSetup = X, - table SignUpConnectionAuth = X, - page SignUpConnectionSetupCard = X, - codeunit SignUpIntegrationImpl = X, - codeunit SignUpProcessing = X, - codeunit SignUpAuth = X, - codeunit SignUpAPIRequests = X, - codeunit SignUpConnection = X, - codeunit SignUpPatchSent = X, - codeunit SignUpGetReadyStatus = X; + Permissions = table ConnectionSetup = X, + table ConnectionAuth = X, + page ConnectionSetupCard = X, + codeunit IntegrationImpl = X, + codeunit Processing = X, + codeunit Auth = X, + codeunit APIRequests = X, + codeunit Connection = X, + codeunit PatchSent = X, + codeunit GetReadyStatus = X; } \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocRead.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocRead.PermissionSet.al index 85c62e581f..1bf5a00de2 100644 --- a/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocRead.PermissionSet.al +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocRead.PermissionSet.al @@ -4,12 +4,12 @@ // ------------------------------------------------------------------------------------------------ namespace Microsoft.EServices.EDocumentConnector.SignUp; -permissionset 6381 SignUpEDocRead +permissionset 6381 "SignUpEDoc. - Read" { Access = Internal; Assignable = false; - IncludedPermissionSets = SignUpEDocObjects; + IncludedPermissionSets = "SignUpEDoc. - Objects"; - Permissions = tabledata SignUpConnectionSetup = R, - tabledata SignUpConnectionAuth = R; + Permissions = tabledata ConnectionSetup = R, + tabledata ConnectionAuth = R; } \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/APIRequests.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/APIRequests.Codeunit.al index f33d29d208..7daf0c6b99 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/APIRequests.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/APIRequests.Codeunit.al @@ -12,28 +12,28 @@ using System.Text; using System.Utilities; using System.Xml; -codeunit 6380 SignUpAPIRequests +codeunit 6380 APIRequests { Access = Internal; // https:///api/Peppol procedure SendFilePostRequest(var TempBlob: Codeunit "Temp Blob"; EDocument: Record "E-Document"; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean var - SignUpConnectionSetup: Record SignUpConnectionSetup; + ConnectionSetup: Record ConnectionSetup; Payload: Text; ContentHttpHeaders: HttpHeaders; HttpContent: HttpContent; ContentText: Text; UriTemplateLbl: Label '%1/api/Peppol', Comment = '%1 = Service Url', Locked = true; begin - InitRequest(SignUpConnectionSetup, HttpRequestMessage, HttpResponseMessage); - HttpRequestMessage := PrepareRequestMsg("Http Request Type"::POST, StrSubstNo(UriTemplateLbl, SignUpConnectionSetup.ServiceURL)); + InitRequest(ConnectionSetup, HttpRequestMessage, HttpResponseMessage); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::POST, StrSubstNo(UriTemplateLbl, ConnectionSetup.ServiceURL)); Payload := XmlToTxt(TempBlob); if Payload = '' then exit(false); Clear(HttpContent); - ContentText := PrepareContentForSend(GetDocumentType(EDocument), SignUpConnectionSetup."Company Id", GetCustomerID(EDocument), GetSenderCountryCode(), Payload, SignUpConnectionSetup."Send Mode"); + ContentText := PrepareContentForSend(GetDocumentType(EDocument), ConnectionSetup."Company Id", GetCustomerID(EDocument), GetSenderCountryCode(), Payload, ConnectionSetup."Send Mode"); HttpContent.WriteFrom(ContentText); HttpContent.GetHeaders(ContentHttpHeaders); if ContentHttpHeaders.Contains('Content-Type') then @@ -47,74 +47,74 @@ codeunit 6380 SignUpAPIRequests // https:///api/Peppol/status?peppolInstanceId= procedure GetSentDocumentStatus(EDocument: Record "E-Document"; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean var - SignUpConnectionSetup: Record SignUpConnectionSetup; + ConnectionSetup: Record ConnectionSetup; UriTemplateLbl: Label '%1/api/Peppol/status?peppolInstanceId=%2', Comment = '%1 = Service Url, %2 = Document ID', Locked = true; begin - InitRequest(SignUpConnectionSetup, HttpRequestMessage, HttpResponseMessage); - HttpRequestMessage := PrepareRequestMsg("Http Request Type"::GET, StrSubstNo(UriTemplateLbl, SignUpConnectionSetup.ServiceURL, EDocument."Document Id")); + InitRequest(ConnectionSetup, HttpRequestMessage, HttpResponseMessage); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::GET, StrSubstNo(UriTemplateLbl, ConnectionSetup.ServiceURL, EDocument."Document Id")); exit(SendRequest(HttpRequestMessage, HttpResponseMessage)); end; // https:///api/Peppol/outbox?peppolInstanceId= procedure PatchADocument(EDocument: Record "E-Document"; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean var - SignUpConnectionSetup: Record SignUpConnectionSetup; + ConnectionSetup: Record ConnectionSetup; UriTemplateLbl: Label '%1/api/Peppol/outbox?peppolInstanceId=%2', Comment = '%1 = Service Url, %2 = Document ID', Locked = true; begin - InitRequest(SignUpConnectionSetup, HttpRequestMessage, HttpResponseMessage); - HttpRequestMessage := PrepareRequestMsg("Http Request Type"::PATCH, StrSubstNo(UriTemplateLbl, SignUpConnectionSetup.ServiceURL, EDocument."Document Id")); + InitRequest(ConnectionSetup, HttpRequestMessage, HttpResponseMessage); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::PATCH, StrSubstNo(UriTemplateLbl, ConnectionSetup.ServiceURL, EDocument."Document Id")); exit(SendRequest(HttpRequestMessage, HttpResponseMessage)); end; // https:///api/Peppol/Inbox?peppolId= procedure GetReceivedDocumentsRequest(var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage; Parameters: Dictionary of [Text, Text]): Boolean var - SignUpConnectionSetup: Record SignUpConnectionSetup; + ConnectionSetup: Record ConnectionSetup; UriTemplateLbl: Label '%1/api/Peppol/Inbox?peppolId=%2', Comment = '%1 = Service Url, %2 = Peppol Identifier', Locked = true; begin - InitRequest(SignUpConnectionSetup, HttpRequestMessage, HttpResponseMessage); - HttpRequestMessage := PrepareRequestMsg("Http Request Type"::GET, StrSubstNo(UriTemplateLbl, SignUpConnectionSetup.ServiceURL, GetSenderReceiverPrefix() + SignUpConnectionSetup."Company Id")); + InitRequest(ConnectionSetup, HttpRequestMessage, HttpResponseMessage); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::GET, StrSubstNo(UriTemplateLbl, ConnectionSetup.ServiceURL, GetSenderReceiverPrefix() + ConnectionSetup."Company Id")); exit(SendRequest(HttpRequestMessage, HttpResponseMessage)); end; // https:///api/Peppol/inbox-document?peppolId= procedure GetTargetDocumentRequest(DocumentId: Text; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean var - SignUpConnectionSetup: Record SignUpConnectionSetup; + ConnectionSetup: Record ConnectionSetup; UriTemplateLbl: Label '%1/api/Peppol/inbox-document?peppolId=%2&peppolInstanceId=%3', Comment = '%1 = Service Url, %2 = Peppol Identifier, %3 = Peppol Gateway Instance', Locked = true; begin - InitRequest(SignUpConnectionSetup, HttpRequestMessage, HttpResponseMessage); - HttpRequestMessage := PrepareRequestMsg("Http Request Type"::GET, StrSubstNo(UriTemplateLbl, SignUpConnectionSetup.ServiceURL, GetSenderReceiverPrefix() + SignUpConnectionSetup."Company Id", DocumentId)); + InitRequest(ConnectionSetup, HttpRequestMessage, HttpResponseMessage); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::GET, StrSubstNo(UriTemplateLbl, ConnectionSetup.ServiceURL, GetSenderReceiverPrefix() + ConnectionSetup."Company Id", DocumentId)); exit(SendRequest(HttpRequestMessage, HttpResponseMessage)); end; // https:///api/Peppol/inbox?peppolInstanceId= procedure PatchReceivedDocument(EDocument: Record "E-Document"; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean var - SignUpConnectionSetup: Record SignUpConnectionSetup; + ConnectionSetup: Record ConnectionSetup; UriTemplateLbl: Label '%1/api/Peppol/inbox?peppolInstanceId=%2', Comment = '%1 = Service Url, %2 = Peppol Gateway Instance', Locked = true; begin - InitRequest(SignUpConnectionSetup, HttpRequestMessage, HttpResponseMessage); - HttpRequestMessage := PrepareRequestMsg("Http Request Type"::PATCH, StrSubstNo(UriTemplateLbl, SignUpConnectionSetup.ServiceURL, EDocument."Document Id")); + InitRequest(ConnectionSetup, HttpRequestMessage, HttpResponseMessage); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::PATCH, StrSubstNo(UriTemplateLbl, ConnectionSetup.ServiceURL, EDocument."Document Id")); exit(SendRequest(HttpRequestMessage, HttpResponseMessage)); end; procedure GetMarketPlaceCredentials(var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean var - SignUpConnectionSetup: Record SignUpConnectionSetup; - SignUpAuth: Codeunit SignUpAuth; + ConnectionSetup: Record ConnectionSetup; + Auth: Codeunit Auth; BaseUrlTxt: Label '%1/api/Registration/init?EntraTenantId=%2', Locked = true; begin - InitRequest(SignUpConnectionSetup, HttpRequestMessage, HttpResponseMessage); - HttpRequestMessage := PrepareRequestMsg("Http Request Type"::POST, StrSubstNo(BaseUrlTxt, SignUpAuth.GetRootUrl(), SignUpAuth.GetBCInstanceIdentifier())); + InitRequest(ConnectionSetup, HttpRequestMessage, HttpResponseMessage); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::POST, StrSubstNo(BaseUrlTxt, Auth.GetRootUrl(), Auth.GetBCInstanceIdentifier())); exit(SendRequest(HttpRequestMessage, HttpResponseMessage, true)); end; - local procedure InitRequest(var SignUpConnectionSetup: Record SignUpConnectionSetup; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage) + local procedure InitRequest(var ConnectionSetup: Record ConnectionSetup; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage) begin Clear(HttpRequestMessage); Clear(HttpResponseMessage); - if not SignUpConnectionSetup.Get() then + if not ConnectionSetup.Get() then Error(MissingSetupErr); end; @@ -125,23 +125,23 @@ codeunit 6380 SignUpAPIRequests local procedure SendRequest(HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage; RootRequest: Boolean): Boolean var - SignUpAuth: Codeunit SignUpAuth; + Auth: Codeunit Auth; HttpClient: HttpClient; HttpHeaders: HttpHeaders; begin HttpRequestMessage.GetHeaders(HttpHeaders); if RootRequest then - HttpHeaders.Add('Authorization', SignUpAuth.GetRootBearerAuthText()) + HttpHeaders.Add('Authorization', Auth.GetRootBearerAuthText()) else - HttpHeaders.Add('Authorization', SignUpAuth.GetBearerAuthText()); + HttpHeaders.Add('Authorization', Auth.GetBearerAuthText()); exit(HttpClient.Send(HttpRequestMessage, HttpResponseMessage)); end; - local procedure PrepareRequestMsg(pHttpRequestType: Enum "Http Request Type"; Uri: Text) RequestMessage: HttpRequestMessage + local procedure PrepareRequestMsg(HttpRequestType: Enum "Http Request Type"; Uri: Text) RequestMessage: HttpRequestMessage var Headers: HttpHeaders; begin - RequestMessage.Method(Format(pHttpRequestType)); + RequestMessage.Method(Format(HttpRequestType)); RequestMessage.SetRequestUri(Uri); RequestMessage.GetHeaders(Headers); Headers.Add('Accept', '*/*'); @@ -175,9 +175,6 @@ codeunit 6380 SignUpAPIRequests var Customer: Record Customer; begin - if EDocument.Direction <> EDocument.Direction::Outgoing then - exit(''); - Customer.Get(EDocument."Bill-to/Pay-to No."); Customer.TestField("Service Participant Id"); exit(Customer."Service Participant Id"); @@ -192,7 +189,7 @@ codeunit 6380 SignUpAPIRequests exit(CompanyInformation."Country/Region Code"); end; - local procedure PrepareContentForSend(DocumentType: Text; SendingCompanyID: Text; RecieverCompanyID: Text; SenderCountryCode: Text; Payload: Text; SendMode: Enum SignUpSendMode): Text + local procedure PrepareContentForSend(DocumentType: Text; SendingCompanyID: Text; RecieverCompanyID: Text; SenderCountryCode: Text; Payload: Text; SendMode: Enum SendMode): Text var Base64Convert: Codeunit "Base64 Convert"; SendJsonObject: JsonObject; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/Auth.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/Auth.Codeunit.al index 1a2167f901..43e627b37a 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/Auth.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/Auth.Codeunit.al @@ -5,24 +5,23 @@ namespace Microsoft.EServices.EDocumentConnector.SignUp; using System.Azure.KeyVault; -using Microsoft.Sales.Customer; using System.Environment; using System.Reflection; -codeunit 6381 SignUpAuth +codeunit 6381 Auth { Access = Internal; procedure InitConnectionSetup() var - lSignUpConnectionSetup: Record SignUpConnectionSetup; + lConnectionSetup: Record ConnectionSetup; begin - if lSignUpConnectionSetup.Get() then + if lConnectionSetup.Get() then exit; - lSignUpConnectionSetup."Authentication URL" := AuthURLTxt; - lSignUpConnectionSetup.ServiceURL := ProdServiceAPITxt; - StorageSet(lSignUpConnectionSetup."Client Tenant", ProdTenantIdTxt); - lSignUpConnectionSetup.Insert(); + lConnectionSetup."Authentication URL" := AuthURLTxt; + lConnectionSetup.ServiceURL := ProdServiceAPITxt; + StorageSet(lConnectionSetup."Client Tenant", ProdTenantIdTxt); + lConnectionSetup.Insert(); end; procedure GetRootOnboardingUrl(): Text @@ -45,8 +44,8 @@ codeunit 6381 SignUpAuth if not GetClientCredentials(HttpRequestMessage, HttpResponseMessage) then Error(ErrorUnableToCreateClientCredentialsLbl); if HttpResponseMessage.Content.ReadAs(JText) then begin - ClientId := SignUpHelpers.GetJsonValueFromText(JText, 'clientId'); - ClientSecret := SignUpHelpers.GetJsonValueFromText(JText, 'clientSecret'); + ClientId := Helpers.GetJsonValueFromText(JText, 'clientId'); + ClientSecret := Helpers.GetJsonValueFromText(JText, 'clientSecret'); if (ClientId <> '') and (not ClientSecret.IsEmpty()) then SaveClientCredentials(ClientId, ClientSecret); end; @@ -55,12 +54,12 @@ codeunit 6381 SignUpAuth [NonDebuggable] local procedure GetClientCredentials(var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean var - SignUpSignUpAPIRequests: Codeunit SignUpAPIRequests; + APIRequests: Codeunit APIRequests; begin - SignUpSignUpAPIRequests.GetMarketPlaceCredentials(HttpRequest, HttpResponse); + APIRequests.GetMarketPlaceCredentials(HttpRequest, HttpResponse); if not HttpResponse.IsSuccessStatusCode then exit(false); - exit(SignUpHelpers.ParseJsonString(HttpResponse.Content) <> ''); + exit(Helpers.ParseJsonString(HttpResponse.Content) <> ''); end; procedure GetBearerAuthText(): SecretText; @@ -75,15 +74,15 @@ codeunit 6381 SignUpAuth procedure GetAuthBearerToken(): SecretText; var - SignUpConnectionAuth: Record SignUpConnectionAuth; + ConnectionAuth: Record ConnectionAuth; HttpError: Text; begin - SignUpConnectionAuth.GetRecordOnce(); - if SignUpConnectionAuth."Token Timestamp" < CurrentDateTime() + 60 * 1000 then + ConnectionAuth.GetRecordOnce(); + if ConnectionAuth."Token Timestamp" < CurrentDateTime() + 60 * 1000 then if not RefreshAccessToken(HttpError) then Error(HttpError); - exit(StorageGet(SignUpConnectionAuth."Access Token", DataScope::Company)); + exit(StorageGet(ConnectionAuth."Access Token", DataScope::Company)); end; procedure GetRootAuthBearerToken() ReturnValue: SecretText; @@ -97,18 +96,18 @@ codeunit 6381 SignUpAuth [NonDebuggable] local procedure RefreshAccessToken(var HttpError: Text): Boolean; var - SignUpConnectionAuth: Record SignUpConnectionAuth; + ConnectionAuth: Record ConnectionAuth; SecretToken: SecretText; RefreshToken: SecretText; begin - SignUpConnectionAuth.GetRecordOnce(); + ConnectionAuth.GetRecordOnce(); if not GetClientAccessToken(SecretToken) then begin HttpError := GetLastErrorText(); exit(false); end; - SignUpConnectionAuth."Token Timestamp" := CurrentDateTime(); - SaveTokens(SignUpConnectionAuth, DataScope::Company, SecretToken, RefreshToken); - SignUpConnectionAuth.Modify(); + ConnectionAuth."Token Timestamp" := CurrentDateTime(); + SaveTokens(ConnectionAuth, DataScope::Company, SecretToken, RefreshToken); + ConnectionAuth.Modify(); exit(true); end; @@ -121,12 +120,12 @@ codeunit 6381 SignUpAuth [NonDebuggable] local procedure GetClientAccessToken(var AccessToken: SecretText): Boolean begin - SignUpConnectionSetup.GetRecordOnce(); + ConnectionSetup.GetRecordOnce(); exit(GetAccessToken( AccessToken, - StorageGetText(SignUpConnectionSetup."Client ID", DataScope::Module), - StorageGet(SignUpConnectionSetup."Client Secret", DataScope::Module), - StorageGetText(SignUpConnectionSetup."Client Tenant", DataScope::Module))); + StorageGetText(ConnectionSetup."Client ID", DataScope::Module), + StorageGet(ConnectionSetup."Client Secret", DataScope::Module), + StorageGetText(ConnectionSetup."Client Tenant", DataScope::Module))); end; [NonDebuggable] @@ -142,8 +141,8 @@ codeunit 6381 SignUpAuth ContentTemplateTxt: Label 'grant_type=client_credentials&client_id=%1&client_secret=%2&resource=%3', Locked = true; JText: Text; begin - SignUpConnectionSetup.GetRecordOnce(); - SignUpConnectionSetup.TestField("Authentication URL"); + ConnectionSetup.GetRecordOnce(); + ConnectionSetup.TestField("Authentication URL"); ContentText := SecretStrSubstNo(ContentTemplateTxt, TypeHelper.UriEscapeDataString(ClientId), ClientSecret, TypeHelper.UriEscapeDataString(ClientId)); @@ -154,31 +153,31 @@ codeunit 6381 SignUpAuth HttpHeaders.Add('Content-Type', 'application/x-www-form-urlencoded'); HttpRequestMessage.Method := 'POST'; - HttpRequestMessage.SetRequestUri(StrSubstNo(SignUpConnectionSetup."Authentication URL", ClientTenant)); + HttpRequestMessage.SetRequestUri(StrSubstNo(ConnectionSetup."Authentication URL", ClientTenant)); HttpRequestMessage.Content(HttpContent); Clear(AccessToken); if HttpClient.Send(HttpRequestMessage, HttpResponseMessage) then if HttpResponseMessage.IsSuccessStatusCode() then if HttpResponseMessage.Content.ReadAs(JText) then - AccessToken := SignUpHelpers.GetJsonValueFromText(JText, 'access_token'); + AccessToken := Helpers.GetJsonValueFromText(JText, 'access_token'); exit(not AccessToken.IsEmpty()); end; - local procedure SaveTokens(var SignUpConnectionAuth: Record SignUpConnectionAuth; TokenDataScope: DataScope; AccessToken: SecretText; RefreshToken: SecretText) + local procedure SaveTokens(var ConnectionAuth: Record ConnectionAuth; TokenDataScope: DataScope; AccessToken: SecretText; RefreshToken: SecretText) begin - StorageSet(SignUpConnectionAuth."Access Token", AccessToken, TokenDataScope); - StorageSet(SignUpConnectionAuth."Refresh Token", RefreshToken, TokenDataScope); + StorageSet(ConnectionAuth."Access Token", AccessToken, TokenDataScope); + StorageSet(ConnectionAuth."Refresh Token", RefreshToken, TokenDataScope); end; procedure SaveClientCredentials(ClientId: Text; ClientSecret: SecretText) begin - Clear(SignUpConnectionSetup); - SignUpConnectionSetup.GetRecordOnce(); - StorageSet(SignUpConnectionSetup."Client ID", ClientId); - StorageSet(SignUpConnectionSetup."Client Secret", ClientSecret); - SignUpConnectionSetup.Modify(); - Clear(SignUpConnectionSetup); + Clear(ConnectionSetup); + ConnectionSetup.GetRecordOnce(); + StorageSet(ConnectionSetup."Client ID", ClientId); + StorageSet(ConnectionSetup."Client Secret", ClientSecret); + ConnectionSetup.Modify(); + Clear(ConnectionSetup); end; local procedure StorageGet(TokenKey: Text; TokenDataScope: DataScope) TokenValueAsSecret: SecretText @@ -243,11 +242,11 @@ codeunit 6381 SignUpAuth [NonDebuggable] local procedure GetRootId() ReturnValue: Text begin - if FetchSecretFromKeyVault('signup-root-id', ReturnValue) then + if FetchSecretFromKeyVault('-root-id', ReturnValue) then exit; - if SignUpConnectionSetup.GetRecordOnce() then begin - SignUpConnectionSetup.TestField("Root App ID"); - ReturnValue := StorageGetText(SignUpConnectionSetup."Root App ID", DataScope::Module); + if ConnectionSetup.GetRecordOnce() then begin + ConnectionSetup.TestField("Root App ID"); + ReturnValue := StorageGetText(ConnectionSetup."Root App ID", DataScope::Module); end; end; @@ -256,9 +255,9 @@ codeunit 6381 SignUpAuth begin if FetchSecretFromKeyVault('signup-root-secret', ReturnValue) then exit; - if SignUpConnectionSetup.GetRecordOnce() then begin - SignUpConnectionSetup.TestField("Root Secret"); - ReturnValue := StorageGetText(SignUpConnectionSetup."Root Secret", DataScope::Module); + if ConnectionSetup.GetRecordOnce() then begin + ConnectionSetup.TestField("Root Secret"); + ReturnValue := StorageGetText(ConnectionSetup."Root Secret", DataScope::Module); end; end; @@ -267,9 +266,9 @@ codeunit 6381 SignUpAuth begin if FetchSecretFromKeyVault('signup-root-tenant', ReturnValue) then exit; - if SignUpConnectionSetup.GetRecordOnce() then begin - SignUpConnectionSetup.TestField("Root Tenant"); - ReturnValue := StorageGetText(SignUpConnectionSetup."Root Tenant", DataScope::Module); + if ConnectionSetup.GetRecordOnce() then begin + ConnectionSetup.TestField("Root Tenant"); + ReturnValue := StorageGetText(ConnectionSetup."Root Tenant", DataScope::Module); end; end; @@ -278,9 +277,9 @@ codeunit 6381 SignUpAuth begin if FetchSecretFromKeyVault('signup-root-url', ReturnValue) then exit; - if SignUpConnectionSetup.GetRecordOnce() then begin - SignUpConnectionSetup.TestField("Root Market URL"); - ReturnValue := StorageGetText(SignUpConnectionSetup."Root Market URL", DataScope::Module); + if ConnectionSetup.GetRecordOnce() then begin + ConnectionSetup.TestField("Root Market URL"); + ReturnValue := StorageGetText(ConnectionSetup."Root Market URL", DataScope::Module); end; end; @@ -305,21 +304,21 @@ codeunit 6381 SignUpAuth local procedure GetAADTenantInformation(var AADTenantID: Text; var AADDomainName: Text): Boolean var - SignUpSignUpErrorSensitive: Codeunit SignUpErrorSensitive; + ErrorSensitive: Codeunit ErrorSensitive; begin - Clear(SignUpSignUpErrorSensitive); - SignUpSignUpErrorSensitive.SetParameter('AADDETAILS'); + Clear(ErrorSensitive); + ErrorSensitive.SetParameter('AADDETAILS'); Commit(); - if SignUpSignUpErrorSensitive.Run() then begin - AADTenantID := SignUpSignUpErrorSensitive.GetFirstResult(); - AADDomainName := SignUpSignUpErrorSensitive.GetSecondResult(); + if ErrorSensitive.Run() then begin + AADTenantID := ErrorSensitive.GetFirstResult(); + AADDomainName := ErrorSensitive.GetSecondResult(); exit(true); end; end; var - SignUpConnectionSetup: Record SignUpConnectionSetup; - SignUpHelpers: Codeunit SignUpHelpers; + ConnectionSetup: Record ConnectionSetup; + Helpers: Codeunit Helpers; BearerTxt: Label 'Bearer %1', Comment = '%1 = text value', Locked = true; AuthURLTxt: Label 'https://login.microsoftonline.com/%1/oauth2/token', Comment = '%1 Entra Tenant Id', Locked = true; ProdTenantIdTxt: Label '0d725623-dc26-484f-a090-b09d2003d092', Locked = true; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/Connection.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/Connection.Codeunit.al index 833cec05a2..34bcd77c6e 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/Connection.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/Connection.Codeunit.al @@ -9,25 +9,25 @@ using Microsoft.Purchases.Document; using Microsoft.Purchases.Posting; using System.Utilities; -codeunit 6382 SignUpConnection +codeunit 6382 Connection { Access = Internal; Permissions = tabledata "E-Document" = m; procedure HandleSendFilePostRequest(var TempBlob: Codeunit "Temp Blob"; var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage; Retry: Boolean): Boolean begin - if not SignUpAPIRequests.SendFilePostRequest(TempBlob, EDocument, HttpRequest, HttpResponse) then + if not APIRequests.SendFilePostRequest(TempBlob, EDocument, HttpRequest, HttpResponse) then if Retry then - SignUpAPIRequests.SendFilePostRequest(TempBlob, EDocument, HttpRequest, HttpResponse); + APIRequests.SendFilePostRequest(TempBlob, EDocument, HttpRequest, HttpResponse); exit(CheckIfSuccessfulRequest(EDocument, HttpResponse)); end; procedure CheckDocumentStatus(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage; Retry: Boolean): Boolean begin - if not SignUpAPIRequests.GetSentDocumentStatus(EDocument, HttpRequest, HttpResponse) then + if not APIRequests.GetSentDocumentStatus(EDocument, HttpRequest, HttpResponse) then if Retry then - SignUpAPIRequests.GetSentDocumentStatus(EDocument, HttpRequest, HttpResponse); + APIRequests.GetSentDocumentStatus(EDocument, HttpRequest, HttpResponse); exit(CheckIfSuccessfulRequest(EDocument, HttpResponse)); end; @@ -36,30 +36,30 @@ codeunit 6382 SignUpConnection var Parameters: Dictionary of [Text, Text]; begin - if not SignUpAPIRequests.GetReceivedDocumentsRequest(HttpRequest, HttpResponse, Parameters) then + if not APIRequests.GetReceivedDocumentsRequest(HttpRequest, HttpResponse, Parameters) then if Retry then - SignUpAPIRequests.GetReceivedDocumentsRequest(HttpRequest, HttpResponse, Parameters); + APIRequests.GetReceivedDocumentsRequest(HttpRequest, HttpResponse, Parameters); if not HttpResponse.IsSuccessStatusCode then exit(false); - exit(SignUpHelpers.ParseJsonString(HttpResponse.Content) <> ''); + exit(Helpers.ParseJsonString(HttpResponse.Content) <> ''); end; procedure HandleGetTargetDocumentRequest(DocumentId: Text; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage; Retry: Boolean): Boolean begin - if not SignUpAPIRequests.GetTargetDocumentRequest(DocumentId, HttpRequest, HttpResponse) then + if not APIRequests.GetTargetDocumentRequest(DocumentId, HttpRequest, HttpResponse) then if Retry then - SignUpAPIRequests.GetTargetDocumentRequest(DocumentId, HttpRequest, HttpResponse); + APIRequests.GetTargetDocumentRequest(DocumentId, HttpRequest, HttpResponse); exit(HttpResponse.IsSuccessStatusCode); end; procedure RemoveDocumentFromReceived(EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage; Retry: Boolean): Boolean begin - if not SignUpAPIRequests.PatchReceivedDocument(EDocument, HttpRequest, HttpResponse) then + if not APIRequests.PatchReceivedDocument(EDocument, HttpRequest, HttpResponse) then if Retry then - SignUpAPIRequests.PatchReceivedDocument(EDocument, HttpRequest, HttpResponse); + APIRequests.PatchReceivedDocument(EDocument, HttpRequest, HttpResponse); exit(HttpResponse.IsSuccessStatusCode); end; @@ -98,8 +98,8 @@ codeunit 6382 SignUpConnection end; var - SignUpAPIRequests: Codeunit SignUpAPIRequests; - SignUpHelpers: Codeunit SignUpHelpers; + APIRequests: Codeunit APIRequests; + Helpers: Codeunit Helpers; UnsuccessfulResponseErr: Label 'There was an error sending the request. Response code: %1 and error message: %2', Comment = '%1 - http response status code, e.g. 400, %2- error message'; EnvironmentBlocksErr: Label 'The request to send documents has been blocked. To resolve the problem, enable outgoing HTTP requests for the E-Document apps on the Extension Management page.'; } \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionAuth.Table.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionAuth.Table.al index d735de2598..e1cc465a0b 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionAuth.Table.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionAuth.Table.al @@ -4,7 +4,7 @@ // ------------------------------------------------------------------------------------------------ namespace Microsoft.EServices.EDocumentConnector.SignUp; -table 6380 SignUpConnectionAuth +table 6380 ConnectionAuth { Access = Internal; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetup.Table.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetup.Table.al index 69964f235f..af59bc6a08 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetup.Table.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetup.Table.al @@ -4,7 +4,7 @@ // ------------------------------------------------------------------------------------------------ namespace Microsoft.EServices.EDocumentConnector.SignUp; -table 6381 SignUpConnectionSetup +table 6381 ConnectionSetup { Access = Internal; DataPerCompany = false; @@ -28,14 +28,14 @@ table 6381 SignUpConnectionSetup field(10; "Client ID"; Guid) { Caption = 'Client ID'; - DataClassification = EndUserIdentifiableInformation; + DataClassification = CustomerContent; } field(11; "Client Secret"; Guid) { Caption = 'Client Secret'; - DataClassification = EndUserIdentifiableInformation; + DataClassification = CustomerContent; } - field(12; "Send Mode"; Enum SignUpSendMode) + field(12; "Send Mode"; Enum SendMode) { Caption = 'Send Mode'; DataClassification = CustomerContent; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al index 5227c39da9..d49482d7ea 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al @@ -7,10 +7,10 @@ namespace Microsoft.EServices.EDocumentConnector.SignUp; using System.Telemetry; using System.Environment; -page 6380 SignUpConnectionSetupCard +page 6380 ConnectionSetupCard { PageType = Card; - SourceTable = SignUpConnectionSetup; + SourceTable = ConnectionSetup; ApplicationArea = Basic, Suite; UsageCategory = None; Caption = 'E-Document External Connection Setup'; @@ -33,7 +33,7 @@ page 6380 SignUpConnectionSetupCard trigger OnValidate() begin - SignUpAuth.StorageSet(Rec."Client ID", ClientID); + Auth.StorageSet(Rec."Client ID", ClientID); end; } field(ClientSecret; ClientSecret) @@ -47,7 +47,7 @@ page 6380 SignUpConnectionSetupCard trigger OnValidate() begin - SignUpAuth.StorageSet(Rec."Client Secret", ClientSecret); + Auth.StorageSet(Rec."Client Secret", ClientSecret); end; } field(ClientTenant; ClientTenant) @@ -60,7 +60,7 @@ page 6380 SignUpConnectionSetupCard trigger OnValidate() begin - SignUpAuth.StorageSet(Rec."Client Tenant", ClientTenant); + Auth.StorageSet(Rec."Client Tenant", ClientTenant); end; } field(RootID; RootID) @@ -73,7 +73,7 @@ page 6380 SignUpConnectionSetupCard trigger OnValidate() begin - SignUpAuth.StorageSet(Rec."Root App ID", RootID); + Auth.StorageSet(Rec."Root App ID", RootID); end; } field(RootSecret; RootSecret) @@ -86,7 +86,7 @@ page 6380 SignUpConnectionSetupCard trigger OnValidate() begin - SignUpAuth.StorageSet(Rec."Root Secret", RootSecret); + Auth.StorageSet(Rec."Root Secret", RootSecret); end; } field(RootTenant; RootTenant) @@ -99,7 +99,7 @@ page 6380 SignUpConnectionSetupCard trigger OnValidate() begin - SignUpAuth.StorageSet(Rec."Root Tenant", RootTenant); + Auth.StorageSet(Rec."Root Tenant", RootTenant); end; } field(RootUrl; RootUrl) @@ -112,7 +112,7 @@ page 6380 SignUpConnectionSetupCard trigger OnValidate() begin - SignUpAuth.StorageSet(Rec."Root Market URL", RootUrl); + Auth.StorageSet(Rec."Root Market URL", RootUrl); end; } field("Authentication URL"; Rec."Authentication URL") @@ -158,10 +158,10 @@ page 6380 SignUpConnectionSetupCard trigger OnAction() begin - SignUpAuth.CreateClientCredentials(); + Auth.CreateClientCredentials(); CurrPage.Update(); SetPageVariables(); - Hyperlink(SignUpAuth.GetRootOnboardingUrl()); + Hyperlink(Auth.GetRootOnboardingUrl()); FeatureTelemetry.LogUptake('', ExternalServiceTok, Enum::"Feature Uptake Status"::"Set up"); end; } @@ -173,7 +173,7 @@ page 6380 SignUpConnectionSetupCard EnvironmentInfo: Codeunit "Environment Information"; begin IsSaaSInfrastructure := EnvironmentInfo.IsSaaSInfrastructure(); - SignUpAuth.InitConnectionSetup(); + Auth.InitConnectionSetup(); if Rec.Get() then ; SetPageVariables(); @@ -199,7 +199,7 @@ page 6380 SignUpConnectionSetupCard end; var - SignUpAuth: Codeunit SignUpAuth; + Auth: Codeunit Auth; FeatureTelemetry: Codeunit "Feature Telemetry"; [NonDebuggable] ClientID, ClientSecret, ClientTenant, ClientUrl, RootID, RootSecret, RootTenant, RootUrl : Text; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/ErrorSensitive.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/ErrorSensitive.Codeunit.al index bc11430480..25eafdafe4 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/ErrorSensitive.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/ErrorSensitive.Codeunit.al @@ -6,7 +6,7 @@ namespace Microsoft.EServices.EDocumentConnector.SignUp; using System.Azure.Identity; -codeunit 6383 SignUpErrorSensitive +codeunit 6383 ErrorSensitive { Access = Internal; Description = 'Create functions to run sensitive code that may fail out of your control but you need to keep the code going'; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/GetReadyStatus.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/GetReadyStatus.Codeunit.al index 36cf672292..92cb4f7474 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/GetReadyStatus.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/GetReadyStatus.Codeunit.al @@ -8,7 +8,7 @@ using System.Telemetry; using System.Threading; using Microsoft.EServices.EDocument; -codeunit 6384 SignUpGetReadyStatus +codeunit 6384 GetReadyStatus { TableNo = "Job Queue Entry"; Access = Internal; @@ -23,7 +23,7 @@ codeunit 6384 SignUpGetReadyStatus ProcessSentDocuments(); if IsEDocumentStatusSent() then - ScheduleEDocumentJob(Codeunit::SignUpGetReadyStatus, BlankRecordId, 300000); + ScheduleEDocumentJob(Codeunit::GetReadyStatus, BlankRecordId, 300000); end; local procedure ProcessSentDocuments() @@ -49,14 +49,14 @@ codeunit 6384 SignUpGetReadyStatus local procedure HandleResponse(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; var EDocumentServiceStatus: Record "E-Document Service Status") var - SignUpProcessing: Codeunit SignUpProcessing; + Processing: Codeunit Processing; BlankRecordId: RecordId; HttpResponse: HttpResponseMessage; HttpRequest: HttpRequestMessage; begin if GetResponse(EDocumentServiceStatus, HttpRequest, HttpResponse) then begin - SignUpProcessing.InsertLogWithIntegration(EDocument, EDocumentService, Enum::"E-Document Service Status"::Approved, 0, HttpRequest, HttpResponse); - ScheduleEDocumentJob(Codeunit::SignUpPatchSent, BlankRecordId, 300000); + Processing.InsertLogWithIntegration(EDocument, EDocumentService, Enum::"E-Document Service Status"::Approved, 0, HttpRequest, HttpResponse); + ScheduleEDocumentJob(Codeunit::PatchSent, BlankRecordId, 300000); end; end; @@ -64,7 +64,7 @@ codeunit 6384 SignUpGetReadyStatus local procedure GetResponse(var EDocumentServiceStatus: Record "E-Document Service Status"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) ReturnStatus: Boolean var EDocument: Record "E-Document"; - SignUpProcessing: Codeunit SignUpProcessing; + Processing: Codeunit Processing; TelemetryDimensions: Dictionary of [Text, Text]; begin // Commit before create document with error handling @@ -73,7 +73,7 @@ codeunit 6384 SignUpGetReadyStatus EDocument.Get(EDocumentServiceStatus."E-Document Entry No"); - if SignUpProcessing.GetDocumentSentResponse(EDocument, HttpRequest, HttpResponse) then + if Processing.GetDocumentSentResponse(EDocument, HttpRequest, HttpResponse) then ReturnStatus := true; Telemetry.LogMessage('', EDocTelemetryGetResponseScopeEndLbl, Verbosity::Normal, DataClassification::OrganizationIdentifiableInformation, TelemetryScope::All); diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/Helpers.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/Helpers.Codeunit.al index f97642792e..4b1406aba7 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/Helpers.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/Helpers.Codeunit.al @@ -6,7 +6,7 @@ namespace Microsoft.EServices.EDocumentConnector.SignUp; using System.Text; -codeunit 6385 SignUpHelpers +codeunit 6385 Helpers { Access = Internal; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationEnumExt.EnumExt.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationEnumExt.EnumExt.al index 63f5c5c08f..db4953f886 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationEnumExt.EnumExt.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationEnumExt.EnumExt.al @@ -6,11 +6,11 @@ namespace Microsoft.EServices.EDocumentConnector.SignUp; using Microsoft.EServices.EDocument; -enumextension 6380 SignUpIntegrationEnumExt extends "E-Document Integration" +enumextension 6380 IntegrationEnumExt extends "E-Document Integration" { value(6380; "ExFlow E-Invoicing") { Caption = 'ExFlow E-Invoicing'; - Implementation = "E-Document Integration" = SignUpIntegrationImpl; + Implementation = "E-Document Integration" = IntegrationImpl; } } \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationImpl.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationImpl.Codeunit.al index 577c4fe44c..0b257a5e64 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationImpl.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationImpl.Codeunit.al @@ -7,14 +7,14 @@ namespace Microsoft.EServices.EDocumentConnector.SignUp; using System.Utilities; using Microsoft.EServices.EDocument; -codeunit 6386 SignUpIntegrationImpl implements "E-Document Integration" +codeunit 6386 IntegrationImpl implements "E-Document Integration" { Access = Internal; procedure Send(var EDocument: Record "E-Document"; var TempBlob: Codeunit "Temp Blob"; var IsAsync: Boolean; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) var begin - SignUpProcessing.SendEDocument(EDocument, TempBlob, IsAsync, HttpRequest, HttpResponse); + Processing.SendEDocument(EDocument, TempBlob, IsAsync, HttpRequest, HttpResponse); end; procedure SendBatch(var EDocuments: Record "E-Document"; var TempBlob: Codeunit "Temp Blob"; var IsAsync: Boolean; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) @@ -25,12 +25,12 @@ codeunit 6386 SignUpIntegrationImpl implements "E-Document Integration" procedure GetResponse(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean begin - exit(SignUpProcessing.GetDocumentResponse(EDocument, HttpRequest, HttpResponse)); + exit(Processing.GetDocumentResponse(EDocument, HttpRequest, HttpResponse)); end; procedure GetApproval(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean begin - exit(SignUpProcessing.GetDocumentApproval(EDocument, HttpRequest, HttpResponse)); + exit(Processing.GetDocumentApproval(EDocument, HttpRequest, HttpResponse)); end; procedure Cancel(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean @@ -40,20 +40,20 @@ codeunit 6386 SignUpIntegrationImpl implements "E-Document Integration" procedure ReceiveDocument(var TempBlob: Codeunit "Temp Blob"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) begin - SignUpProcessing.ReceiveDocument(TempBlob, HttpRequest, HttpResponse); + Processing.ReceiveDocument(TempBlob, HttpRequest, HttpResponse); end; procedure GetDocumentCountInBatch(var TempBlob: Codeunit "Temp Blob"): Integer begin - exit(SignUpProcessing.GetDocumentCountInBatch(TempBlob)); + exit(Processing.GetDocumentCountInBatch(TempBlob)); end; procedure GetIntegrationSetup(var SetupPage: Integer; var SetupTable: Integer) begin - SetupPage := Page::SignUpConnectionSetupCard; - SetupTable := Database::SignUpConnectionSetup; + SetupPage := Page::ConnectionSetupCard; + SetupTable := Database::ConnectionSetup; end; var - SignUpProcessing: Codeunit SignUpProcessing; + Processing: Codeunit Processing; } \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/PatchSent.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/PatchSent.Codeunit.al index 66f637d269..c7994b9648 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/PatchSent.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/PatchSent.Codeunit.al @@ -7,14 +7,14 @@ namespace Microsoft.EServices.EDocumentConnector.SignUp; using System.Threading; using Microsoft.EServices.EDocument; -codeunit 6387 SignUpPatchSent +codeunit 6387 PatchSent { TableNo = "Job Queue Entry"; Access = Internal; trigger OnRun() var - SignUpGetReadyStatus: Codeunit SignUpGetReadyStatus; + GetReadyStatus: Codeunit GetReadyStatus; BlankRecordId: RecordId; begin if not IsEDocumentApproved() then @@ -23,7 +23,7 @@ codeunit 6387 SignUpPatchSent ProcessApprovedDocuments(); if IsEDocumentApproved() then - SignUpGetReadyStatus.ScheduleEDocumentJob(Codeunit::SignUpPatchSent, BlankRecordId, 300000); + GetReadyStatus.ScheduleEDocumentJob(Codeunit::PatchSent, BlankRecordId, 300000); end; local procedure ProcessApprovedDocuments() @@ -32,8 +32,8 @@ codeunit 6387 SignUpPatchSent EDocumentService: Record "E-Document Service"; EDocumentIntegrationLog: Record "E-Document Integration Log"; EDocument: Record "E-Document"; - SignUpAPIRequests: Codeunit SignUpAPIRequests; - SignUpProcessing: Codeunit SignUpProcessing; + APIRequests: Codeunit APIRequests; + Processing: Codeunit Processing; HttpResponse: HttpResponseMessage; HttpRequest: HttpRequestMessage; begin @@ -47,8 +47,8 @@ codeunit 6387 SignUpPatchSent EDocumentIntegrationLog.SetRange("Response Status", 204); EDocumentIntegrationLog.SetRange(Method, 'PATCH'); if EDocumentIntegrationLog.IsEmpty then - if SignUpAPIRequests.PatchADocument(EDocument, HttpRequest, HttpResponse) then - SignUpProcessing.InsertIntegrationLog(EDocument, EDocumentService, HttpRequest, HttpResponse); + if APIRequests.PatchADocument(EDocument, HttpRequest, HttpResponse) then + Processing.InsertIntegrationLog(EDocument, EDocumentService, HttpRequest, HttpResponse); until EDocumentServiceStatus.Next() = 0; end; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/Processing.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/Processing.Codeunit.al index 52f9e1f2a8..5684cc5b2c 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/Processing.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/Processing.Codeunit.al @@ -9,7 +9,7 @@ using System.Telemetry; using System.Text; using System.Utilities; -codeunit 6388 SignUpProcessing +codeunit 6388 Processing { Access = Internal; Permissions = tabledata "E-Document" = m, @@ -50,14 +50,14 @@ codeunit 6388 SignUpProcessing var EDocumentService: Record "E-Document Service"; EDocumentServiceStatus: Record "E-Document Service Status"; - SignUpAPIRequests: Codeunit SignUpAPIRequests; - SignUpProcessing: Codeunit SignUpProcessing; + APIRequests: Codeunit APIRequests; + Processing: Codeunit Processing; HttpContentResponse: HttpContent; Status, StatusDescription : Text; begin EDocumentHelper.GetEdocumentService(EDocument, EdocumentService); EDocumentServiceStatus.Get(EDocument."Entry No", EdocumentService.Code); - SignUpAPIRequests.GetSentDocumentStatus(EDocument, HttpRequestMessage, HttpResponseMessage); + APIRequests.GetSentDocumentStatus(EDocument, HttpRequestMessage, HttpResponseMessage); HttpContentResponse := HttpResponseMessage.Content; if ParseGetADocumentApprovalResponse(HttpContentResponse, Status, StatusDescription) then case Status of @@ -67,7 +67,7 @@ codeunit 6388 SignUpProcessing begin if StatusDescription <> '' then EDocumentErrorHelper.LogSimpleErrorMessage(EDocument, 'Reason: ' + StatusDescription); - SignUpProcessing.InsertLogWithIntegration(EDocument, EDocumentService, Enum::"E-Document Service Status"::Rejected, 0, HttpRequestMessage, HttpResponseMessage); + Processing.InsertLogWithIntegration(EDocument, EDocumentService, Enum::"E-Document Service Status"::Rejected, 0, HttpRequestMessage, HttpResponseMessage); exit(false); end; end; @@ -78,9 +78,9 @@ codeunit 6388 SignUpProcessing var EDocumentService: Record "E-Document Service"; EDocumentServiceStatus: Record "E-Document Service Status"; - SignUpAPIRequests: Codeunit SignUpAPIRequests; - SignUpGetReadyStatus: Codeunit SignUpGetReadyStatus; - SignUpProcessing: Codeunit SignUpProcessing; + APIRequests: Codeunit APIRequests; + GetReadyStatus: Codeunit GetReadyStatus; + Processing: Codeunit Processing; BlankRecordId: RecordId; HttpContentResponse: HttpContent; Status, StatusDescription : Text; @@ -90,23 +90,23 @@ codeunit 6388 SignUpProcessing if not (EDocumentServiceStatus.Status in [EDocumentServiceStatus.Status::Sent, EDocumentServiceStatus.Status::"Pending Response"]) then Error(GetApprovalCheckStatusErr, EDocumentServiceStatus.Status); - SignUpAPIRequests.GetSentDocumentStatus(EDocument, HttpRequestMessage, HttpResponseMessage); + APIRequests.GetSentDocumentStatus(EDocument, HttpRequestMessage, HttpResponseMessage); HttpContentResponse := HttpResponseMessage.Content; if ParseGetADocumentApprovalResponse(HttpContentResponse, Status, StatusDescription) then case Status of 'Ready': begin if EDocumentServiceStatus.Status = EDocumentServiceStatus.Status::Approved then - SignUpGetReadyStatus.ScheduleEDocumentJob(Codeunit::SignUpPatchSent, BlankRecordId, 300000) + GetReadyStatus.ScheduleEDocumentJob(Codeunit::PatchSent, BlankRecordId, 300000) else - SignUpGetReadyStatus.ScheduleEDocumentJob(Codeunit::SignUpGetReadyStatus, BlankRecordId, 300000); + GetReadyStatus.ScheduleEDocumentJob(Codeunit::GetReadyStatus, BlankRecordId, 300000); exit(true); end; 'Failed': begin if StatusDescription <> '' then EDocumentErrorHelper.LogSimpleErrorMessage(EDocument, 'Reason: ' + StatusDescription); - SignUpProcessing.InsertLogWithIntegration(EDocument, EDocumentService, Enum::"E-Document Service Status"::Rejected, 0, HttpRequestMessage, HttpResponseMessage); + Processing.InsertLogWithIntegration(EDocument, EDocumentService, Enum::"E-Document Service Status"::Rejected, 0, HttpRequestMessage, HttpResponseMessage); exit(false); end; end; @@ -118,7 +118,7 @@ codeunit 6388 SignUpProcessing ContentData: Text; OutStream: OutStream; begin - if not SignUpConnection.GetReceivedDocuments(HttpRequest, HttpResponse, true) then + if not Connection.GetReceivedDocuments(HttpRequest, HttpResponse, true) then exit; HttpResponse.Content.ReadAs(ContentData); @@ -142,7 +142,7 @@ codeunit 6388 SignUpProcessing var HttpContentResponse: HttpContent; begin - SignUpConnection.HandleSendFilePostRequest(TempBlob, EDocument, HttpRequest, HttpResponse, true); + Connection.HandleSendFilePostRequest(TempBlob, EDocument, HttpRequest, HttpResponse, true); HttpContentResponse := HttpResponse.Content; SetEDocumentFileID(EDocument."Entry No", ParseSendFileResponse(HttpContentResponse)); end; @@ -192,7 +192,7 @@ codeunit 6388 SignUpProcessing var ErrorDescription: Text; begin - if not SignUpConnection.CheckDocumentStatus(EDocument, HttpRequestMessage, HttpResponse, true) then + if not Connection.CheckDocumentStatus(EDocument, HttpRequestMessage, HttpResponse, true) then exit(false); if DocumentHasErrorOrProcessing(EDocument, HttpResponse, ErrorDescription) then @@ -207,7 +207,7 @@ codeunit 6388 SignUpProcessing Result: Text; Value: Text; begin - Result := SignUpHelpers.ParseJsonString(HttpContentResponse); + Result := Helpers.ParseJsonString(HttpContentResponse); if Result = '' then exit(''); @@ -236,13 +236,13 @@ codeunit 6388 SignUpProcessing EDocumentService: Record "E-Document Service"; EDocumentServiceStatus: Record "E-Document Service Status"; JsonManagement: Codeunit "JSON Management"; - SignUpGetReadyStatus: Codeunit SignUpGetReadyStatus; + GetReadyStatus: Codeunit GetReadyStatus; BlankRecordId: RecordId; HttpContentResponse: HttpContent; Result, Value : Text; begin HttpContentResponse := HttpResponse.Content; - Result := SignUpHelpers.ParseJsonString(HttpContentResponse); + Result := Helpers.ParseJsonString(HttpContentResponse); if Result = '' then exit(true); @@ -252,7 +252,7 @@ codeunit 6388 SignUpProcessing JsonManagement.GetArrayPropertyValueAsStringByName('status', Value); if Value in ['Sent'] then begin - SignUpGetReadyStatus.ScheduleEDocumentJob(Codeunit::SignUpGetReadyStatus, BlankRecordId, 120000); + GetReadyStatus.ScheduleEDocumentJob(Codeunit::GetReadyStatus, BlankRecordId, 120000); exit(false); end; @@ -260,9 +260,9 @@ codeunit 6388 SignUpProcessing EDocumentHelper.GetEdocumentService(EDocument, EDocumentService); EDocumentServiceStatus.Get(EDocument."Entry No", EdocumentService.Code); if EDocumentServiceStatus.Status = EDocumentServiceStatus.Status::Approved then - SignUpGetReadyStatus.ScheduleEDocumentJob(Codeunit::SignUpPatchSent, BlankRecordId, 180000) + GetReadyStatus.ScheduleEDocumentJob(Codeunit::PatchSent, BlankRecordId, 180000) else - SignUpGetReadyStatus.ScheduleEDocumentJob(Codeunit::SignUpGetReadyStatus, BlankRecordId, 120000); + GetReadyStatus.ScheduleEDocumentJob(Codeunit::GetReadyStatus, BlankRecordId, 120000); exit(false); end; @@ -280,7 +280,7 @@ codeunit 6388 SignUpProcessing JsonManagement: Codeunit "JSON Management"; Result: Text; begin - Result := SignUpHelpers.ParseJsonString(HttpContentResponse); + Result := Helpers.ParseJsonString(HttpContentResponse); if Result = '' then exit(false); @@ -332,7 +332,7 @@ codeunit 6388 SignUpProcessing exit; end; - SignUpConnection.HandleGetTargetDocumentRequest(DocumentId, LocalHttpRequest, LocalHttpResponse, false); + Connection.HandleGetTargetDocumentRequest(DocumentId, LocalHttpRequest, LocalHttpResponse, false); EDocumentLogHelper.InsertIntegrationLog(EDocument, EDocumentService, LocalHttpRequest, LocalHttpResponse); LocalHttpResponse.Content.ReadAs(ContentData); @@ -348,7 +348,7 @@ codeunit 6388 SignUpProcessing DocumentOutStream.WriteText(ContentData); EDocument."Document Id" := CopyStr(DocumentId, 1, MaxStrLen(EDocument."Document Id")); EDocumentLogHelper.InsertLog(EDocument, EDocumentService, TempBlob, "E-Document Service Status"::Imported); - SignUpConnection.RemoveDocumentFromReceived(EDocument, LocalHttpRequest, LocalHttpResponse, true); + Connection.RemoveDocumentFromReceived(EDocument, LocalHttpRequest, LocalHttpResponse, true); EDocumentLogHelper.InsertIntegrationLog(EDocument, EDocumentService, LocalHttpRequest, LocalHttpResponse); end; @@ -561,8 +561,8 @@ codeunit 6388 SignUpProcessing end; var - SignUpConnection: Codeunit SignUpConnection; - SignUpHelpers: Codeunit SignUpHelpers; + Connection: Codeunit Connection; + Helpers: Codeunit Helpers; EDocumentHelper: Codeunit "E-Document Helper"; EDocumentLogHelper: Codeunit "E-Document Log Helper"; EDocumentErrorHelper: Codeunit "E-Document Error Helper"; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/SendMode.Enum.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/SendMode.Enum.al index 22915cce76..8dd530ae19 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/SendMode.Enum.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/SendMode.Enum.al @@ -4,7 +4,7 @@ // ------------------------------------------------------------------------------------------------ namespace Microsoft.EServices.EDocumentConnector.SignUp; -enum 6380 SignUpSendMode +enum 6380 SendMode { Access = Internal; From 9eb37045c2101ee5b0aa63cda0754f70cf3373a5 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Tue, 24 Sep 2024 10:46:43 +0200 Subject: [PATCH 09/31] Resolve Build Conflict in GitHub - Rename --- .../{Processing.Codeunit.al => SignUpProcessing.Codeunit.al} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Apps/W1/EDocumentsConnector/app/src/SignUp/{Processing.Codeunit.al => SignUpProcessing.Codeunit.al} (100%) diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/Processing.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/SignUpProcessing.Codeunit.al similarity index 100% rename from Apps/W1/EDocumentsConnector/app/src/SignUp/Processing.Codeunit.al rename to Apps/W1/EDocumentsConnector/app/src/SignUp/SignUpProcessing.Codeunit.al From 94266e2e72ce3a074b6bc3d9fa15b35716470975 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Tue, 24 Sep 2024 10:51:09 +0200 Subject: [PATCH 10/31] Resolve Build Conflict in GitHub - Refactor Codeunit Processing --- .../Permissions/SignUpEDocObjects.PermissionSet.al | 2 +- .../app/src/SignUp/Auth.Codeunit.al | 12 ++++++------ .../app/src/SignUp/GetReadyStatus.Codeunit.al | 8 ++++---- .../app/src/SignUp/IntegrationImpl.Codeunit.al | 12 ++++++------ .../app/src/SignUp/PatchSent.Codeunit.al | 4 ++-- .../app/src/SignUp/SignUpProcessing.Codeunit.al | 10 +++++----- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocObjects.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocObjects.PermissionSet.al index 9dad400f69..1a071065c4 100644 --- a/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocObjects.PermissionSet.al +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocObjects.PermissionSet.al @@ -13,7 +13,7 @@ permissionset 6380 "SignUpEDoc. - Objects" table ConnectionAuth = X, page ConnectionSetupCard = X, codeunit IntegrationImpl = X, - codeunit Processing = X, + codeunit SignUpProcessing = X, codeunit Auth = X, codeunit APIRequests = X, codeunit Connection = X, diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/Auth.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/Auth.Codeunit.al index 43e627b37a..035d32ef13 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/Auth.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/Auth.Codeunit.al @@ -14,14 +14,14 @@ codeunit 6381 Auth procedure InitConnectionSetup() var - lConnectionSetup: Record ConnectionSetup; + LConnectionSetup: Record ConnectionSetup; begin - if lConnectionSetup.Get() then + if LConnectionSetup.Get() then exit; - lConnectionSetup."Authentication URL" := AuthURLTxt; - lConnectionSetup.ServiceURL := ProdServiceAPITxt; - StorageSet(lConnectionSetup."Client Tenant", ProdTenantIdTxt); - lConnectionSetup.Insert(); + LConnectionSetup."Authentication URL" := AuthURLTxt; + LConnectionSetup.ServiceURL := ProdServiceAPITxt; + StorageSet(LConnectionSetup."Client Tenant", ProdTenantIdTxt); + LConnectionSetup.Insert(); end; procedure GetRootOnboardingUrl(): Text diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/GetReadyStatus.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/GetReadyStatus.Codeunit.al index 92cb4f7474..9254b3f20a 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/GetReadyStatus.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/GetReadyStatus.Codeunit.al @@ -49,13 +49,13 @@ codeunit 6384 GetReadyStatus local procedure HandleResponse(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; var EDocumentServiceStatus: Record "E-Document Service Status") var - Processing: Codeunit Processing; + SignUpProcessing: Codeunit SignUpProcessing; BlankRecordId: RecordId; HttpResponse: HttpResponseMessage; HttpRequest: HttpRequestMessage; begin if GetResponse(EDocumentServiceStatus, HttpRequest, HttpResponse) then begin - Processing.InsertLogWithIntegration(EDocument, EDocumentService, Enum::"E-Document Service Status"::Approved, 0, HttpRequest, HttpResponse); + SignUpProcessing.InsertLogWithIntegration(EDocument, EDocumentService, Enum::"E-Document Service Status"::Approved, 0, HttpRequest, HttpResponse); ScheduleEDocumentJob(Codeunit::PatchSent, BlankRecordId, 300000); end; @@ -64,7 +64,7 @@ codeunit 6384 GetReadyStatus local procedure GetResponse(var EDocumentServiceStatus: Record "E-Document Service Status"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) ReturnStatus: Boolean var EDocument: Record "E-Document"; - Processing: Codeunit Processing; + SignUpProcessing: Codeunit SignUpProcessing; TelemetryDimensions: Dictionary of [Text, Text]; begin // Commit before create document with error handling @@ -73,7 +73,7 @@ codeunit 6384 GetReadyStatus EDocument.Get(EDocumentServiceStatus."E-Document Entry No"); - if Processing.GetDocumentSentResponse(EDocument, HttpRequest, HttpResponse) then + if SignUpProcessing.GetDocumentSentResponse(EDocument, HttpRequest, HttpResponse) then ReturnStatus := true; Telemetry.LogMessage('', EDocTelemetryGetResponseScopeEndLbl, Verbosity::Normal, DataClassification::OrganizationIdentifiableInformation, TelemetryScope::All); diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationImpl.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationImpl.Codeunit.al index 0b257a5e64..ab4eadc630 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationImpl.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationImpl.Codeunit.al @@ -14,7 +14,7 @@ codeunit 6386 IntegrationImpl implements "E-Document Integration" procedure Send(var EDocument: Record "E-Document"; var TempBlob: Codeunit "Temp Blob"; var IsAsync: Boolean; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) var begin - Processing.SendEDocument(EDocument, TempBlob, IsAsync, HttpRequest, HttpResponse); + SignUpProcessing.SendEDocument(EDocument, TempBlob, IsAsync, HttpRequest, HttpResponse); end; procedure SendBatch(var EDocuments: Record "E-Document"; var TempBlob: Codeunit "Temp Blob"; var IsAsync: Boolean; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) @@ -25,12 +25,12 @@ codeunit 6386 IntegrationImpl implements "E-Document Integration" procedure GetResponse(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean begin - exit(Processing.GetDocumentResponse(EDocument, HttpRequest, HttpResponse)); + exit(SignUpProcessing.GetDocumentResponse(EDocument, HttpRequest, HttpResponse)); end; procedure GetApproval(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean begin - exit(Processing.GetDocumentApproval(EDocument, HttpRequest, HttpResponse)); + exit(SignUpProcessing.GetDocumentApproval(EDocument, HttpRequest, HttpResponse)); end; procedure Cancel(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean @@ -40,12 +40,12 @@ codeunit 6386 IntegrationImpl implements "E-Document Integration" procedure ReceiveDocument(var TempBlob: Codeunit "Temp Blob"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) begin - Processing.ReceiveDocument(TempBlob, HttpRequest, HttpResponse); + SignUpProcessing.ReceiveDocument(TempBlob, HttpRequest, HttpResponse); end; procedure GetDocumentCountInBatch(var TempBlob: Codeunit "Temp Blob"): Integer begin - exit(Processing.GetDocumentCountInBatch(TempBlob)); + exit(SignUpProcessing.GetDocumentCountInBatch(TempBlob)); end; procedure GetIntegrationSetup(var SetupPage: Integer; var SetupTable: Integer) @@ -55,5 +55,5 @@ codeunit 6386 IntegrationImpl implements "E-Document Integration" end; var - Processing: Codeunit Processing; + SignUpProcessing: Codeunit SignUpProcessing; } \ No newline at end of file diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/PatchSent.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/PatchSent.Codeunit.al index c7994b9648..144fa8b40e 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/PatchSent.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/PatchSent.Codeunit.al @@ -33,7 +33,7 @@ codeunit 6387 PatchSent EDocumentIntegrationLog: Record "E-Document Integration Log"; EDocument: Record "E-Document"; APIRequests: Codeunit APIRequests; - Processing: Codeunit Processing; + SignUpProcessing: Codeunit SignUpProcessing; HttpResponse: HttpResponseMessage; HttpRequest: HttpRequestMessage; begin @@ -48,7 +48,7 @@ codeunit 6387 PatchSent EDocumentIntegrationLog.SetRange(Method, 'PATCH'); if EDocumentIntegrationLog.IsEmpty then if APIRequests.PatchADocument(EDocument, HttpRequest, HttpResponse) then - Processing.InsertIntegrationLog(EDocument, EDocumentService, HttpRequest, HttpResponse); + SignUpProcessing.InsertIntegrationLog(EDocument, EDocumentService, HttpRequest, HttpResponse); until EDocumentServiceStatus.Next() = 0; end; diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/SignUpProcessing.Codeunit.al b/Apps/W1/EDocumentsConnector/app/src/SignUp/SignUpProcessing.Codeunit.al index 5684cc5b2c..fa91f382e4 100644 --- a/Apps/W1/EDocumentsConnector/app/src/SignUp/SignUpProcessing.Codeunit.al +++ b/Apps/W1/EDocumentsConnector/app/src/SignUp/SignUpProcessing.Codeunit.al @@ -9,7 +9,7 @@ using System.Telemetry; using System.Text; using System.Utilities; -codeunit 6388 Processing +codeunit 6388 SignUpProcessing { Access = Internal; Permissions = tabledata "E-Document" = m, @@ -51,7 +51,7 @@ codeunit 6388 Processing EDocumentService: Record "E-Document Service"; EDocumentServiceStatus: Record "E-Document Service Status"; APIRequests: Codeunit APIRequests; - Processing: Codeunit Processing; + SignUpProcessing: Codeunit SignUpProcessing; HttpContentResponse: HttpContent; Status, StatusDescription : Text; begin @@ -67,7 +67,7 @@ codeunit 6388 Processing begin if StatusDescription <> '' then EDocumentErrorHelper.LogSimpleErrorMessage(EDocument, 'Reason: ' + StatusDescription); - Processing.InsertLogWithIntegration(EDocument, EDocumentService, Enum::"E-Document Service Status"::Rejected, 0, HttpRequestMessage, HttpResponseMessage); + SignUpProcessing.InsertLogWithIntegration(EDocument, EDocumentService, Enum::"E-Document Service Status"::Rejected, 0, HttpRequestMessage, HttpResponseMessage); exit(false); end; end; @@ -80,7 +80,7 @@ codeunit 6388 Processing EDocumentServiceStatus: Record "E-Document Service Status"; APIRequests: Codeunit APIRequests; GetReadyStatus: Codeunit GetReadyStatus; - Processing: Codeunit Processing; + SignUpProcessing: Codeunit SignUpProcessing; BlankRecordId: RecordId; HttpContentResponse: HttpContent; Status, StatusDescription : Text; @@ -106,7 +106,7 @@ codeunit 6388 Processing begin if StatusDescription <> '' then EDocumentErrorHelper.LogSimpleErrorMessage(EDocument, 'Reason: ' + StatusDescription); - Processing.InsertLogWithIntegration(EDocument, EDocumentService, Enum::"E-Document Service Status"::Rejected, 0, HttpRequestMessage, HttpResponseMessage); + SignUpProcessing.InsertLogWithIntegration(EDocument, EDocumentService, Enum::"E-Document Service Status"::Rejected, 0, HttpRequestMessage, HttpResponseMessage); exit(false); end; end; From def717600af21165b403e3e052fcb700f489c730 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Wed, 25 Sep 2024 10:22:45 +0200 Subject: [PATCH 11/31] Relocate To Own App - Move Files --- .../SignUp/app/src}/APIRequests.Codeunit.al | 0 .../SignUp/app/src}/Auth.Codeunit.al | 0 .../SignUp/app/src}/Connection.Codeunit.al | 0 .../SignUp/app/src}/ConnectionAuth.Table.al | 0 .../SignUp/app/src}/ConnectionSetup.Table.al | 0 .../SignUp/app/src}/ConnectionSetupCard.Page.al | 0 .../SignUp/app/src}/ErrorSensitive.Codeunit.al | 0 .../SignUp/app/src/Extensions}/IntegrationEnumExt.EnumExt.al | 0 .../SignUp/app/src}/GetReadyStatus.Codeunit.al | 0 .../SignUp/app/src}/Helpers.Codeunit.al | 0 .../SignUp/app/src}/IntegrationImpl.Codeunit.al | 0 .../SignUp/app/src}/PatchSent.Codeunit.al | 0 .../SignUp}/app/src/Permissions/SignUpEDocEdit.PermissionSet.al | 0 .../app/src/Permissions/SignUpEDocObjects.PermissionSet.al | 0 .../SignUp}/app/src/Permissions/SignUpEDocRead.PermissionSet.al | 0 .../SignUp/app/src}/SendMode.Enum.al | 0 .../SignUp/app/src}/SignUpProcessing.Codeunit.al | 0 17 files changed, 0 insertions(+), 0 deletions(-) rename Apps/W1/{EDocumentsConnector/app/src/SignUp => EDocumentConnectors/SignUp/app/src}/APIRequests.Codeunit.al (100%) rename Apps/W1/{EDocumentsConnector/app/src/SignUp => EDocumentConnectors/SignUp/app/src}/Auth.Codeunit.al (100%) rename Apps/W1/{EDocumentsConnector/app/src/SignUp => EDocumentConnectors/SignUp/app/src}/Connection.Codeunit.al (100%) rename Apps/W1/{EDocumentsConnector/app/src/SignUp => EDocumentConnectors/SignUp/app/src}/ConnectionAuth.Table.al (100%) rename Apps/W1/{EDocumentsConnector/app/src/SignUp => EDocumentConnectors/SignUp/app/src}/ConnectionSetup.Table.al (100%) rename Apps/W1/{EDocumentsConnector/app/src/SignUp => EDocumentConnectors/SignUp/app/src}/ConnectionSetupCard.Page.al (100%) rename Apps/W1/{EDocumentsConnector/app/src/SignUp => EDocumentConnectors/SignUp/app/src}/ErrorSensitive.Codeunit.al (100%) rename Apps/W1/{EDocumentsConnector/app/src/SignUp => EDocumentConnectors/SignUp/app/src/Extensions}/IntegrationEnumExt.EnumExt.al (100%) rename Apps/W1/{EDocumentsConnector/app/src/SignUp => EDocumentConnectors/SignUp/app/src}/GetReadyStatus.Codeunit.al (100%) rename Apps/W1/{EDocumentsConnector/app/src/SignUp => EDocumentConnectors/SignUp/app/src}/Helpers.Codeunit.al (100%) rename Apps/W1/{EDocumentsConnector/app/src/SignUp => EDocumentConnectors/SignUp/app/src}/IntegrationImpl.Codeunit.al (100%) rename Apps/W1/{EDocumentsConnector/app/src/SignUp => EDocumentConnectors/SignUp/app/src}/PatchSent.Codeunit.al (100%) rename Apps/W1/{EDocumentsConnector => EDocumentConnectors/SignUp}/app/src/Permissions/SignUpEDocEdit.PermissionSet.al (100%) rename Apps/W1/{EDocumentsConnector => EDocumentConnectors/SignUp}/app/src/Permissions/SignUpEDocObjects.PermissionSet.al (100%) rename Apps/W1/{EDocumentsConnector => EDocumentConnectors/SignUp}/app/src/Permissions/SignUpEDocRead.PermissionSet.al (100%) rename Apps/W1/{EDocumentsConnector/app/src/SignUp => EDocumentConnectors/SignUp/app/src}/SendMode.Enum.al (100%) rename Apps/W1/{EDocumentsConnector/app/src/SignUp => EDocumentConnectors/SignUp/app/src}/SignUpProcessing.Codeunit.al (100%) diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/APIRequests.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al similarity index 100% rename from Apps/W1/EDocumentsConnector/app/src/SignUp/APIRequests.Codeunit.al rename to Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/Auth.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Auth.Codeunit.al similarity index 100% rename from Apps/W1/EDocumentsConnector/app/src/SignUp/Auth.Codeunit.al rename to Apps/W1/EDocumentConnectors/SignUp/app/src/Auth.Codeunit.al diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/Connection.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Connection.Codeunit.al similarity index 100% rename from Apps/W1/EDocumentsConnector/app/src/SignUp/Connection.Codeunit.al rename to Apps/W1/EDocumentConnectors/SignUp/app/src/Connection.Codeunit.al diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionAuth.Table.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/ConnectionAuth.Table.al similarity index 100% rename from Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionAuth.Table.al rename to Apps/W1/EDocumentConnectors/SignUp/app/src/ConnectionAuth.Table.al diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetup.Table.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/ConnectionSetup.Table.al similarity index 100% rename from Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetup.Table.al rename to Apps/W1/EDocumentConnectors/SignUp/app/src/ConnectionSetup.Table.al diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/ConnectionSetupCard.Page.al similarity index 100% rename from Apps/W1/EDocumentsConnector/app/src/SignUp/ConnectionSetupCard.Page.al rename to Apps/W1/EDocumentConnectors/SignUp/app/src/ConnectionSetupCard.Page.al diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/ErrorSensitive.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/ErrorSensitive.Codeunit.al similarity index 100% rename from Apps/W1/EDocumentsConnector/app/src/SignUp/ErrorSensitive.Codeunit.al rename to Apps/W1/EDocumentConnectors/SignUp/app/src/ErrorSensitive.Codeunit.al diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationEnumExt.EnumExt.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Extensions/IntegrationEnumExt.EnumExt.al similarity index 100% rename from Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationEnumExt.EnumExt.al rename to Apps/W1/EDocumentConnectors/SignUp/app/src/Extensions/IntegrationEnumExt.EnumExt.al diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/GetReadyStatus.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/GetReadyStatus.Codeunit.al similarity index 100% rename from Apps/W1/EDocumentsConnector/app/src/SignUp/GetReadyStatus.Codeunit.al rename to Apps/W1/EDocumentConnectors/SignUp/app/src/GetReadyStatus.Codeunit.al diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/Helpers.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Helpers.Codeunit.al similarity index 100% rename from Apps/W1/EDocumentsConnector/app/src/SignUp/Helpers.Codeunit.al rename to Apps/W1/EDocumentConnectors/SignUp/app/src/Helpers.Codeunit.al diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationImpl.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/IntegrationImpl.Codeunit.al similarity index 100% rename from Apps/W1/EDocumentsConnector/app/src/SignUp/IntegrationImpl.Codeunit.al rename to Apps/W1/EDocumentConnectors/SignUp/app/src/IntegrationImpl.Codeunit.al diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/PatchSent.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/PatchSent.Codeunit.al similarity index 100% rename from Apps/W1/EDocumentsConnector/app/src/SignUp/PatchSent.Codeunit.al rename to Apps/W1/EDocumentConnectors/SignUp/app/src/PatchSent.Codeunit.al diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocEdit.PermissionSet.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/SignUpEDocEdit.PermissionSet.al similarity index 100% rename from Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocEdit.PermissionSet.al rename to Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/SignUpEDocEdit.PermissionSet.al diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocObjects.PermissionSet.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/SignUpEDocObjects.PermissionSet.al similarity index 100% rename from Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocObjects.PermissionSet.al rename to Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/SignUpEDocObjects.PermissionSet.al diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocRead.PermissionSet.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/SignUpEDocRead.PermissionSet.al similarity index 100% rename from Apps/W1/EDocumentsConnector/app/src/Permissions/SignUpEDocRead.PermissionSet.al rename to Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/SignUpEDocRead.PermissionSet.al diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/SendMode.Enum.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/SendMode.Enum.al similarity index 100% rename from Apps/W1/EDocumentsConnector/app/src/SignUp/SendMode.Enum.al rename to Apps/W1/EDocumentConnectors/SignUp/app/src/SendMode.Enum.al diff --git a/Apps/W1/EDocumentsConnector/app/src/SignUp/SignUpProcessing.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/SignUpProcessing.Codeunit.al similarity index 100% rename from Apps/W1/EDocumentsConnector/app/src/SignUp/SignUpProcessing.Codeunit.al rename to Apps/W1/EDocumentConnectors/SignUp/app/src/SignUpProcessing.Codeunit.al From 381137015addf5a44dbfb8e34c15195a9710afdd Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Wed, 25 Sep 2024 12:43:28 +0200 Subject: [PATCH 12/31] Refactor - Rename Files --- .../{SignUpEDocEdit.PermissionSet.al => Edit.PermissionSet.al} | 0 ...ignUpEDocObjects.PermissionSet.al => Objects.PermissionSet.al} | 0 .../{SignUpEDocRead.PermissionSet.al => Read.PermissionSet.al} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/{SignUpEDocEdit.PermissionSet.al => Edit.PermissionSet.al} (100%) rename Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/{SignUpEDocObjects.PermissionSet.al => Objects.PermissionSet.al} (100%) rename Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/{SignUpEDocRead.PermissionSet.al => Read.PermissionSet.al} (100%) diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/SignUpEDocEdit.PermissionSet.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/Edit.PermissionSet.al similarity index 100% rename from Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/SignUpEDocEdit.PermissionSet.al rename to Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/Edit.PermissionSet.al diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/SignUpEDocObjects.PermissionSet.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/Objects.PermissionSet.al similarity index 100% rename from Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/SignUpEDocObjects.PermissionSet.al rename to Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/Objects.PermissionSet.al diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/SignUpEDocRead.PermissionSet.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/Read.PermissionSet.al similarity index 100% rename from Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/SignUpEDocRead.PermissionSet.al rename to Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/Read.PermissionSet.al From 17944a29538f4acee7038bcf383224da816def69 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Wed, 25 Sep 2024 12:45:51 +0200 Subject: [PATCH 13/31] Refactor - Add app.json --- .../EDocumentConnectors/SignUp/app/app.json | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Apps/W1/EDocumentConnectors/SignUp/app/app.json diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/app.json b/Apps/W1/EDocumentConnectors/SignUp/app/app.json new file mode 100644 index 0000000000..5d02eb4470 --- /dev/null +++ b/Apps/W1/EDocumentConnectors/SignUp/app/app.json @@ -0,0 +1,47 @@ +{ + "id": "b56171bd-9a8e-47ad-a527-99f476d5af83", + "name": "E-Document Connector - SignUp", + "publisher": "Microsoft", + "brief": "E-Document Connector - SignUp", + "description": "E-Document Connector - SignUp", + "version": "26.0.0.0", + "privacyStatement": "https://go.microsoft.com/fwlink/?LinkId=724009", + "EULA": "https://go.microsoft.com/fwlink/?linkid=2009120", + "help": "https://go.microsoft.com/fwlink/?linkid=2204541", + "url": "https://go.microsoft.com/fwlink/?LinkId=724011", + "logo": "ExtensionLogo.png", + "contextSensitiveHelpUrl": "https://go.microsoft.com/fwlink/?linkid=2206603", + "dependencies": [ + { + "id": "e1d97edc-c239-46b4-8d84-6368bdf67c8b", + "name": "E-Document Core", + "publisher": "Microsoft", + "version": "26.0.0.0" + }, + { + "id": "d852a468-263e-49e5-bfda-f09e33342b89", + "name": "E-Documents Connector with External Endpoints", + "publisher": "Microsoft", + "version": "26.0.0.0" + } + ], + "internalsVisibleTo": [], + "screenshots": [], + "platform": "26.0.0.0", + "idRanges": [ + { + "from": 6380, + "to": 6389 + } + ], + "resourceExposurePolicy": { + "allowDebugging": true, + "allowDownloadingSource": true, + "includeSourceInSymbolFile": true + }, + "application": "26.0.0.0", + "target": "OnPrem", + "features": [ + "TranslationFile" + ] +} \ No newline at end of file From 6cdeaeaf12baa3ff6fe4010ccabfb4debb008537 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Wed, 25 Sep 2024 12:46:22 +0200 Subject: [PATCH 14/31] Refactor - Restore Original Objects --- .../app/src/Permissions/EDocConnectorEdit.PermissionSet.al | 3 +-- .../app/src/Permissions/EDocConnectorObjects.PermissionSet.al | 1 - .../app/src/Permissions/EDocConnectorRead.PermissionSet.al | 3 +-- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorEdit.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorEdit.PermissionSet.al index a55382fbf8..88f0f656e6 100644 --- a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorEdit.PermissionSet.al +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorEdit.PermissionSet.al @@ -8,8 +8,7 @@ permissionset 6361 "EDocConnector - Edit" { Access = Public; Assignable = true; - IncludedPermissionSets = "EDocConnector - Read", - Microsoft.EServices.EDocumentConnector.SignUp."SignUpEDoc. - Edit"; + IncludedPermissionSets = "EDocConnector - Read"; Permissions = tabledata "E-Doc. Ext. Connection Setup" = IM, tabledata Microsoft.EServices.EDocumentConnector.Avalara."Connection Setup" = imd; diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorObjects.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorObjects.PermissionSet.al index 0a1e7a24aa..f5fb6cb8e0 100644 --- a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorObjects.PermissionSet.al +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorObjects.PermissionSet.al @@ -8,7 +8,6 @@ permissionset 6363 "EDoc. Connector Objects" { Access = Public; Assignable = false; - IncludedPermissionSets = Microsoft.EServices.EDocumentConnector.SignUp."SignUpEDoc. - Objects"; Permissions = table "E-Doc. Ext. Connection Setup" = X, page "EDoc Ext Connection Setup Card" = X, diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al index 0086239cfa..1d01f7b465 100644 --- a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al @@ -8,8 +8,7 @@ permissionset 6362 "EDocConnector - Read" { Access = Public; Assignable = true; - IncludedPermissionSets = "EDoc. Connector Objects", - Microsoft.EServices.EDocumentConnector.SignUp."SignUpEDoc. - Read"; + IncludedPermissionSets = "EDoc. Connector Objects"; Permissions = tabledata "E-Doc. Ext. Connection Setup" = R, tabledata Microsoft.EServices.EDocumentConnector.Avalara."Connection Setup" = r; From 4382237430d89de68c780ab5ad43c1dda88221a1 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Wed, 25 Sep 2024 12:51:39 +0200 Subject: [PATCH 15/31] Refactor - Rename Processing --- .../src/{SignUpProcessing.Codeunit.al => Processing.Codeunit.al} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Apps/W1/EDocumentConnectors/SignUp/app/src/{SignUpProcessing.Codeunit.al => Processing.Codeunit.al} (100%) diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/SignUpProcessing.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al similarity index 100% rename from Apps/W1/EDocumentConnectors/SignUp/app/src/SignUpProcessing.Codeunit.al rename to Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al From 7bd134c511796e93654fe93961bdd942e8c3a5eb Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Wed, 25 Sep 2024 12:54:21 +0200 Subject: [PATCH 16/31] Refactor - Permission Extensions, Object Rename --- .../SignUp/app/src/Permissions/Edit.PermissionSet.al | 9 +++++---- .../app/src/Permissions/Objects.PermissionSet.al | 5 +++-- .../SignUp/app/src/Permissions/Read.PermissionSet.al | 9 +++++---- .../SignUpEDocConnectorEdit.PermissionSetExt.al | 11 +++++++++++ .../SignUpEDocConnectorRead.PermissionSetExt.al | 11 +++++++++++ 5 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/SignUpEDocConnectorEdit.PermissionSetExt.al create mode 100644 Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/SignUpEDocConnectorRead.PermissionSetExt.al diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/Edit.PermissionSet.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/Edit.PermissionSet.al index eac95d8021..b017d9b5e7 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/Edit.PermissionSet.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/Edit.PermissionSet.al @@ -4,12 +4,13 @@ // ------------------------------------------------------------------------------------------------ namespace Microsoft.EServices.EDocumentConnector.SignUp; -permissionset 6382 "SignUpEDoc. - Edit" +permissionset 6382 Edit { Access = Internal; Assignable = false; - IncludedPermissionSets = "SignUpEDoc. - Read"; + Caption = 'SignUp E-Document Connector - Edit'; + IncludedPermissionSets = Read; - Permissions = tabledata ConnectionSetup = IM, - tabledata ConnectionAuth = IM; + Permissions = tabledata ConnectionSetup = imd, + tabledata ConnectionAuth = imd; } \ No newline at end of file diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/Objects.PermissionSet.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/Objects.PermissionSet.al index 1a071065c4..e0f855fc66 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/Objects.PermissionSet.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/Objects.PermissionSet.al @@ -4,16 +4,17 @@ // ------------------------------------------------------------------------------------------------ namespace Microsoft.EServices.EDocumentConnector.SignUp; -permissionset 6380 "SignUpEDoc. - Objects" +permissionset 6380 Objects { Access = Internal; Assignable = false; + Caption = 'SignUp E-Document Connector - Objects'; Permissions = table ConnectionSetup = X, table ConnectionAuth = X, page ConnectionSetupCard = X, codeunit IntegrationImpl = X, - codeunit SignUpProcessing = X, + codeunit Processing = X, codeunit Auth = X, codeunit APIRequests = X, codeunit Connection = X, diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/Read.PermissionSet.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/Read.PermissionSet.al index 1bf5a00de2..1a9b95afc2 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/Read.PermissionSet.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/Read.PermissionSet.al @@ -4,12 +4,13 @@ // ------------------------------------------------------------------------------------------------ namespace Microsoft.EServices.EDocumentConnector.SignUp; -permissionset 6381 "SignUpEDoc. - Read" +permissionset 6381 Read { Access = Internal; Assignable = false; - IncludedPermissionSets = "SignUpEDoc. - Objects"; + Caption = 'SignUp E-Document Connector - Read'; + IncludedPermissionSets = Objects; - Permissions = tabledata ConnectionSetup = R, - tabledata ConnectionAuth = R; + Permissions = tabledata ConnectionSetup = r, + tabledata ConnectionAuth = r; } \ No newline at end of file diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/SignUpEDocConnectorEdit.PermissionSetExt.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/SignUpEDocConnectorEdit.PermissionSetExt.al new file mode 100644 index 0000000000..94cbf00cde --- /dev/null +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/SignUpEDocConnectorEdit.PermissionSetExt.al @@ -0,0 +1,11 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.EServices.EDocumentConnector.SignUp; +using Microsoft.EServices.EDocumentConnector; + +permissionsetextension 6380 "SignUp EDoc. Connector - Edit" extends "EDocConnector - Edit" +{ + IncludedPermissionSets = Edit; +} \ No newline at end of file diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/SignUpEDocConnectorRead.PermissionSetExt.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/SignUpEDocConnectorRead.PermissionSetExt.al new file mode 100644 index 0000000000..9c27703bce --- /dev/null +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/Permissions/SignUpEDocConnectorRead.PermissionSetExt.al @@ -0,0 +1,11 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.EServices.EDocumentConnector.SignUp; +using Microsoft.EServices.EDocumentConnector; + +permissionsetextension 6381 "SignUp EDoc. Connector - Read" extends "EDocConnector - Read" +{ + IncludedPermissionSets = Read; +} \ No newline at end of file From 42b9a11b6fd3b2917997212860db3194bf796fd8 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Wed, 25 Sep 2024 12:55:01 +0200 Subject: [PATCH 17/31] Refactor - References to Processing --- .../SignUp/app/src/GetReadyStatus.Codeunit.al | 8 ++++---- .../SignUp/app/src/IntegrationImpl.Codeunit.al | 12 ++++++------ .../SignUp/app/src/PatchSent.Codeunit.al | 4 ++-- .../SignUp/app/src/Processing.Codeunit.al | 10 +++++----- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/GetReadyStatus.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/GetReadyStatus.Codeunit.al index 9254b3f20a..92cb4f7474 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/GetReadyStatus.Codeunit.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/GetReadyStatus.Codeunit.al @@ -49,13 +49,13 @@ codeunit 6384 GetReadyStatus local procedure HandleResponse(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; var EDocumentServiceStatus: Record "E-Document Service Status") var - SignUpProcessing: Codeunit SignUpProcessing; + Processing: Codeunit Processing; BlankRecordId: RecordId; HttpResponse: HttpResponseMessage; HttpRequest: HttpRequestMessage; begin if GetResponse(EDocumentServiceStatus, HttpRequest, HttpResponse) then begin - SignUpProcessing.InsertLogWithIntegration(EDocument, EDocumentService, Enum::"E-Document Service Status"::Approved, 0, HttpRequest, HttpResponse); + Processing.InsertLogWithIntegration(EDocument, EDocumentService, Enum::"E-Document Service Status"::Approved, 0, HttpRequest, HttpResponse); ScheduleEDocumentJob(Codeunit::PatchSent, BlankRecordId, 300000); end; @@ -64,7 +64,7 @@ codeunit 6384 GetReadyStatus local procedure GetResponse(var EDocumentServiceStatus: Record "E-Document Service Status"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) ReturnStatus: Boolean var EDocument: Record "E-Document"; - SignUpProcessing: Codeunit SignUpProcessing; + Processing: Codeunit Processing; TelemetryDimensions: Dictionary of [Text, Text]; begin // Commit before create document with error handling @@ -73,7 +73,7 @@ codeunit 6384 GetReadyStatus EDocument.Get(EDocumentServiceStatus."E-Document Entry No"); - if SignUpProcessing.GetDocumentSentResponse(EDocument, HttpRequest, HttpResponse) then + if Processing.GetDocumentSentResponse(EDocument, HttpRequest, HttpResponse) then ReturnStatus := true; Telemetry.LogMessage('', EDocTelemetryGetResponseScopeEndLbl, Verbosity::Normal, DataClassification::OrganizationIdentifiableInformation, TelemetryScope::All); diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/IntegrationImpl.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/IntegrationImpl.Codeunit.al index ab4eadc630..0b257a5e64 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/IntegrationImpl.Codeunit.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/IntegrationImpl.Codeunit.al @@ -14,7 +14,7 @@ codeunit 6386 IntegrationImpl implements "E-Document Integration" procedure Send(var EDocument: Record "E-Document"; var TempBlob: Codeunit "Temp Blob"; var IsAsync: Boolean; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) var begin - SignUpProcessing.SendEDocument(EDocument, TempBlob, IsAsync, HttpRequest, HttpResponse); + Processing.SendEDocument(EDocument, TempBlob, IsAsync, HttpRequest, HttpResponse); end; procedure SendBatch(var EDocuments: Record "E-Document"; var TempBlob: Codeunit "Temp Blob"; var IsAsync: Boolean; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) @@ -25,12 +25,12 @@ codeunit 6386 IntegrationImpl implements "E-Document Integration" procedure GetResponse(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean begin - exit(SignUpProcessing.GetDocumentResponse(EDocument, HttpRequest, HttpResponse)); + exit(Processing.GetDocumentResponse(EDocument, HttpRequest, HttpResponse)); end; procedure GetApproval(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean begin - exit(SignUpProcessing.GetDocumentApproval(EDocument, HttpRequest, HttpResponse)); + exit(Processing.GetDocumentApproval(EDocument, HttpRequest, HttpResponse)); end; procedure Cancel(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean @@ -40,12 +40,12 @@ codeunit 6386 IntegrationImpl implements "E-Document Integration" procedure ReceiveDocument(var TempBlob: Codeunit "Temp Blob"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) begin - SignUpProcessing.ReceiveDocument(TempBlob, HttpRequest, HttpResponse); + Processing.ReceiveDocument(TempBlob, HttpRequest, HttpResponse); end; procedure GetDocumentCountInBatch(var TempBlob: Codeunit "Temp Blob"): Integer begin - exit(SignUpProcessing.GetDocumentCountInBatch(TempBlob)); + exit(Processing.GetDocumentCountInBatch(TempBlob)); end; procedure GetIntegrationSetup(var SetupPage: Integer; var SetupTable: Integer) @@ -55,5 +55,5 @@ codeunit 6386 IntegrationImpl implements "E-Document Integration" end; var - SignUpProcessing: Codeunit SignUpProcessing; + Processing: Codeunit Processing; } \ No newline at end of file diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/PatchSent.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/PatchSent.Codeunit.al index 144fa8b40e..c7994b9648 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/PatchSent.Codeunit.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/PatchSent.Codeunit.al @@ -33,7 +33,7 @@ codeunit 6387 PatchSent EDocumentIntegrationLog: Record "E-Document Integration Log"; EDocument: Record "E-Document"; APIRequests: Codeunit APIRequests; - SignUpProcessing: Codeunit SignUpProcessing; + Processing: Codeunit Processing; HttpResponse: HttpResponseMessage; HttpRequest: HttpRequestMessage; begin @@ -48,7 +48,7 @@ codeunit 6387 PatchSent EDocumentIntegrationLog.SetRange(Method, 'PATCH'); if EDocumentIntegrationLog.IsEmpty then if APIRequests.PatchADocument(EDocument, HttpRequest, HttpResponse) then - SignUpProcessing.InsertIntegrationLog(EDocument, EDocumentService, HttpRequest, HttpResponse); + Processing.InsertIntegrationLog(EDocument, EDocumentService, HttpRequest, HttpResponse); until EDocumentServiceStatus.Next() = 0; end; diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al index fa91f382e4..5684cc5b2c 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al @@ -9,7 +9,7 @@ using System.Telemetry; using System.Text; using System.Utilities; -codeunit 6388 SignUpProcessing +codeunit 6388 Processing { Access = Internal; Permissions = tabledata "E-Document" = m, @@ -51,7 +51,7 @@ codeunit 6388 SignUpProcessing EDocumentService: Record "E-Document Service"; EDocumentServiceStatus: Record "E-Document Service Status"; APIRequests: Codeunit APIRequests; - SignUpProcessing: Codeunit SignUpProcessing; + Processing: Codeunit Processing; HttpContentResponse: HttpContent; Status, StatusDescription : Text; begin @@ -67,7 +67,7 @@ codeunit 6388 SignUpProcessing begin if StatusDescription <> '' then EDocumentErrorHelper.LogSimpleErrorMessage(EDocument, 'Reason: ' + StatusDescription); - SignUpProcessing.InsertLogWithIntegration(EDocument, EDocumentService, Enum::"E-Document Service Status"::Rejected, 0, HttpRequestMessage, HttpResponseMessage); + Processing.InsertLogWithIntegration(EDocument, EDocumentService, Enum::"E-Document Service Status"::Rejected, 0, HttpRequestMessage, HttpResponseMessage); exit(false); end; end; @@ -80,7 +80,7 @@ codeunit 6388 SignUpProcessing EDocumentServiceStatus: Record "E-Document Service Status"; APIRequests: Codeunit APIRequests; GetReadyStatus: Codeunit GetReadyStatus; - SignUpProcessing: Codeunit SignUpProcessing; + Processing: Codeunit Processing; BlankRecordId: RecordId; HttpContentResponse: HttpContent; Status, StatusDescription : Text; @@ -106,7 +106,7 @@ codeunit 6388 SignUpProcessing begin if StatusDescription <> '' then EDocumentErrorHelper.LogSimpleErrorMessage(EDocument, 'Reason: ' + StatusDescription); - SignUpProcessing.InsertLogWithIntegration(EDocument, EDocumentService, Enum::"E-Document Service Status"::Rejected, 0, HttpRequestMessage, HttpResponseMessage); + Processing.InsertLogWithIntegration(EDocument, EDocumentService, Enum::"E-Document Service Status"::Rejected, 0, HttpRequestMessage, HttpResponseMessage); exit(false); end; end; From 6480969a1199ec40885c39f42d27b373064d2042 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Wed, 25 Sep 2024 12:56:04 +0200 Subject: [PATCH 18/31] Refactor - Restore app.json --- Apps/W1/EDocumentsConnector/app/app.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Apps/W1/EDocumentsConnector/app/app.json b/Apps/W1/EDocumentsConnector/app/app.json index 30fafc9597..301840542b 100644 --- a/Apps/W1/EDocumentsConnector/app/app.json +++ b/Apps/W1/EDocumentsConnector/app/app.json @@ -31,7 +31,7 @@ "idRanges": [ { "from": 6360, - "to": 6389 + "to": 6379 } ], "resourceExposurePolicy": { From d7ecea8419eeae80c1abf5fbfc6930f0f6885a68 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Wed, 25 Sep 2024 13:05:33 +0200 Subject: [PATCH 19/31] Refactor - Missed a spot in restoring original --- .../app/src/Permissions/EDocConnectorRead.PermissionSet.al | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al index 1d01f7b465..07be9b89a6 100644 --- a/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al +++ b/Apps/W1/EDocumentsConnector/app/src/Permissions/EDocConnectorRead.PermissionSet.al @@ -11,5 +11,5 @@ permissionset 6362 "EDocConnector - Read" IncludedPermissionSets = "EDoc. Connector Objects"; Permissions = tabledata "E-Doc. Ext. Connection Setup" = R, - tabledata Microsoft.EServices.EDocumentConnector.Avalara."Connection Setup" = r; + tabledata Microsoft.EServices.EDocumentConnector.Avalara."Connection Setup" = r; } \ No newline at end of file From f39fb473cbeb679d3b8aa1053c18972fd897cb69 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Thu, 26 Sep 2024 15:53:05 +0200 Subject: [PATCH 20/31] Refactor - Missing Logo --- .../SignUp/app/ExtensionLogo.png | Bin 0 -> 5446 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Apps/W1/EDocumentConnectors/SignUp/app/ExtensionLogo.png diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/ExtensionLogo.png b/Apps/W1/EDocumentConnectors/SignUp/app/ExtensionLogo.png new file mode 100644 index 0000000000000000000000000000000000000000..4d2c9a626cb9617350617c40cd73904129d4c108 GIT binary patch literal 5446 zcma)=S5VVywD$iAMIcgC2u+$uktV%J6$Dhev_NQrfC^Fsq!|cJ=^|Z`P&U*^N-uuwi#_w5i!*aB*89x5SkKKnv*ua91anhEW+omc005Zp+`e`1 zOsW4C1O3^nWxbYuCX9Z!?E(M*a`E2+jm<_J0|5K}om)4pLZ&wJ&3t(K(|ffcq#?ky z#^aeQO#|lO9vyUeb0ezqQtpipl3Sj#-xy!eh7lu@5+BnW zNhL-~3Zpw&1u=bMN*Q(sgYksq4dM>Iw7p&Qk_Su~b*PgEs#LK~^K}aDaTG_6Q?_tM<8wOS}`Z+?~Et8GB>T%(k7$9`DL!d5)f!ZoXco-vj+s_QLEs2cf zKM&F>#c9w|TmM9MFtl8L*cYQgl9khf5CYMR)DJOUf;M~a9|+ys@RYR zCusNC(CSlUk|r`qdS&ZKh$O=@#&e0>;W~S#|KjHdfLx!-J9r1JtP4RGIhS|Rm0eZ6 z7eOE~Zfo4Li~K^|&)d^-r?8Rh2Q}#ZjL=?VJZ7~hlp4(!U!0K%679I`OR&x54*0&4 znho|hKu)WR)4PUVA1}N;jXHg}AG+gSKQ6O_fEP^Y51!LwBERH09|t!GNx2KH4co>r zA%cgSHxh2Sezx-w!S5DTG#0zVCbnLM6BP}2P-G{8 zh**wJHj<652FS05bSQNx-0fS7^(wREYvZwpt;$!!k4H0U*iyhS8(syBDMv>L<)~LI zPl!Y^-cM{_J@{hY1=XJ#T=Ef(FD!I^r1^lca3c0ftVuvo-(%!Zn)C1bK{}-i*Jc); zIIc+o&iMgvboj&4`@5sF23MV!*zIVmA0>{1;*H*faMAG6EZ7XydTfaGyABAGx>)yl z@Y+|)SVxCx@!GWqspay7GBetK*s2@CJ?s{8v!(b|ShLb|O;3T1rAMB?DJ?Z`@013q zoyIvV84eYiS+?kRJOz`3AFcR~ZQ1Uq7wCnbSJ%-HZwhAnJ^4zDp2W8I)~WI7ush5> z&f3O)rj~2ZGr!c@=p3!n>jG-O#9`$7&WyF7bB}(rq4ldokUp5TY?E62r+YJbJp8Jf znDW3fYZ^nBQ9O}3?zH_*mZ9+G#HHnwop1Vfm!Df~{Z%D?5KzMN&RA>&#q8iCzTfAt zV#TyMeyyh8=M$8tyA|KeUwo_Q6Si)P)%n(W-*QE~08BG|>J!sQPq?IF;;%1ypP?Z` zK_0Un>p;9=9d675ELHboC0+fNMY&(;k(|=0TS>ka)BKI3q#)zx!Jp@zv0QfeEAjU< z=vI5@-d^A^-*#|P+b2QFiGxk4z<8Tp4p6{aOp88x>SQEa0M`VxX%IUb$bya!5EgRf6$fFw zp}jNTKUXjNe0x(;)Nu)Ij5K?QD0u6~mRHQ-!;6m#VP>)}=irAqy;f$e{W-EWnR75~ zm2b0u@r7ASk4x0oTqs9{f&F|eAmD*Gf^A;te7f}J{dXqLaH_4%D_(mnp0VmWhq>^E z&7>5*-mh>FX{w5SJf^#th&GrpOQk58U-+4 zq3$q~C4ySH7@lr>W+|c0`UF*ieC+3vC1$4m}F(ic|G7}QDt(t z7`#>$c4U-4LU_;nWHhdN9Fcv~L8h6M_}nW&EGTjgW(=c}uD9>eU^rDOrkNg_effOV z^8z_y=vNIt{`wOfgG2o^3ey`R!aP1=t7Mz@&MKK3>_BH_QkgNO@4IoQ-2d8EqsDg) zTMb-5lqlubRot-7!RD@+udO?O9_Da3XV5bvjW zXTb2psHUdeiIaI(lknQE_<+YlY31}R!VfoM_BuILQ{>Q89=LB5j;V|-yAW2gY82+~ zYlu~#*R(cHw2NO1h5xaiAD2oiIEQ-aQyA-D^y^z2ZHNfM{o(3M#SbqOP3>k9FOdDO z(t%c9hk)NCPe_8>=Y^U-_-6IwS-D0cE=pwdyLp!;r-fWiXtbUS$<dl!~WV$TR8 zP$KU?K>m?*O)mSGccn&kn|nj7NXFeo<0D=ue8s^~BK#P?J~gB}v5<0nK9GPipjT#9 zkm6yXFyLlgoUIDEVxw*0Z-WDqp8swCs(bcjAqdDLl1oUqYf#a`NjT6IO3?=P`FvUZ zlWC&lWb9_dexSz%N~-oscM`oC%b#KS|KS7AptwRX5h&1VDCKWzP{&??TFdF3h53&c zU(v)WhOr)#!V6Y6d7CzOO-@KF%@67>kh34@Exj7Rh}p5_0?yUeyC7@c7DHf+mW=~wpLeLYDA9#W-Ri*S|M@g zjPHH@qHrPuzq(+5y$V*UoFEg(g$$mRNUEF!C{IN3Rig{tU54W|OD_`M0G3u)B{WhC z*D?hTF7J+YdF8-Z-Uuw{3jBx`_!aus`uDDBecwuu&tsVpj2~DZJb2-!a2l??m{}er}lR6Lqu)-2+Vm)jr(g{nfQPx9-<^1d;k-d zkU{E^g7qwp+D`b+QtU5@+swaVKp9<`>sT~U)O!EEMBo!*)~s_<`6Yl z7fX2;ki>kVDfdietW1k;TYvaY({>?5X)&(d&_y<-J7Qa@b z(zwGCI=`P#^b>1>2#Y!9T5|AdtaU|zXxw9^KpIu6CAmQf$GzaeOJmYVsc3eh5%6lb z)t~(Ak2J`;KW_L6psME-h?xF6ryr4d{q;>-b`Q$L43T{r`{N?U6cqP(Q3f%kA8`c@ z<82KXjte|7u_Lo~MV!d%y$tYi(hzU$6t+*ml~Z&Mg{eK?@}^XEBK+-&j`Uv95x)=_ zZLs=Mpg_IuZenjm(~}b8Aggaaje8NX$A_7^G%-)!xtu)C{N|S<3hVOmU;{|i+q6zn zfr(1Ua*jF!%-dU3L}O2fvWAe%-4kxtXo_vJHF(AxSx)4AI8-$^uBQO_86Z_y%RZX4 zJpu5`pOAztxv?jXv9yx|r>#9!0|`71C-fli@v${6r+V$hgvcr|W_I`{=7*0s(PKQH zzn8r2+tSeD15stz|DIJ3%X%8EkyN?bsHhuq4(5D0Oewn_)-o)Nx$eNs{0V*ZTSVt4 z3ifXGGw5fBv+9b6d~Nl+08L4VbbZqf3DL^e?l@!uZVdWkdOpJPaE?{zF!ZI?c(vF3 zvX~OK4vktvm&R$MgNpiKA~&zT!1#H7!q1h7AQiuSNG9<=$64)Zym(UQ``(j#^hDzt}{aur0pS?mmBi&z4I0Jfieqh%Pa_A%N?_1OZHm-S{ zQ*)4(N_J;y7tRh0o>xs25-s9!M-)i;@I68#SGXB2XgS}N zx_r3%V)z1jLA_M&?)E^DT$kzdHMJF%e2w6BH@iI5tKWM+zcuhCsz@N0a_1RBvrdZx zjzD>V%;c4*$RkEv{zHuVyaB+ANl(iT8w{pJdziC7YcO2&(ciqGLhs@q-dNh! zkV_V_(_~$*>ND}j1yozMedYnu-_GKMh?IpP<@D+edeB4M%3@xr3oj{@mdFKoBVpm^)1_}Y^}rOWBSB|Uv)*-pTdiU ztW9~{qq5@iB+$QpbeJVKH^n^9vV})i>Z@2CHoY2$PC888c;#Yz-pHRK@EVheWhE!> zZzjPmy?0Ni8#=o_k6_s3DY7nS^&Bm}BW&ZfAuF7bQbDgAGM$dE)RM6RvdobKb&MhsYD4exRm9*jcHPjbz#rI?vj$u zPLF5Gjv|8}?ta9`&^H}Va3H;llghU-BC7pxo6?-eTP`7CUZHJrw{5 zhkDYeIYlhL%brQJ1X#<#fz#E}Z87Kj=Hde*f{l|A`9E my8jz0{9hgZgN;Rh%;ug!HJ{lE_@04L;EulOt!iDD=>G@$cU!Ii literal 0 HcmV?d00001 From a8c22c702c52b49e0ff153fa2526053a46d9ecda Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Fri, 27 Sep 2024 13:44:26 +0200 Subject: [PATCH 21/31] Refactor - Exit return value --- .../SignUp/app/src/ConnectionSetupCard.Page.al | 1 - .../SignUp/app/src/Processing.Codeunit.al | 7 ++----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/ConnectionSetupCard.Page.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/ConnectionSetupCard.Page.al index d49482d7ea..c611fa91ab 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/ConnectionSetupCard.Page.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/ConnectionSetupCard.Page.al @@ -206,5 +206,4 @@ page 6380 ConnectionSetupCard IsSaaSInfrastructure: Boolean; ExternalServiceTok: Label 'ExternalServiceConnector', Locked = true; - } \ No newline at end of file diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al index 5684cc5b2c..bcd78891bc 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al @@ -193,12 +193,9 @@ codeunit 6388 Processing ErrorDescription: Text; begin if not Connection.CheckDocumentStatus(EDocument, HttpRequestMessage, HttpResponse, true) then - exit(false); - - if DocumentHasErrorOrProcessing(EDocument, HttpResponse, ErrorDescription) then - exit(false); + exit; - exit(true); + exit(not DocumentHasErrorOrProcessing(EDocument, HttpResponse, ErrorDescription)); end; local procedure ParseSendFileResponse(HttpContentResponse: HttpContent): Text From e11508ab8440e305ae019b7cc4367bc7535a866b Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Fri, 27 Sep 2024 14:01:28 +0200 Subject: [PATCH 22/31] Refactor - Move UriTemplates to Global --- .../SignUp/app/src/APIRequests.Codeunit.al | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al index 7daf0c6b99..0fb1b3739b 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al @@ -24,10 +24,9 @@ codeunit 6380 APIRequests ContentHttpHeaders: HttpHeaders; HttpContent: HttpContent; ContentText: Text; - UriTemplateLbl: Label '%1/api/Peppol', Comment = '%1 = Service Url', Locked = true; begin InitRequest(ConnectionSetup, HttpRequestMessage, HttpResponseMessage); - HttpRequestMessage := PrepareRequestMsg("Http Request Type"::POST, StrSubstNo(UriTemplateLbl, ConnectionSetup.ServiceURL)); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::POST, StrSubstNo(SendFilePostRequestUriTxt, ConnectionSetup.ServiceURL)); Payload := XmlToTxt(TempBlob); if Payload = '' then @@ -48,10 +47,9 @@ codeunit 6380 APIRequests procedure GetSentDocumentStatus(EDocument: Record "E-Document"; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean var ConnectionSetup: Record ConnectionSetup; - UriTemplateLbl: Label '%1/api/Peppol/status?peppolInstanceId=%2', Comment = '%1 = Service Url, %2 = Document ID', Locked = true; begin InitRequest(ConnectionSetup, HttpRequestMessage, HttpResponseMessage); - HttpRequestMessage := PrepareRequestMsg("Http Request Type"::GET, StrSubstNo(UriTemplateLbl, ConnectionSetup.ServiceURL, EDocument."Document Id")); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::GET, StrSubstNo(GetSentDocumentStatusUriTxt, ConnectionSetup.ServiceURL, EDocument."Document Id")); exit(SendRequest(HttpRequestMessage, HttpResponseMessage)); end; @@ -59,10 +57,9 @@ codeunit 6380 APIRequests procedure PatchADocument(EDocument: Record "E-Document"; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean var ConnectionSetup: Record ConnectionSetup; - UriTemplateLbl: Label '%1/api/Peppol/outbox?peppolInstanceId=%2', Comment = '%1 = Service Url, %2 = Document ID', Locked = true; begin InitRequest(ConnectionSetup, HttpRequestMessage, HttpResponseMessage); - HttpRequestMessage := PrepareRequestMsg("Http Request Type"::PATCH, StrSubstNo(UriTemplateLbl, ConnectionSetup.ServiceURL, EDocument."Document Id")); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::PATCH, StrSubstNo(PatchADocumentUriTxt, ConnectionSetup.ServiceURL, EDocument."Document Id")); exit(SendRequest(HttpRequestMessage, HttpResponseMessage)); end; @@ -70,10 +67,9 @@ codeunit 6380 APIRequests procedure GetReceivedDocumentsRequest(var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage; Parameters: Dictionary of [Text, Text]): Boolean var ConnectionSetup: Record ConnectionSetup; - UriTemplateLbl: Label '%1/api/Peppol/Inbox?peppolId=%2', Comment = '%1 = Service Url, %2 = Peppol Identifier', Locked = true; begin InitRequest(ConnectionSetup, HttpRequestMessage, HttpResponseMessage); - HttpRequestMessage := PrepareRequestMsg("Http Request Type"::GET, StrSubstNo(UriTemplateLbl, ConnectionSetup.ServiceURL, GetSenderReceiverPrefix() + ConnectionSetup."Company Id")); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::GET, StrSubstNo(GetReceivedDocumentsUriTxt, ConnectionSetup.ServiceURL, GetSenderReceiverPrefix() + ConnectionSetup."Company Id")); exit(SendRequest(HttpRequestMessage, HttpResponseMessage)); end; @@ -81,10 +77,9 @@ codeunit 6380 APIRequests procedure GetTargetDocumentRequest(DocumentId: Text; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean var ConnectionSetup: Record ConnectionSetup; - UriTemplateLbl: Label '%1/api/Peppol/inbox-document?peppolId=%2&peppolInstanceId=%3', Comment = '%1 = Service Url, %2 = Peppol Identifier, %3 = Peppol Gateway Instance', Locked = true; begin InitRequest(ConnectionSetup, HttpRequestMessage, HttpResponseMessage); - HttpRequestMessage := PrepareRequestMsg("Http Request Type"::GET, StrSubstNo(UriTemplateLbl, ConnectionSetup.ServiceURL, GetSenderReceiverPrefix() + ConnectionSetup."Company Id", DocumentId)); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::GET, StrSubstNo(GetTargetDocumentUriTxt, ConnectionSetup.ServiceURL, GetSenderReceiverPrefix() + ConnectionSetup."Company Id", DocumentId)); exit(SendRequest(HttpRequestMessage, HttpResponseMessage)); end; @@ -92,10 +87,9 @@ codeunit 6380 APIRequests procedure PatchReceivedDocument(EDocument: Record "E-Document"; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean var ConnectionSetup: Record ConnectionSetup; - UriTemplateLbl: Label '%1/api/Peppol/inbox?peppolInstanceId=%2', Comment = '%1 = Service Url, %2 = Peppol Gateway Instance', Locked = true; begin InitRequest(ConnectionSetup, HttpRequestMessage, HttpResponseMessage); - HttpRequestMessage := PrepareRequestMsg("Http Request Type"::PATCH, StrSubstNo(UriTemplateLbl, ConnectionSetup.ServiceURL, EDocument."Document Id")); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::PATCH, StrSubstNo(PatchReceivedDocumentUriTxt, ConnectionSetup.ServiceURL, EDocument."Document Id")); exit(SendRequest(HttpRequestMessage, HttpResponseMessage)); end; @@ -103,10 +97,9 @@ codeunit 6380 APIRequests var ConnectionSetup: Record ConnectionSetup; Auth: Codeunit Auth; - BaseUrlTxt: Label '%1/api/Registration/init?EntraTenantId=%2', Locked = true; begin InitRequest(ConnectionSetup, HttpRequestMessage, HttpResponseMessage); - HttpRequestMessage := PrepareRequestMsg("Http Request Type"::POST, StrSubstNo(BaseUrlTxt, Auth.GetRootUrl(), Auth.GetBCInstanceIdentifier())); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::POST, StrSubstNo(GetMarketPlaceCredentialsUriTxt, Auth.GetRootUrl(), Auth.GetBCInstanceIdentifier())); exit(SendRequest(HttpRequestMessage, HttpResponseMessage, true)); end; @@ -218,4 +211,11 @@ codeunit 6380 APIRequests var MissingSetupErr: Label 'You must set up service integration in the E-Document service card.'; + GetSentDocumentStatusUriTxt: Label '%1/api/Peppol/status?peppolInstanceId=%2', Comment = '%1 = Service Url, %2 = Document ID', Locked = true; + SendFilePostRequestUriTxt: Label '%1/api/Peppol', Comment = '%1 = Service Url', Locked = true; + PatchADocumentUriTxt: Label '%1/api/Peppol/outbox?peppolInstanceId=%2', Comment = '%1 = Service Url, %2 = Document ID', Locked = true; + GetReceivedDocumentsUriTxt: Label '%1/api/Peppol/Inbox?peppolId=%2', Comment = '%1 = Service Url, %2 = Peppol Identifier', Locked = true; + GetTargetDocumentUriTxt: Label '%1/api/Peppol/inbox-document?peppolId=%2&peppolInstanceId=%3', Comment = '%1 = Service Url, %2 = Peppol Identifier, %3 = Peppol Gateway Instance', Locked = true; + PatchReceivedDocumentUriTxt: Label '%1/api/Peppol/inbox?peppolInstanceId=%2', Comment = '%1 = Service Url, %2 = Peppol Gateway Instance', Locked = true; + GetMarketPlaceCredentialsUriTxt: Label '%1/api/Registration/init?EntraTenantId=%2', Locked = true; } \ No newline at end of file From bfca6405e67570f7f2c85daed6127214c56cd9f6 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Fri, 27 Sep 2024 14:21:06 +0200 Subject: [PATCH 23/31] Refactor - Eliminate unneeded calls --- .../SignUp/app/src/Processing.Codeunit.al | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al index bcd78891bc..ef3cb0285b 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al @@ -39,11 +39,11 @@ codeunit 6388 Processing procedure GetDocumentResponse(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean var + ErrorDescription: Text; begin - if not CheckIfDocumentStatusSuccessful(EDocument, HttpRequest, HttpResponse) then - exit(false); - - exit(true); + if not Connection.CheckDocumentStatus(EDocument, HttpRequest, HttpResponse, true) then + exit; + exit(DocumentHasErrorOrProcessing(EDocument, HttpResponse, ErrorDescription)); end; procedure GetDocumentSentResponse(EDocument: Record "E-Document"; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean @@ -188,16 +188,6 @@ codeunit 6388 Processing exit(JsonManagement.GetCollectionCount()); end; - local procedure CheckIfDocumentStatusSuccessful(EDocument: Record "E-Document"; var HttpRequestMessage: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean - var - ErrorDescription: Text; - begin - if not Connection.CheckDocumentStatus(EDocument, HttpRequestMessage, HttpResponse, true) then - exit; - - exit(not DocumentHasErrorOrProcessing(EDocument, HttpResponse, ErrorDescription)); - end; - local procedure ParseSendFileResponse(HttpContentResponse: HttpContent): Text var JsonManagement: Codeunit "JSON Management"; From 1e245932e5e20a481b12631b6838b0a5baa18f15 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Fri, 27 Sep 2024 14:27:19 +0200 Subject: [PATCH 24/31] Refactor - Error when unsupported EDocument Type --- .../EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al index 0fb1b3739b..faa1f49aad 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al @@ -161,6 +161,8 @@ codeunit 6380 APIRequests exit('Invoice'); "E-Document Type"::"Issued Finance Charge Memo", "E-Document Type"::"Issued Reminder": exit('PaymentReminder'); + else + Error(UnSupportedDocumentTypeLbl, EDocument."Document Type"); end; end; @@ -218,4 +220,5 @@ codeunit 6380 APIRequests GetTargetDocumentUriTxt: Label '%1/api/Peppol/inbox-document?peppolId=%2&peppolInstanceId=%3', Comment = '%1 = Service Url, %2 = Peppol Identifier, %3 = Peppol Gateway Instance', Locked = true; PatchReceivedDocumentUriTxt: Label '%1/api/Peppol/inbox?peppolInstanceId=%2', Comment = '%1 = Service Url, %2 = Peppol Gateway Instance', Locked = true; GetMarketPlaceCredentialsUriTxt: Label '%1/api/Registration/init?EntraTenantId=%2', Locked = true; + UnSupportedDocumentTypeLbl: Label 'Document %1 is not supported.', Comment = '%1 = EDocument Type', Locked = true; } \ No newline at end of file From 80274503d1e7dfb7c1c663bcd2d1d13b8e57ac38 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Fri, 27 Sep 2024 14:49:32 +0200 Subject: [PATCH 25/31] Refactor - To use ErrorInfo --- .../SignUp/app/src/APIRequests.Codeunit.al | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al index faa1f49aad..a4541781fc 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al @@ -104,11 +104,18 @@ codeunit 6380 APIRequests end; local procedure InitRequest(var ConnectionSetup: Record ConnectionSetup; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage) + var + MissingSetupErrorInfo: ErrorInfo; begin Clear(HttpRequestMessage); Clear(HttpResponseMessage); - if not ConnectionSetup.Get() then - Error(MissingSetupErr); + if not ConnectionSetup.Get() then begin + MissingSetupErrorInfo.Title := MissingSetupErr; + MissingSetupErrorInfo.Message := MissingSetupMessageLbl; + MissingSetupErrorInfo.PageNo := Page::"E-Document Services"; + MissingSetupErrorInfo.AddNavigationAction(MissingSetupNavigationActionLbl); + Error(MissingSetupErrorInfo); + end; end; local procedure SendRequest(HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean @@ -212,7 +219,9 @@ codeunit 6380 APIRequests end; var - MissingSetupErr: Label 'You must set up service integration in the E-Document service card.'; + MissingSetupErr: Label 'Connection Setup is missing'; + MissingSetupMessageLbl: Label 'You must set up service integration in the e-document service card.'; + MissingSetupNavigationActionLbl: Label 'Show E-Document Services'; GetSentDocumentStatusUriTxt: Label '%1/api/Peppol/status?peppolInstanceId=%2', Comment = '%1 = Service Url, %2 = Document ID', Locked = true; SendFilePostRequestUriTxt: Label '%1/api/Peppol', Comment = '%1 = Service Url', Locked = true; PatchADocumentUriTxt: Label '%1/api/Peppol/outbox?peppolInstanceId=%2', Comment = '%1 = Service Url, %2 = Document ID', Locked = true; From 8bd90ac22b1480ae613d501e3bee4def98a326b8 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Fri, 27 Sep 2024 14:57:30 +0200 Subject: [PATCH 26/31] Refactor - Move local labels to global --- .../SignUp/app/src/IntegrationImpl.Codeunit.al | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/IntegrationImpl.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/IntegrationImpl.Codeunit.al index 0b257a5e64..55d28f88d0 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/IntegrationImpl.Codeunit.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/IntegrationImpl.Codeunit.al @@ -20,7 +20,7 @@ codeunit 6386 IntegrationImpl implements "E-Document Integration" procedure SendBatch(var EDocuments: Record "E-Document"; var TempBlob: Codeunit "Temp Blob"; var IsAsync: Boolean; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) begin IsAsync := false; - Error('Batch sending is not supported in this version'); + Error(BatchSendNotSupportedErr); end; procedure GetResponse(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean @@ -35,7 +35,7 @@ codeunit 6386 IntegrationImpl implements "E-Document Integration" procedure Cancel(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean begin - Error('Cancel is not supported in this version'); + Error(CancelNotSupportedErr); end; procedure ReceiveDocument(var TempBlob: Codeunit "Temp Blob"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage) @@ -56,4 +56,6 @@ codeunit 6386 IntegrationImpl implements "E-Document Integration" var Processing: Codeunit Processing; + BatchSendNotSupportedErr: Label 'Batch sending is not supported in this version'; + CancelNotSupportedErr: Label 'Cancel is not supported in this version'; } \ No newline at end of file From 896cbe865ec2405ae93405fb052caaa138a2803e Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Fri, 27 Sep 2024 15:06:24 +0200 Subject: [PATCH 27/31] Refactor - No need for Retry --- .../SignUp/app/src/Connection.Codeunit.al | 33 ++++++------------- .../SignUp/app/src/Processing.Codeunit.al | 10 +++--- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/Connection.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Connection.Codeunit.al index 34bcd77c6e..7543cbe345 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/Connection.Codeunit.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/Connection.Codeunit.al @@ -14,31 +14,23 @@ codeunit 6382 Connection Access = Internal; Permissions = tabledata "E-Document" = m; - procedure HandleSendFilePostRequest(var TempBlob: Codeunit "Temp Blob"; var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage; Retry: Boolean): Boolean + procedure HandleSendFilePostRequest(var TempBlob: Codeunit "Temp Blob"; var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean begin - if not APIRequests.SendFilePostRequest(TempBlob, EDocument, HttpRequest, HttpResponse) then - if Retry then - APIRequests.SendFilePostRequest(TempBlob, EDocument, HttpRequest, HttpResponse); - + APIRequests.SendFilePostRequest(TempBlob, EDocument, HttpRequest, HttpResponse); exit(CheckIfSuccessfulRequest(EDocument, HttpResponse)); end; - procedure CheckDocumentStatus(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage; Retry: Boolean): Boolean + procedure CheckDocumentStatus(var EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean begin - if not APIRequests.GetSentDocumentStatus(EDocument, HttpRequest, HttpResponse) then - if Retry then - APIRequests.GetSentDocumentStatus(EDocument, HttpRequest, HttpResponse); - + APIRequests.GetSentDocumentStatus(EDocument, HttpRequest, HttpResponse); exit(CheckIfSuccessfulRequest(EDocument, HttpResponse)); end; - procedure GetReceivedDocuments(var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage; Retry: Boolean): Boolean + procedure GetReceivedDocuments(var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean var Parameters: Dictionary of [Text, Text]; begin - if not APIRequests.GetReceivedDocumentsRequest(HttpRequest, HttpResponse, Parameters) then - if Retry then - APIRequests.GetReceivedDocumentsRequest(HttpRequest, HttpResponse, Parameters); + APIRequests.GetReceivedDocumentsRequest(HttpRequest, HttpResponse, Parameters); if not HttpResponse.IsSuccessStatusCode then exit(false); @@ -46,20 +38,15 @@ codeunit 6382 Connection exit(Helpers.ParseJsonString(HttpResponse.Content) <> ''); end; - procedure HandleGetTargetDocumentRequest(DocumentId: Text; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage; Retry: Boolean): Boolean + procedure HandleGetTargetDocumentRequest(DocumentId: Text; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean begin - if not APIRequests.GetTargetDocumentRequest(DocumentId, HttpRequest, HttpResponse) then - if Retry then - APIRequests.GetTargetDocumentRequest(DocumentId, HttpRequest, HttpResponse); - + APIRequests.GetTargetDocumentRequest(DocumentId, HttpRequest, HttpResponse); exit(HttpResponse.IsSuccessStatusCode); end; - procedure RemoveDocumentFromReceived(EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage; Retry: Boolean): Boolean + procedure RemoveDocumentFromReceived(EDocument: Record "E-Document"; var HttpRequest: HttpRequestMessage; var HttpResponse: HttpResponseMessage): Boolean begin - if not APIRequests.PatchReceivedDocument(EDocument, HttpRequest, HttpResponse) then - if Retry then - APIRequests.PatchReceivedDocument(EDocument, HttpRequest, HttpResponse); + APIRequests.PatchReceivedDocument(EDocument, HttpRequest, HttpResponse); exit(HttpResponse.IsSuccessStatusCode); end; diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al index ef3cb0285b..d93bac6fe7 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al @@ -41,7 +41,7 @@ codeunit 6388 Processing var ErrorDescription: Text; begin - if not Connection.CheckDocumentStatus(EDocument, HttpRequest, HttpResponse, true) then + if not Connection.CheckDocumentStatus(EDocument, HttpRequest, HttpResponse) then exit; exit(DocumentHasErrorOrProcessing(EDocument, HttpResponse, ErrorDescription)); end; @@ -118,7 +118,7 @@ codeunit 6388 Processing ContentData: Text; OutStream: OutStream; begin - if not Connection.GetReceivedDocuments(HttpRequest, HttpResponse, true) then + if not Connection.GetReceivedDocuments(HttpRequest, HttpResponse) then exit; HttpResponse.Content.ReadAs(ContentData); @@ -142,7 +142,7 @@ codeunit 6388 Processing var HttpContentResponse: HttpContent; begin - Connection.HandleSendFilePostRequest(TempBlob, EDocument, HttpRequest, HttpResponse, true); + Connection.HandleSendFilePostRequest(TempBlob, EDocument, HttpRequest, HttpResponse); HttpContentResponse := HttpResponse.Content; SetEDocumentFileID(EDocument."Entry No", ParseSendFileResponse(HttpContentResponse)); end; @@ -319,7 +319,7 @@ codeunit 6388 Processing exit; end; - Connection.HandleGetTargetDocumentRequest(DocumentId, LocalHttpRequest, LocalHttpResponse, false); + Connection.HandleGetTargetDocumentRequest(DocumentId, LocalHttpRequest, LocalHttpResponse); EDocumentLogHelper.InsertIntegrationLog(EDocument, EDocumentService, LocalHttpRequest, LocalHttpResponse); LocalHttpResponse.Content.ReadAs(ContentData); @@ -335,7 +335,7 @@ codeunit 6388 Processing DocumentOutStream.WriteText(ContentData); EDocument."Document Id" := CopyStr(DocumentId, 1, MaxStrLen(EDocument."Document Id")); EDocumentLogHelper.InsertLog(EDocument, EDocumentService, TempBlob, "E-Document Service Status"::Imported); - Connection.RemoveDocumentFromReceived(EDocument, LocalHttpRequest, LocalHttpResponse, true); + Connection.RemoveDocumentFromReceived(EDocument, LocalHttpRequest, LocalHttpResponse); EDocumentLogHelper.InsertIntegrationLog(EDocument, EDocumentService, LocalHttpRequest, LocalHttpResponse); end; From a12493f4d55c3f0e3898f628e4082e634bdfdc90 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Fri, 27 Sep 2024 16:45:52 +0200 Subject: [PATCH 28/31] Refactor - Make labels Global --- .../SignUp/app/src/APIRequests.Codeunit.al | 3 +-- .../SignUp/app/src/Auth.Codeunit.al | 11 ++++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al index a4541781fc..8e86fb5bda 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al @@ -212,8 +212,6 @@ codeunit 6380 APIRequests end; local procedure GetSenderReceiverPrefix(): Text - var - SenderReceiverPrefixLbl: Label 'iso6523-actorid-upis::', Locked = true; begin exit(SenderReceiverPrefixLbl); end; @@ -230,4 +228,5 @@ codeunit 6380 APIRequests PatchReceivedDocumentUriTxt: Label '%1/api/Peppol/inbox?peppolInstanceId=%2', Comment = '%1 = Service Url, %2 = Peppol Gateway Instance', Locked = true; GetMarketPlaceCredentialsUriTxt: Label '%1/api/Registration/init?EntraTenantId=%2', Locked = true; UnSupportedDocumentTypeLbl: Label 'Document %1 is not supported.', Comment = '%1 = EDocument Type', Locked = true; + SenderReceiverPrefixLbl: Label 'iso6523-actorid-upis::', Locked = true; } \ No newline at end of file diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/Auth.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Auth.Codeunit.al index 035d32ef13..984108a704 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/Auth.Codeunit.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/Auth.Codeunit.al @@ -25,10 +25,8 @@ codeunit 6381 Auth end; procedure GetRootOnboardingUrl(): Text - var - UrlTxt: Label '%1/supm/landingpage?EntraTenantId=%2', Comment = '%1 = Root Market URL, %2 = BC Instance Identifier', Locked = true; begin - exit(StrSubstNo(UrlTxt, GetRootUrl(), GetBCInstanceIdentifier())); + exit(GetRootUrl() + '/supm/landingpage?EntraTenantId=' + GetBCInstanceIdentifier()); end; [NonDebuggable] @@ -39,7 +37,6 @@ codeunit 6381 Auth JText: Text; ClientId: Text; ClientSecret: SecretText; - ErrorUnableToCreateClientCredentialsLbl: Label 'Unable to create client credentials.'; begin if not GetClientCredentials(HttpRequestMessage, HttpResponseMessage) then Error(ErrorUnableToCreateClientCredentialsLbl); @@ -86,8 +83,6 @@ codeunit 6381 Auth end; procedure GetRootAuthBearerToken() ReturnValue: SecretText; - var - ErrorTokenLbl: Label 'Unable to fetch a root token.'; begin if not GetRootAccessToken(ReturnValue) then Error(ErrorTokenLbl); @@ -138,7 +133,6 @@ codeunit 6381 Auth HttpContent: HttpContent; HttpHeaders: HttpHeaders; ContentText: SecretText; - ContentTemplateTxt: Label 'grant_type=client_credentials&client_id=%1&client_secret=%2&resource=%3', Locked = true; JText: Text; begin ConnectionSetup.GetRecordOnce(); @@ -323,4 +317,7 @@ codeunit 6381 Auth AuthURLTxt: Label 'https://login.microsoftonline.com/%1/oauth2/token', Comment = '%1 Entra Tenant Id', Locked = true; ProdTenantIdTxt: Label '0d725623-dc26-484f-a090-b09d2003d092', Locked = true; ProdServiceAPITxt: Label 'https://edoc.exflow.io', Locked = true; + ContentTemplateTxt: Label 'grant_type=client_credentials&client_id=%1&client_secret=%2&resource=%3', Locked = true; + ErrorTokenLbl: Label 'Unable to fetch a root token.'; + ErrorUnableToCreateClientCredentialsLbl: Label 'Unable to create client credentials.'; } \ No newline at end of file From ea3a35e1d62d3b0a63e40a3d91bf70f7f405e6ed Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Fri, 27 Sep 2024 17:00:40 +0200 Subject: [PATCH 29/31] Refactor - Remove labels, API path inline the Avalara way --- .../SignUp/app/src/APIRequests.Codeunit.al | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al index 8e86fb5bda..a17bd2d256 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/APIRequests.Codeunit.al @@ -26,7 +26,7 @@ codeunit 6380 APIRequests ContentText: Text; begin InitRequest(ConnectionSetup, HttpRequestMessage, HttpResponseMessage); - HttpRequestMessage := PrepareRequestMsg("Http Request Type"::POST, StrSubstNo(SendFilePostRequestUriTxt, ConnectionSetup.ServiceURL)); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::POST, ConnectionSetup.ServiceURL + '/api/Peppol'); Payload := XmlToTxt(TempBlob); if Payload = '' then @@ -49,7 +49,7 @@ codeunit 6380 APIRequests ConnectionSetup: Record ConnectionSetup; begin InitRequest(ConnectionSetup, HttpRequestMessage, HttpResponseMessage); - HttpRequestMessage := PrepareRequestMsg("Http Request Type"::GET, StrSubstNo(GetSentDocumentStatusUriTxt, ConnectionSetup.ServiceURL, EDocument."Document Id")); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::GET, ConnectionSetup.ServiceURL + '/api/Peppol/status?peppolInstanceId=' + EDocument."Document Id"); exit(SendRequest(HttpRequestMessage, HttpResponseMessage)); end; @@ -59,7 +59,7 @@ codeunit 6380 APIRequests ConnectionSetup: Record ConnectionSetup; begin InitRequest(ConnectionSetup, HttpRequestMessage, HttpResponseMessage); - HttpRequestMessage := PrepareRequestMsg("Http Request Type"::PATCH, StrSubstNo(PatchADocumentUriTxt, ConnectionSetup.ServiceURL, EDocument."Document Id")); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::PATCH, ConnectionSetup.ServiceURL + '/api/Peppol/outbox?peppolInstanceId=' + EDocument."Document Id"); exit(SendRequest(HttpRequestMessage, HttpResponseMessage)); end; @@ -69,7 +69,7 @@ codeunit 6380 APIRequests ConnectionSetup: Record ConnectionSetup; begin InitRequest(ConnectionSetup, HttpRequestMessage, HttpResponseMessage); - HttpRequestMessage := PrepareRequestMsg("Http Request Type"::GET, StrSubstNo(GetReceivedDocumentsUriTxt, ConnectionSetup.ServiceURL, GetSenderReceiverPrefix() + ConnectionSetup."Company Id")); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::GET, ConnectionSetup.ServiceURL + '/api/Peppol/Inbox?peppolId=' + GetSenderReceiverPrefix() + ConnectionSetup."Company Id"); exit(SendRequest(HttpRequestMessage, HttpResponseMessage)); end; @@ -79,7 +79,7 @@ codeunit 6380 APIRequests ConnectionSetup: Record ConnectionSetup; begin InitRequest(ConnectionSetup, HttpRequestMessage, HttpResponseMessage); - HttpRequestMessage := PrepareRequestMsg("Http Request Type"::GET, StrSubstNo(GetTargetDocumentUriTxt, ConnectionSetup.ServiceURL, GetSenderReceiverPrefix() + ConnectionSetup."Company Id", DocumentId)); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::GET, ConnectionSetup.ServiceURL + '/api/Peppol/inbox-document?peppolId=' + GetSenderReceiverPrefix() + ConnectionSetup."Company Id" + '&peppolInstanceId=' + DocumentId); exit(SendRequest(HttpRequestMessage, HttpResponseMessage)); end; @@ -89,7 +89,7 @@ codeunit 6380 APIRequests ConnectionSetup: Record ConnectionSetup; begin InitRequest(ConnectionSetup, HttpRequestMessage, HttpResponseMessage); - HttpRequestMessage := PrepareRequestMsg("Http Request Type"::PATCH, StrSubstNo(PatchReceivedDocumentUriTxt, ConnectionSetup.ServiceURL, EDocument."Document Id")); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::PATCH, ConnectionSetup.ServiceURL + '/api/Peppol/inbox?peppolInstanceId=' + EDocument."Document Id"); exit(SendRequest(HttpRequestMessage, HttpResponseMessage)); end; @@ -99,7 +99,7 @@ codeunit 6380 APIRequests Auth: Codeunit Auth; begin InitRequest(ConnectionSetup, HttpRequestMessage, HttpResponseMessage); - HttpRequestMessage := PrepareRequestMsg("Http Request Type"::POST, StrSubstNo(GetMarketPlaceCredentialsUriTxt, Auth.GetRootUrl(), Auth.GetBCInstanceIdentifier())); + HttpRequestMessage := PrepareRequestMsg("Http Request Type"::POST, Auth.GetRootUrl() + '/api/Registration/init?EntraTenantId=' + Auth.GetBCInstanceIdentifier()); exit(SendRequest(HttpRequestMessage, HttpResponseMessage, true)); end; @@ -220,13 +220,6 @@ codeunit 6380 APIRequests MissingSetupErr: Label 'Connection Setup is missing'; MissingSetupMessageLbl: Label 'You must set up service integration in the e-document service card.'; MissingSetupNavigationActionLbl: Label 'Show E-Document Services'; - GetSentDocumentStatusUriTxt: Label '%1/api/Peppol/status?peppolInstanceId=%2', Comment = '%1 = Service Url, %2 = Document ID', Locked = true; - SendFilePostRequestUriTxt: Label '%1/api/Peppol', Comment = '%1 = Service Url', Locked = true; - PatchADocumentUriTxt: Label '%1/api/Peppol/outbox?peppolInstanceId=%2', Comment = '%1 = Service Url, %2 = Document ID', Locked = true; - GetReceivedDocumentsUriTxt: Label '%1/api/Peppol/Inbox?peppolId=%2', Comment = '%1 = Service Url, %2 = Peppol Identifier', Locked = true; - GetTargetDocumentUriTxt: Label '%1/api/Peppol/inbox-document?peppolId=%2&peppolInstanceId=%3', Comment = '%1 = Service Url, %2 = Peppol Identifier, %3 = Peppol Gateway Instance', Locked = true; - PatchReceivedDocumentUriTxt: Label '%1/api/Peppol/inbox?peppolInstanceId=%2', Comment = '%1 = Service Url, %2 = Peppol Gateway Instance', Locked = true; - GetMarketPlaceCredentialsUriTxt: Label '%1/api/Registration/init?EntraTenantId=%2', Locked = true; UnSupportedDocumentTypeLbl: Label 'Document %1 is not supported.', Comment = '%1 = EDocument Type', Locked = true; SenderReceiverPrefixLbl: Label 'iso6523-actorid-upis::', Locked = true; } \ No newline at end of file From e991757c8afd53304bad7f816fc6c26d78ed009e Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Mon, 30 Sep 2024 11:29:33 +0200 Subject: [PATCH 30/31] Refactor - Correct Telemetry Token --- .../SignUp/app/src/ConnectionSetupCard.Page.al | 3 +-- .../EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/ConnectionSetupCard.Page.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/ConnectionSetupCard.Page.al index c611fa91ab..859575abb5 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/ConnectionSetupCard.Page.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/ConnectionSetupCard.Page.al @@ -204,6 +204,5 @@ page 6380 ConnectionSetupCard [NonDebuggable] ClientID, ClientSecret, ClientTenant, ClientUrl, RootID, RootSecret, RootTenant, RootUrl : Text; IsSaaSInfrastructure: Boolean; - ExternalServiceTok: Label 'ExternalServiceConnector', Locked = true; - + ExternalServiceTok: Label 'E-Document - SignUp', Locked = true; } \ No newline at end of file diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al index d93bac6fe7..6dfed28e56 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al @@ -556,5 +556,5 @@ codeunit 6388 Processing GetApprovalCheckStatusErr: Label 'You cannot ask for approval with the E-Document in this current status %1. You can request for approval when E-document status is Sent or Pending Response.', Comment = '%1 - Status'; CouldNotRetrieveDocumentErr: Label 'Could not retrieve document with id: %1 from the service', Comment = '%1 - Document ID'; DocumentIdNotFoundErr: Label 'Document ID not found in response'; - ExternalServiceTok: Label 'ExternalServiceConnector', Locked = true; + ExternalServiceTok: Label 'E-Document - SignUp', Locked = true; } \ No newline at end of file From a8c547d84f8e9d344b4dcf1fcb756031873e7952 Mon Sep 17 00:00:00 2001 From: Stefan Lindberg Date: Tue, 1 Oct 2024 09:39:31 +0200 Subject: [PATCH 31/31] Refactor - Fix bug introduced during refactoring, Rename procedure to more logical name --- .../EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al b/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al index 6dfed28e56..df0dd30acd 100644 --- a/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al +++ b/Apps/W1/EDocumentConnectors/SignUp/app/src/Processing.Codeunit.al @@ -43,7 +43,7 @@ codeunit 6388 Processing begin if not Connection.CheckDocumentStatus(EDocument, HttpRequest, HttpResponse) then exit; - exit(DocumentHasErrorOrProcessing(EDocument, HttpResponse, ErrorDescription)); + exit(not DocumentHasErrorOrStillInProcessing(EDocument, HttpResponse, ErrorDescription)); end; procedure GetDocumentSentResponse(EDocument: Record "E-Document"; var HttpRequestMessage: HttpRequestMessage; var HttpResponseMessage: HttpResponseMessage): Boolean @@ -218,7 +218,7 @@ codeunit 6388 Processing EDocument.Modify(); end; - local procedure DocumentHasErrorOrProcessing(EDocument: Record "E-Document"; HttpResponse: HttpResponseMessage; var ErrorDescription: Text): Boolean + local procedure DocumentHasErrorOrStillInProcessing(EDocument: Record "E-Document"; HttpResponse: HttpResponseMessage; var ErrorDescription: Text): Boolean var EDocumentService: Record "E-Document Service"; EDocumentServiceStatus: Record "E-Document Service Status";