diff --git a/BTCPayServer/Plugins/Shopify/ApiModels/ShopifyOrder.cs b/BTCPayServer/Plugins/Shopify/ApiModels/ShopifyOrder.cs index a77c5bfd2..0d29f78f5 100644 --- a/BTCPayServer/Plugins/Shopify/ApiModels/ShopifyOrder.cs +++ b/BTCPayServer/Plugins/Shopify/ApiModels/ShopifyOrder.cs @@ -6,9 +6,9 @@ namespace BTCPayServer.Plugins.Shopify.ApiModels public class ShopifyOrder { [JsonProperty("id")] - public string Id { get; set; } + public long Id { get; set; } [JsonProperty("order_number")] - public string OrderNumber { get; set; } + public long OrderNumber { get; set; } [JsonProperty("total_price")] public decimal TotalPrice { get; set; } [JsonProperty("total_outstanding")] diff --git a/BTCPayServer/Plugins/Shopify/ShopifyApiClient.cs b/BTCPayServer/Plugins/Shopify/ShopifyApiClient.cs index ce4425236..1c9cce886 100644 --- a/BTCPayServer/Plugins/Shopify/ShopifyApiClient.cs +++ b/BTCPayServer/Plugins/Shopify/ShopifyApiClient.cs @@ -102,7 +102,7 @@ namespace BTCPayServer.Plugins.Shopify public async Task GetOrder(string orderId) { var req = CreateRequest(_credentials.ShopName, HttpMethod.Get, - $"orders/{orderId}.json?fields=id,total_price,total_outstanding,currency,presentment_currency,transactions,financial_status"); + $"orders/{orderId}.json?fields=id,order_number,total_price,total_outstanding,currency,presentment_currency,transactions,financial_status"); var strResp = await SendRequest(req); diff --git a/BTCPayServer/Plugins/Shopify/UIShopifyController.cs b/BTCPayServer/Plugins/Shopify/UIShopifyController.cs index 47220f699..65bbf54c9 100644 --- a/BTCPayServer/Plugins/Shopify/UIShopifyController.cs +++ b/BTCPayServer/Plugins/Shopify/UIShopifyController.cs @@ -109,10 +109,10 @@ namespace BTCPayServer.Plugins.Shopify public async Task ShopifyInvoiceEndpoint( string storeId, string orderId, decimal amount, bool checkOnly = false) { - var invoiceOrderId = $"{ShopifyOrderMarkerHostedService.SHOPIFY_ORDER_ID_PREFIX}{orderId}"; + var shopifySearchTerm = $"{ShopifyOrderMarkerHostedService.SHOPIFY_ORDER_ID_PREFIX}{orderId}"; var matchedExistingInvoices = await _invoiceRepository.GetInvoices(new InvoiceQuery() { - TextSearch = invoiceOrderId, + TextSearch = shopifySearchTerm, StoreId = new[] { storeId } }); matchedExistingInvoices = matchedExistingInvoices.Where(entity => @@ -146,7 +146,7 @@ namespace BTCPayServer.Plugins.Shopify { client = new ShopifyApiClient(_clientFactory, shopify.CreateShopifyApiCredentials()); order = await client.GetOrder(orderId); - if (string.IsNullOrEmpty(order?.Id)) + if (order?.Id is null) { return NotFound(); } @@ -178,7 +178,7 @@ namespace BTCPayServer.Plugins.Shopify if (shopify?.IntegratedAt.HasValue is true) { - if (string.IsNullOrEmpty(order?.Id) || + if (order?.Id is null || !new[] { "pending", "partially_paid" }.Contains(order.FinancialStatus)) { return NotFound(); @@ -190,10 +190,20 @@ namespace BTCPayServer.Plugins.Shopify { Amount = amount < order.TotalOutstanding ? amount : order.TotalOutstanding, Currency = order.PresentmentCurrency, - Metadata = new JObject { ["orderId"] = order.OrderNumber }, - AdditionalSearchTerms = new []{ "shopify", order.OrderNumber, order.Id, invoiceOrderId} + Metadata = new JObject + { + ["orderId"] = order.OrderNumber, + ["shopifyOrderId"] = order.Id, + ["shopifyOrderNumber"] = order.OrderNumber + }, + AdditionalSearchTerms = new [] + { + order.OrderNumber.ToString(CultureInfo.InvariantCulture), + order.Id.ToString(CultureInfo.InvariantCulture), + shopifySearchTerm + } }, store, - Request.GetAbsoluteRoot(), new List() { invoiceOrderId }); + Request.GetAbsoluteRoot(), new List() { shopifySearchTerm }); return Ok(new { invoiceId = invoice.Id, status = invoice.Status.ToString().ToLowerInvariant() }); }