mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-22 14:22:40 +01:00
Merge pull request #3777 from NicolasDorier/fuowiuiq
Fix: Invoices from shopify had empty orderId (Fix #3769)
This commit is contained in:
commit
bad429e853
3 changed files with 20 additions and 10 deletions
|
@ -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")]
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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() });
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue