Merge pull request #3777 from NicolasDorier/fuowiuiq

Fix: Invoices from shopify had empty orderId (Fix #3769)
This commit is contained in:
Nicolas Dorier 2022-05-25 19:32:28 +09:00 committed by GitHub
commit bad429e853
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 10 deletions

View file

@ -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")]

View file

@ -102,7 +102,7 @@ namespace BTCPayServer.Plugins.Shopify
public async Task<ShopifyOrder> 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);

View file

@ -109,10 +109,10 @@ namespace BTCPayServer.Plugins.Shopify
public async Task<IActionResult> 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<string>() { invoiceOrderId });
Request.GetAbsoluteRoot(), new List<string>() { shopifySearchTerm });
return Ok(new { invoiceId = invoice.Id, status = invoice.Status.ToString().ToLowerInvariant() });
}