diff --git a/src/Apps/W1/Shopify/App/src/Order handling/Codeunits/ShpfyImportOrder.Codeunit.al b/src/Apps/W1/Shopify/App/src/Order handling/Codeunits/ShpfyImportOrder.Codeunit.al index 5d08f434e6..a6b6faa89b 100644 --- a/src/Apps/W1/Shopify/App/src/Order handling/Codeunits/ShpfyImportOrder.Codeunit.al +++ b/src/Apps/W1/Shopify/App/src/Order handling/Codeunits/ShpfyImportOrder.Codeunit.al @@ -77,6 +77,9 @@ codeunit 30161 "Shpfy Import Order" OrderEvents: Codeunit "Shpfy Order Events"; OrderFulfillments: Codeunit "Shpfy Order Fulfillments"; ProcessedConflictErr: Label 'The order has already been processed in Business Central, but an edition was received from Shopify. Changes were not propagated to the processed order in Business Central. Update the processed documents to match the received data from Shopify.'; + DuplicateISOCodeTelemetryLbl: Label 'Multiple currencies found with ISO Code %1. Count: %2.', Locked = true; + CurrencyNotFoundTelemetryLbl: Label 'No currency found with ISO Code %1.', Locked = true; + CategoryTok: Label 'Shopify Integration', Locked = true; local procedure ImportOrderAndCreateOrUpdate(ShopCode: Code[20]; OrderId: BigInteger) var @@ -651,15 +654,31 @@ codeunit 30161 "Shpfy Import Order" GeneralLedgerSetup: Record "General Ledger Setup"; CurrencyCode: Code[10]; begin + if ShopifyCurrencyCode = '' then + exit(''); + + GeneralLedgerSetup.Get(); + if CopyStr(ShopifyCurrencyCode, 1, MaxStrLen(GeneralLedgerSetup."LCY Code")) = GeneralLedgerSetup."LCY Code" then + exit(''); + Currency.SetLoadFields(Code); Currency.SetRange("ISO Code", CopyStr(ShopifyCurrencyCode, 1, 3)); - if Currency.FindFirst() then + if Currency.Count() = 1 then begin + Currency.FindFirst(); CurrencyCode := Currency.Code; - GeneralLedgerSetup.Get(); - if CurrencyCode = GeneralLedgerSetup."LCY Code" then - exit('') - else - exit(CurrencyCode); + end else begin + if Currency.Count() > 1 then begin + Session.LogMessage('0000S1A', StrSubstNo(DuplicateISOCodeTelemetryLbl, ShopifyCurrencyCode, Currency.Count()), Verbosity::Warning, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', CategoryTok); + Currency.FindFirst(); + CurrencyCode := Currency.Code; + end else + if Currency.Get(CopyStr(ShopifyCurrencyCode, 1, MaxStrLen(Currency.Code))) then + CurrencyCode := Currency.Code + else + Session.LogMessage('0000S1B', StrSubstNo(CurrencyNotFoundTelemetryLbl, ShopifyCurrencyCode), Verbosity::Warning, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', CategoryTok); + end; + + exit(CurrencyCode); end; local procedure ImportCustomAttributtes(ShopifyOrderId: BigInteger; JCustomAttributtes: JsonArray) diff --git a/src/Apps/W1/Shopify/App/src/Transactions/Codeunits/ShpfyTransactions.Codeunit.al b/src/Apps/W1/Shopify/App/src/Transactions/Codeunits/ShpfyTransactions.Codeunit.al index ab6fa888f6..7b5d21159e 100644 --- a/src/Apps/W1/Shopify/App/src/Transactions/Codeunits/ShpfyTransactions.Codeunit.al +++ b/src/Apps/W1/Shopify/App/src/Transactions/Codeunits/ShpfyTransactions.Codeunit.al @@ -93,6 +93,7 @@ codeunit 30194 "Shpfy Transactions" JsonHelper.GetValueIntoField(JOrderTransaction, 'errorCode', RecordRef, OrderTransaction.FieldNo("Error Code")); JsonHelper.GetValueIntoField(JOrderTransaction, 'paymentId', RecordRef, OrderTransaction.FieldNo("Payment Id")); JsonHelper.GetValueIntoField(JOrderTransaction, 'amountSet.shopMoney.amount', RecordRef, OrderTransaction.FieldNo(Amount)); + JsonHelper.GetValueIntoField(JOrderTransaction, 'amountSet.shopMoney.currencyCode', RecordRef, OrderTransaction.FieldNo(Currency)); JsonHelper.GetValueIntoField(JOrderTransaction, 'amountSet.presentmentMoney.amount', RecordRef, OrderTransaction.FieldNo("Presentment Amount")); JsonHelper.GetValueIntoField(JOrderTransaction, 'amountSet.presentmentMoney.currencyCode', RecordRef, OrderTransaction.FieldNo("Presentment Currency")); JsonHelper.GetValueIntoField(JOrderTransaction, 'amountRoundingSet.shopMoney.amount', RecordRef, OrderTransaction.FieldNo("Rounding Amount")); diff --git a/src/Apps/W1/Shopify/Test/Shipping/ShpfyShippingChargesTest.Codeunit.al b/src/Apps/W1/Shopify/Test/Shipping/ShpfyShippingChargesTest.Codeunit.al index f32abf44c8..477b0e4a07 100644 --- a/src/Apps/W1/Shopify/Test/Shipping/ShpfyShippingChargesTest.Codeunit.al +++ b/src/Apps/W1/Shopify/Test/Shipping/ShpfyShippingChargesTest.Codeunit.al @@ -5,7 +5,9 @@ namespace Microsoft.Integration.Shopify.Test; +using Microsoft.Finance.Currency; using Microsoft.Finance.GeneralLedger.Account; +using Microsoft.Finance.GeneralLedger.Setup; using Microsoft.Finance.VAT.Setup; using Microsoft.Foundation.Enums; using Microsoft.Foundation.Shipping; @@ -353,6 +355,47 @@ codeunit 139546 "Shpfy Shipping Charges Test" ShpfyShipmentMethodMapping."Shipping Charges No." ); end; + + [Test] + [HandlerFunctions('ShippingChargesHttpHandler')] + procedure UnitTestTransactionCurrencyIsSetFromOrderImport() + var + OrderHeader: Record "Shpfy Order Header"; + OrderTransaction: Record "Shpfy Order Transaction"; + GeneralLedgerSetup: Record "General Ledger Setup"; + ImportOrder: Codeunit "Shpfy Import Order"; + begin + // [SCENARIO] When importing a Shopify order, the transaction currency is correctly populated from the JSON response. + Initialize(); + + // [GIVEN] Shopify Shop + Shop := CommunicationMgt.GetShopRecord(); + + // [GIVEN] Register Expected Outbound API Requests. + OutboundHttpRequests.Clear(); + OutboundHttpRequests.Enqueue('Transactions'); + + // [GIVEN] Shopify order is imported + ImportOrder.SetShop(Shop.Code); + ImportShopifyOrder(Shop, OrderHeader, ImportOrder, false); + + // [THEN] Transaction is created with the correct currency from shopMoney.currencyCode (DKK from resource file) + OrderTransaction.SetRange("Shopify Order Id", OrderHeader."Shopify Order Id"); + OrderTransaction.SetRange(Status, "Shpfy Transaction Status"::Success); + LibraryAssert.IsTrue(OrderTransaction.FindFirst(), 'Transaction should be created'); + + GeneralLedgerSetup.Get(); + if 'DKK' = GeneralLedgerSetup."LCY Code" then + LibraryAssert.AreEqual('', OrderTransaction.Currency, 'Currency should be empty when DKK is LCY') + else + LibraryAssert.AreEqual('DKK', OrderTransaction.Currency, 'Currency should be DKK from shopMoney.currencyCode'); + + // [THEN] Presentment currency is also set correctly + if 'DKK' = GeneralLedgerSetup."LCY Code" then + LibraryAssert.AreEqual('', OrderTransaction."Presentment Currency", 'Presentment Currency should be empty when DKK is LCY') + else + LibraryAssert.AreEqual('DKK', OrderTransaction."Presentment Currency", 'Presentment Currency should be DKK from presentmentMoney.currencyCode'); + end; #endregion [HttpClientHandler] @@ -386,6 +429,7 @@ codeunit 139546 "Shpfy Shipping Charges Test" #region Local Procedures local procedure Initialize() var + Currency: Record Currency; ShippingTime: DateFormula; AccessToken: SecretText; begin @@ -403,6 +447,17 @@ codeunit 139546 "Shpfy Shipping Charges Test" LibraryInventory.CreateShippingAgent(ShippingAgent); LibraryInventory.CreateShippingAgentService(ShippingAgentServices, ShippingAgent.Code, ShippingTime); + if not Currency.Get('DKK') then begin + Currency.Init(); + Currency.Code := 'DKK'; + Currency."ISO Code" := 'DKK'; + Currency.Insert(true); + end else + if Currency."ISO Code" <> 'DKK' then begin + Currency."ISO Code" := 'DKK'; + Currency.Modify(); + end; + Commit(); IsInitialized := true; diff --git a/src/Apps/W1/Shopify/Test/Transactions/ShpfyTransactionsTest.Codeunit.al b/src/Apps/W1/Shopify/Test/Transactions/ShpfyTransactionsTest.Codeunit.al new file mode 100644 index 0000000000..308eaa22d4 --- /dev/null +++ b/src/Apps/W1/Shopify/Test/Transactions/ShpfyTransactionsTest.Codeunit.al @@ -0,0 +1,361 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ + +namespace Microsoft.Integration.Shopify.Test; + +using Microsoft.Finance.Currency; +using Microsoft.Finance.GeneralLedger.Setup; +using Microsoft.Integration.Shopify; +using System.TestLibraries.Utilities; + +codeunit 139700 "Shpfy Transactions Test" +{ + Subtype = Test; + TestType = Uncategorized; + TestPermissions = Disabled; + TestHttpRequestPolicy = BlockOutboundRequests; + + var + Shop: Record "Shpfy Shop"; + Any: Codeunit Any; + LibraryAssert: Codeunit "Library Assert"; + LibraryRandom: Codeunit "Library - Random"; + CommunicationMgt: Codeunit "Shpfy Communication Mgt."; + InitializeTest: Codeunit "Shpfy Initialize Test"; + TransactionData: Codeunit "Library - Variable Storage"; + IsInitialized: Boolean; + + local procedure Initialize() + var + AccessToken: SecretText; + begin + if IsInitialized then + exit; + + Codeunit.Run(Codeunit::"Shpfy Initialize Test"); + Shop := CommunicationMgt.GetShopRecord(); + + AccessToken := LibraryRandom.RandText(20); + InitializeTest.RegisterAccessTokenForShop(Shop.GetStoreName(), AccessToken); + + Commit(); + IsInitialized := true; + end; + + [Test] + [HandlerFunctions('TransactionHttpHandler')] + procedure ImportTransactionSetsShopCurrencyFromJson() + var + OrderHeader: Record "Shpfy Order Header"; + OrderTransaction: Record "Shpfy Order Transaction"; + Currency: Record Currency; + ImportOrder: Codeunit "Shpfy Import Order"; + OrderHandlingHelper: Codeunit "Shpfy Order Handling Helper"; + LibraryERM: Codeunit "Library - ERM"; + OrdersToImport: Record "Shpfy Orders to Import"; + JShopifyOrder: JsonObject; + JShopifyLineItems: JsonArray; + CurrencyCode: Code[10]; + begin + // [SCENARIO] When importing a transaction, the Currency field is populated from shopMoney.currencyCode + Initialize(); + + // [GIVEN] A foreign currency with ISO Code + CurrencyCode := LibraryERM.CreateCurrencyWithRounding(); + Currency.Get(CurrencyCode); + Currency."ISO Code" := CopyStr(CurrencyCode, 1, MaxStrLen(Currency."ISO Code")); + Currency.Modify(); + + // [GIVEN] Set up mock transaction response with foreign shop currency + TransactionData.Clear(); + TransactionData.Enqueue(CurrencyCode); // shopMoney.currencyCode + TransactionData.Enqueue(100.00); // shopMoney.amount + TransactionData.Enqueue('AUD'); // presentmentMoney.currencyCode + TransactionData.Enqueue(120.00); // presentmentMoney.amount + + // [GIVEN] A Shopify order is imported + ImportOrder.SetShop(Shop.Code); + JShopifyOrder := OrderHandlingHelper.CreateShopifyOrderAsJson(Shop, OrdersToImport, JShopifyLineItems, false); + ImportOrder.ImportCreateAndUpdateOrderHeaderFromMock(Shop.Code, OrdersToImport.Id, JShopifyOrder); + ImportOrder.ImportCreateAndUpdateOrderLinesFromMock(OrdersToImport.Id, JShopifyLineItems); + Commit(); + OrderHeader.Get(OrdersToImport.Id); + + // [THEN] OrderTransaction.Currency is set to the translated currency code + OrderTransaction.SetRange("Shopify Order Id", OrderHeader."Shopify Order Id"); + OrderTransaction.SetRange(Status, "Shpfy Transaction Status"::Success); + LibraryAssert.IsTrue(OrderTransaction.FindFirst(), 'Transaction should be created'); + LibraryAssert.AreEqual(CurrencyCode, OrderTransaction.Currency, 'Currency should be set from shopMoney.currencyCode'); + end; + + [Test] + [HandlerFunctions('TransactionHttpHandler')] + procedure ImportTransactionWithLCYCurrencyReturnsEmpty() + var + OrderHeader: Record "Shpfy Order Header"; + OrderTransaction: Record "Shpfy Order Transaction"; + GeneralLedgerSetup: Record "General Ledger Setup"; + ImportOrder: Codeunit "Shpfy Import Order"; + OrderHandlingHelper: Codeunit "Shpfy Order Handling Helper"; + OrdersToImport: Record "Shpfy Orders to Import"; + JShopifyOrder: JsonObject; + JShopifyLineItems: JsonArray; + LCYCode: Code[10]; + begin + // [SCENARIO] When the shop currency matches LCY, the Currency field should be empty + Initialize(); + + // [GIVEN] The LCY code + GeneralLedgerSetup.Get(); + LCYCode := GeneralLedgerSetup."LCY Code"; + + // [GIVEN] Set up mock transaction response with LCY as shop currency + TransactionData.Clear(); + TransactionData.Enqueue(LCYCode); + TransactionData.Enqueue(100.00); + TransactionData.Enqueue(LCYCode); + TransactionData.Enqueue(100.00); + + // [GIVEN] A Shopify order is imported + ImportOrder.SetShop(Shop.Code); + JShopifyOrder := OrderHandlingHelper.CreateShopifyOrderAsJson(Shop, OrdersToImport, JShopifyLineItems, false); + ImportOrder.ImportCreateAndUpdateOrderHeaderFromMock(Shop.Code, OrdersToImport.Id, JShopifyOrder); + ImportOrder.ImportCreateAndUpdateOrderLinesFromMock(OrdersToImport.Id, JShopifyLineItems); + Commit(); + OrderHeader.Get(OrdersToImport.Id); + + // [THEN] OrderTransaction.Currency is empty (LCY is represented as blank in BC) + OrderTransaction.SetRange("Shopify Order Id", OrderHeader."Shopify Order Id"); + OrderTransaction.SetRange(Status, "Shpfy Transaction Status"::Success); + LibraryAssert.IsTrue(OrderTransaction.FindFirst(), 'Transaction should be created'); + LibraryAssert.AreEqual('', OrderTransaction.Currency, 'Currency should be empty for LCY'); + end; + + [Test] + [HandlerFunctions('TransactionHttpHandler')] + procedure ImportTransactionSetsPresentmentCurrencyFromJson() + var + OrderHeader: Record "Shpfy Order Header"; + OrderTransaction: Record "Shpfy Order Transaction"; + Currency: Record Currency; + GeneralLedgerSetup: Record "General Ledger Setup"; + ImportOrder: Codeunit "Shpfy Import Order"; + OrderHandlingHelper: Codeunit "Shpfy Order Handling Helper"; + LibraryERM: Codeunit "Library - ERM"; + OrdersToImport: Record "Shpfy Orders to Import"; + JShopifyOrder: JsonObject; + JShopifyLineItems: JsonArray; + PresentmentCurrencyCode: Code[10]; + LCYCode: Code[10]; + begin + // [SCENARIO] When importing a transaction, Presentment Currency is populated from presentmentMoney.currencyCode + Initialize(); + + // [GIVEN] LCY code and a foreign presentment currency + GeneralLedgerSetup.Get(); + LCYCode := GeneralLedgerSetup."LCY Code"; + PresentmentCurrencyCode := LibraryERM.CreateCurrencyWithRounding(); + Currency.Get(PresentmentCurrencyCode); + Currency."ISO Code" := CopyStr(PresentmentCurrencyCode, 1, MaxStrLen(Currency."ISO Code")); + Currency.Modify(); + + // [GIVEN] Set up mock transaction response with LCY shop currency and foreign presentment + TransactionData.Clear(); + TransactionData.Enqueue(LCYCode); + TransactionData.Enqueue(100.00); + TransactionData.Enqueue(PresentmentCurrencyCode); + TransactionData.Enqueue(150.00); + + // [GIVEN] A Shopify order is imported + ImportOrder.SetShop(Shop.Code); + JShopifyOrder := OrderHandlingHelper.CreateShopifyOrderAsJson(Shop, OrdersToImport, JShopifyLineItems, false); + ImportOrder.ImportCreateAndUpdateOrderHeaderFromMock(Shop.Code, OrdersToImport.Id, JShopifyOrder); + ImportOrder.ImportCreateAndUpdateOrderLinesFromMock(OrdersToImport.Id, JShopifyLineItems); + Commit(); + OrderHeader.Get(OrdersToImport.Id); + + // [THEN] Presentment Currency is set correctly + OrderTransaction.SetRange("Shopify Order Id", OrderHeader."Shopify Order Id"); + OrderTransaction.SetRange(Status, "Shpfy Transaction Status"::Success); + LibraryAssert.IsTrue(OrderTransaction.FindFirst(), 'Transaction should be created'); + LibraryAssert.AreEqual('', OrderTransaction.Currency, 'Currency should be empty for LCY shop currency'); + LibraryAssert.AreEqual(PresentmentCurrencyCode, OrderTransaction."Presentment Currency", 'Presentment Currency should be set from presentmentMoney.currencyCode'); + end; + + [Test] + [HandlerFunctions('TransactionHttpHandler')] + procedure ImportTransactionAmountMatchesShopMoney() + var + OrderHeader: Record "Shpfy Order Header"; + OrderTransaction: Record "Shpfy Order Transaction"; + Currency: Record Currency; + GeneralLedgerSetup: Record "General Ledger Setup"; + ImportOrder: Codeunit "Shpfy Import Order"; + OrderHandlingHelper: Codeunit "Shpfy Order Handling Helper"; + LibraryERM: Codeunit "Library - ERM"; + OrdersToImport: Record "Shpfy Orders to Import"; + JShopifyOrder: JsonObject; + JShopifyLineItems: JsonArray; + PresentmentCurrencyCode: Code[10]; + ShopAmount: Decimal; + PresentmentAmount: Decimal; + begin + // [SCENARIO] Amount field contains shopMoney.amount and Presentment Amount contains presentmentMoney.amount + Initialize(); + + // [GIVEN] A foreign presentment currency + GeneralLedgerSetup.Get(); + PresentmentCurrencyCode := LibraryERM.CreateCurrencyWithRounding(); + Currency.Get(PresentmentCurrencyCode); + Currency."ISO Code" := CopyStr(PresentmentCurrencyCode, 1, MaxStrLen(Currency."ISO Code")); + Currency.Modify(); + + // [GIVEN] Set up mock transaction response with specific amounts + ShopAmount := 85.50; + PresentmentAmount := 120.75; + TransactionData.Clear(); + TransactionData.Enqueue(GeneralLedgerSetup."LCY Code"); + TransactionData.Enqueue(ShopAmount); + TransactionData.Enqueue(PresentmentCurrencyCode); + TransactionData.Enqueue(PresentmentAmount); + + // [GIVEN] A Shopify order is imported + ImportOrder.SetShop(Shop.Code); + JShopifyOrder := OrderHandlingHelper.CreateShopifyOrderAsJson(Shop, OrdersToImport, JShopifyLineItems, false); + ImportOrder.ImportCreateAndUpdateOrderHeaderFromMock(Shop.Code, OrdersToImport.Id, JShopifyOrder); + ImportOrder.ImportCreateAndUpdateOrderLinesFromMock(OrdersToImport.Id, JShopifyLineItems); + Commit(); + OrderHeader.Get(OrdersToImport.Id); + + // [THEN] Amounts are correctly mapped + OrderTransaction.SetRange("Shopify Order Id", OrderHeader."Shopify Order Id"); + OrderTransaction.SetRange(Status, "Shpfy Transaction Status"::Success); + LibraryAssert.IsTrue(OrderTransaction.FindFirst(), 'Transaction should be created'); + LibraryAssert.AreEqual(ShopAmount, OrderTransaction.Amount, 'Amount should match shopMoney.amount'); + LibraryAssert.AreEqual(PresentmentAmount, OrderTransaction."Presentment Amount", 'Presentment Amount should match presentmentMoney.amount'); + end; + + [Test] + procedure TranslateCurrencyCodeWithISOCodeMatch() + var + Currency: Record Currency; + ImportOrder: Codeunit "Shpfy Import Order"; + LibraryERM: Codeunit "Library - ERM"; + CurrencyCode: Code[10]; + Result: Code[10]; + begin + // [SCENARIO] TranslateCurrencyCode finds currency by ISO Code when exactly one match exists + Initialize(); + + // [GIVEN] A currency with ISO Code set + CurrencyCode := LibraryERM.CreateCurrencyWithRounding(); + Currency.Get(CurrencyCode); + Currency."ISO Code" := 'ZZZ'; + Currency.Modify(); + + // [WHEN] TranslateCurrencyCode is called with the ISO Code + ImportOrder.SetShop(Shop.Code); + Result := ImportOrder.TranslateCurrencyCode('ZZZ'); + + // [THEN] The currency code is returned + LibraryAssert.AreEqual(CurrencyCode, Result, 'Should return currency code matching ISO Code'); + end; + + [Test] + procedure TranslateCurrencyCodeWithEmptyInput() + var + ImportOrder: Codeunit "Shpfy Import Order"; + Result: Code[10]; + begin + // [SCENARIO] TranslateCurrencyCode returns empty for empty input + Initialize(); + + // [WHEN] TranslateCurrencyCode is called with empty string + ImportOrder.SetShop(Shop.Code); + Result := ImportOrder.TranslateCurrencyCode(''); + + // [THEN] Returns empty + LibraryAssert.AreEqual('', Result, 'Should return empty for empty input'); + end; + + [Test] + procedure TranslateCurrencyCodeFallsBackToCodeMatch() + var + Currency: Record Currency; + ImportOrder: Codeunit "Shpfy Import Order"; + LibraryERM: Codeunit "Library - ERM"; + CurrencyCode: Code[10]; + Result: Code[10]; + begin + // [SCENARIO] When no currency matches by ISO Code, TranslateCurrencyCode falls back to Currency.Get(code) + Initialize(); + + // [GIVEN] A currency whose Code matches the input but ISO Code does not + CurrencyCode := LibraryERM.CreateCurrencyWithRounding(); + Currency.Get(CurrencyCode); + Currency."ISO Code" := 'XXX'; + Currency.Modify(); + + // [WHEN] TranslateCurrencyCode is called with the currency code (not matching any ISO Code) + ImportOrder.SetShop(Shop.Code); + Result := ImportOrder.TranslateCurrencyCode(CurrencyCode); + + // [THEN] The currency code is returned via Get fallback + LibraryAssert.AreEqual(CurrencyCode, Result, 'Should find currency by Code when ISO Code does not match'); + end; + + [Test] + procedure TranslateCurrencyCodeReturnsEmptyWhenNotFound() + var + ImportOrder: Codeunit "Shpfy Import Order"; + Result: Code[10]; + begin + // [SCENARIO] TranslateCurrencyCode returns empty when currency is not found by ISO Code or Code + Initialize(); + + // [WHEN] TranslateCurrencyCode is called with a non-existent currency code + ImportOrder.SetShop(Shop.Code); + Result := ImportOrder.TranslateCurrencyCode('QQQ'); + + // [THEN] Returns empty + LibraryAssert.AreEqual('', Result, 'Should return empty when currency not found'); + end; + + [HttpClientHandler] + internal procedure TransactionHttpHandler(Request: TestHttpRequestMessage; var Response: TestHttpResponseMessage): Boolean + var + ShopCurrencyCode: Text; + ShopAmount: Decimal; + PresentmentCurrencyCode: Text; + PresentmentAmount: Decimal; + TransactionId: BigInteger; + Body: Text; + TransactionResponseLbl: Label '{"data":{"order":{"transactions":[{"authorizationCode":"","createdAt":"%1","errorCode":null,"formattedGateway":"Shopify Payments","gateway":"shopify_payments","id":"gid://shopify/OrderTransaction/%2","kind":"SALE","paymentId":"gid://shopify/Payment/%3","receiptJson":"{}","status":"SUCCESS","test":true,"amountSet":{"shopMoney":{"amount":"%4","currencyCode":"%5"},"presentmentMoney":{"amount":"%6","currencyCode":"%7"}},"amountRoundingSet":{"shopMoney":{"amount":"0","currencyCode":"%5"},"presentmentMoney":{"amount":"0","currencyCode":"%7"}},"paymentDetails":null}]}},"extensions":{"cost":{"requestedQueryCost":3,"actualQueryCost":3,"throttleStatus":{"maximumAvailable":2000.0,"currentlyAvailable":1997,"restoreRate":100.0}}}}', Locked = true; + begin + if not InitializeTest.VerifyRequestUrl(Request.Path, Shop."Shopify URL") then + exit(true); + + if TransactionData.Length() > 0 then begin + ShopCurrencyCode := TransactionData.DequeueText(); + ShopAmount := TransactionData.DequeueDecimal(); + PresentmentCurrencyCode := TransactionData.DequeueText(); + PresentmentAmount := TransactionData.DequeueDecimal(); + TransactionId := Any.IntegerInRange(100000, 999999); + Body := StrSubstNo( + TransactionResponseLbl, + Format(CurrentDateTime(), 0, 9), + TransactionId, + Any.IntegerInRange(100000, 999999), + Format(ShopAmount, 0, 9), + ShopCurrencyCode, + Format(PresentmentAmount, 0, 9), + PresentmentCurrencyCode + ); + Response.Content.WriteFrom(Body); + end else + Response.Content.WriteFrom('{"data":{"order":{"transactions":[]}}}'); + exit(false); + end; +}