Use Outstanding amount for shopify order invoices (#3203)

* Use Outstanding amount for shopify order invoices

* consider shopify order may have multiple transactions

* Use presentment currency not just currency

fixes #2683
This commit is contained in:
Andrew Camilleri 2021-12-28 07:56:54 +01:00 committed by GitHub
parent eeebb99ca3
commit 9b7ca76b99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 6 deletions

View file

@ -9,8 +9,12 @@ namespace BTCPayServer.Plugins.Shopify.ApiModels
public string Id { get; set; }
[JsonProperty("total_price")]
public decimal TotalPrice { get; set; }
[JsonProperty("total_outstanding")]
public decimal TotalOutstanding { get; set; }
[JsonProperty("currency")]
public string Currency { get; set; }
[JsonProperty("presentment_currency")]
public string PresentmentCurrency { get; set; }
[JsonProperty("financial_status")]
public string FinancialStatus { get; set; }
[JsonProperty("transactions")]

View file

@ -19,9 +19,10 @@ namespace BTCPayServer.Plugins.Shopify
{
currency = currency.ToUpperInvariant().Trim();
var existingShopifyOrderTransactions = (await _client.TransactionsList(orderId)).transactions;
var baseParentTransaction = existingShopifyOrderTransactions.FirstOrDefault();
if (baseParentTransaction is null ||
!_keywords.Any(a => baseParentTransaction.gateway.Contains(a, StringComparison.InvariantCultureIgnoreCase)))
//if there isn't a record for btcpay payment gateway, abort
var baseParentTransaction = existingShopifyOrderTransactions.FirstOrDefault(holder => !_keywords.Any(a => holder.gateway.Contains(a, StringComparison.InvariantCultureIgnoreCase)));
if (baseParentTransaction is null)
{
return null;
}

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,currency,transactions,financial_status");
$"orders/{orderId}.json?fields=id,total_price,total_outstanding,currency,presentment_currency,transactions,financial_status");
var strResp = await SendRequest(req);

View file

@ -189,8 +189,8 @@ namespace BTCPayServer.Plugins.Shopify
var invoice = await _invoiceController.CreateInvoiceCoreRaw(
new CreateInvoiceRequest()
{
Amount = amount < order.TotalPrice ? amount : order.TotalPrice,
Currency = order.Currency,
Amount = amount < order.TotalOutstanding ? amount : order.TotalOutstanding,
Currency = order.PresentmentCurrency,
Metadata = new JObject {["orderId"] = invoiceOrderId}
}, store,
Request.GetAbsoluteRoot(), new List<string>() {invoiceOrderId});