From 0818abe233d7a769cf82323363041ec5c1f58a53 Mon Sep 17 00:00:00 2001 From: rockstardev Date: Sun, 13 Sep 2020 23:54:15 -0500 Subject: [PATCH] Prefixing Shopify invoices, passing real orderId --- .../Services/Shopify/ShopifyOrderMarkerHostedService.cs | 7 ++++++- BTCPayServer/wwwroot/shopify/btcpay-shopify-checkout.js | 7 +++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/BTCPayServer/Services/Shopify/ShopifyOrderMarkerHostedService.cs b/BTCPayServer/Services/Shopify/ShopifyOrderMarkerHostedService.cs index 79df618ea..853877c70 100644 --- a/BTCPayServer/Services/Shopify/ShopifyOrderMarkerHostedService.cs +++ b/BTCPayServer/Services/Shopify/ShopifyOrderMarkerHostedService.cs @@ -28,6 +28,8 @@ namespace BTCPayServer.Services.Shopify private CancellationTokenSource _Cts; private readonly CompositeDisposable leases = new CompositeDisposable(); + public const string SHOPIFY_ORDER_ID_PREFIX = "shopify-"; + public Task StartAsync(CancellationToken cancellationToken) { _Cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); @@ -41,8 +43,11 @@ namespace BTCPayServer.Services.Shopify var storeData = await _storeRepository.FindStore(invoice.StoreId); var storeBlob = storeData.GetStoreBlob(); - if (storeBlob.Shopify?.IntegratedAt.HasValue == true) + if (storeBlob.Shopify?.IntegratedAt.HasValue == true && + shopifyOrderId.StartsWith(SHOPIFY_ORDER_ID_PREFIX, StringComparison.OrdinalIgnoreCase)) { + shopifyOrderId = shopifyOrderId[SHOPIFY_ORDER_ID_PREFIX.Length..]; + var client = createShopifyApiClient(storeBlob.Shopify); if (!await client.OrderExists(shopifyOrderId)) { diff --git a/BTCPayServer/wwwroot/shopify/btcpay-shopify-checkout.js b/BTCPayServer/wwwroot/shopify/btcpay-shopify-checkout.js index 413dcff67..200804137 100644 --- a/BTCPayServer/wwwroot/shopify/btcpay-shopify-checkout.js +++ b/BTCPayServer/wwwroot/shopify/btcpay-shopify-checkout.js @@ -17,6 +17,7 @@ // extracted from shopify initialized page const shopify_price = Shopify.checkout.payment_due; const shopify_currency = Shopify.checkout.currency; + const shopify_order_id = "shopify-" + Shopify.checkout.order_id; "use strict"; const pageElements = document.querySelector.bind(document), @@ -79,9 +80,7 @@ pageItems.orderConfirmed && (pageItems.orderConfirmed.style.display = "none"), pageItems.orderConfirmedDescription && (pageItems.orderConfirmedDescription.style.display = "none"); - const orderId = pageItems.orderNumber.innerText.replace("Order #", ""); - - const url = BTCPAYSERVER_URL + "/invoices" + "?storeId=" + STORE_ID + "&orderId=" + orderId + "&status=complete"; + const url = BTCPAYSERVER_URL + "/invoices" + "?storeId=" + STORE_ID + "&orderId=" + shopify_order_id + "&status=complete"; // Check if already paid. fetch(url, { @@ -112,7 +111,7 @@ { price: shopify_price, currency: shopify_currency, - orderId: orderId + orderId: shopify_order_id } ) .then(function (invoice) {