diff --git a/BTCPayServer/Services/Shopify/ApiModels/DataHolders/TransactionDataHolder.cs b/BTCPayServer/Services/Shopify/ApiModels/DataHolders/TransactionDataHolder.cs new file mode 100644 index 000000000..136b4949d --- /dev/null +++ b/BTCPayServer/Services/Shopify/ApiModels/DataHolders/TransactionDataHolder.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BTCPayServer.Services.Shopify.ApiModels.DataHolders +{ + public class TransactionDataHolder + { + public long id { get; set; } + public long? order_id { get; set; } + public string kind { get; set; } + public string gateway { get; set; } + public string status { get; set; } + public string message { get; set; } + public DateTimeOffset created_at { get; set; } + public bool test { get; set; } + public string authorization { get; set; } + public string location_id { get; set; } + public string user_id { get; set; } + public long? parent_id { get; set; } + public DateTimeOffset processed_at { get; set; } + public string device_id { get; set; } + public object receipt { get; set; } + public string error_code { get; set; } + public string source_name { get; set; } + public string currency_exchange_adjustment { get; set; } + public string amount { get; set; } + public string currency { get; set; } + public string admin_graphql_api_id { get; set; } + } +} diff --git a/BTCPayServer/Services/Shopify/ApiModels/OrdersCountResp.cs b/BTCPayServer/Services/Shopify/ApiModels/OrdersCountResp.cs new file mode 100644 index 000000000..b34ad4e7c --- /dev/null +++ b/BTCPayServer/Services/Shopify/ApiModels/OrdersCountResp.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BTCPayServer.Services.Shopify.ApiModels +{ + public class OrdersCountResp + { + public long count { get; set; } + } +} diff --git a/BTCPayServer/Services/Shopify/ApiModels/TransactionsCreateReq.cs b/BTCPayServer/Services/Shopify/ApiModels/TransactionsCreateReq.cs new file mode 100644 index 000000000..3720b81ea --- /dev/null +++ b/BTCPayServer/Services/Shopify/ApiModels/TransactionsCreateReq.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BTCPayServer.Services.Shopify.ApiModels +{ + public class TransactionsCreateReq + { + public DataHolder transaction { get; set; } + + public class DataHolder + { + public string currency { get; set; } + public string amount { get; set; } + public string kind { get; set; } + public long? parent_id { get; set; } + public string gateway { get; set; } + public string source { get; set; } + public string authorization { get; set; } + } + } +} diff --git a/BTCPayServer/Services/Shopify/ApiModels/TransactionsCreateResp.cs b/BTCPayServer/Services/Shopify/ApiModels/TransactionsCreateResp.cs new file mode 100644 index 000000000..ae38f3f60 --- /dev/null +++ b/BTCPayServer/Services/Shopify/ApiModels/TransactionsCreateResp.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BTCPayServer.Services.Shopify.ApiModels.DataHolders; + +namespace BTCPayServer.Services.Shopify.ApiModels +{ + public class TransactionsCreateResp + { + public TransactionDataHolder transaction { get; set; } + } +} diff --git a/BTCPayServer/Services/Shopify/ApiModels/TransactionsListResp.cs b/BTCPayServer/Services/Shopify/ApiModels/TransactionsListResp.cs new file mode 100644 index 000000000..4b853a228 --- /dev/null +++ b/BTCPayServer/Services/Shopify/ApiModels/TransactionsListResp.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BTCPayServer.Services.Shopify.ApiModels.DataHolders; + +namespace BTCPayServer.Services.Shopify.ApiModels +{ + public class TransactionsListResp + { + public List transactions { get; set; } + } +} diff --git a/BTCPayServer/Services/Shopify/OrderTransactionRegisterLogic.cs b/BTCPayServer/Services/Shopify/OrderTransactionRegisterLogic.cs index 1ae80fc16..5134f7638 100644 --- a/BTCPayServer/Services/Shopify/OrderTransactionRegisterLogic.cs +++ b/BTCPayServer/Services/Shopify/OrderTransactionRegisterLogic.cs @@ -1,5 +1,8 @@ using System; +using System.Linq; using System.Threading.Tasks; +using BTCPayServer.Services.Shopify.ApiModels; +using Microsoft.EntityFrameworkCore.Internal; using Newtonsoft.Json.Linq; namespace BTCPayServer.Services.Shopify @@ -15,12 +18,12 @@ namespace BTCPayServer.Services.Shopify public async Task Process(string orderId, string currency = null, string amountCaptured = null) { - dynamic resp = await _client.TransactionsList(orderId); + var resp = await _client.TransactionsList(orderId); - JArray transactions = resp.transactions; - if (transactions != null && transactions.Count >= 1) + var txns = resp.transactions; + if (txns != null && txns.Count >= 1) { - dynamic transaction = transactions[0]; + var transaction = txns[0]; if (currency != null && currency.ToUpperInvariant().Trim() != transaction.currency.ToString().ToUpperInvariant().Trim()) { @@ -31,9 +34,9 @@ namespace BTCPayServer.Services.Shopify return null; } - var createTransaction = new TransactionCreate + var createTransaction = new TransactionsCreateReq { - transaction = new TransactionCreate.DataHolder + transaction = new TransactionsCreateReq.DataHolder { parent_id = transaction.id, currency = transaction.currency, diff --git a/BTCPayServer/Services/Shopify/ShopifyApiClient.cs b/BTCPayServer/Services/Shopify/ShopifyApiClient.cs index df04a948f..8142db419 100644 --- a/BTCPayServer/Services/Shopify/ShopifyApiClient.cs +++ b/BTCPayServer/Services/Shopify/ShopifyApiClient.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Net.Http; using System.Text; using System.Threading.Tasks; +using BTCPayServer.Services.Shopify.ApiModels; using DBriize.Utils; using Microsoft.Extensions.Logging; using Newtonsoft.Json; @@ -53,18 +54,18 @@ namespace BTCPayServer.Services.Shopify return strResp; } - public async Task TransactionsList(string orderId) + public async Task TransactionsList(string orderId) { var req = createRequest(_creds.ShopName, HttpMethod.Get, $"orders/{orderId}/transactions.json"); var strResp = await sendRequest(req); - dynamic parsed = JObject.Parse(strResp); + var parsed = JsonConvert.DeserializeObject(strResp); return parsed; } - public async Task TransactionCreate(string orderId, TransactionCreate txnCreate) + public async Task TransactionCreate(string orderId, TransactionsCreateReq txnCreate) { var postJson = JsonConvert.SerializeObject(txnCreate); @@ -72,15 +73,15 @@ namespace BTCPayServer.Services.Shopify req.Content = new StringContent(postJson, Encoding.UTF8, "application/json"); var strResp = await sendRequest(req); - return JObject.Parse(strResp); + return JsonConvert.DeserializeObject(strResp); } - public async Task OrdersCount() + public async Task OrdersCount() { var req = createRequest(_creds.ShopName, HttpMethod.Get, $"orders/count.json"); var strResp = await sendRequest(req); - dynamic parsed = JObject.Parse(strResp); + var parsed = JsonConvert.DeserializeObject(strResp); return parsed.count; } @@ -101,19 +102,4 @@ namespace BTCPayServer.Services.Shopify public string ApiPassword { get; set; } public string SharedSecret { get; set; } } - - public class TransactionCreate - { - public DataHolder transaction { get; set; } - - public class DataHolder - { - public string currency { get; set; } - public string amount { get; set; } - public string kind { get; set; } - public string parent_id { get; set; } - public string gateway { get; set; } - public string source { get; set; } - } - } } diff --git a/BTCPayServer/Services/Shopify/ShopifyOrderMarkerHostedService.cs b/BTCPayServer/Services/Shopify/ShopifyOrderMarkerHostedService.cs index 853877c70..084bf9b44 100644 --- a/BTCPayServer/Services/Shopify/ShopifyOrderMarkerHostedService.cs +++ b/BTCPayServer/Services/Shopify/ShopifyOrderMarkerHostedService.cs @@ -38,7 +38,10 @@ namespace BTCPayServer.Services.Shopify { var invoice = b.Invoice; var shopifyOrderId = invoice.Metadata?.OrderId; - if (invoice.Status == Client.Models.InvoiceStatus.Paid && shopifyOrderId != null) + // TODO: Don't code on live webcast, take time offline with Kukks to verify all flows + // Lightning it can just be paid + if ((invoice.Status == Client.Models.InvoiceStatus.Complete || invoice.Status == Client.Models.InvoiceStatus.Confirmed) + && shopifyOrderId != null) { var storeData = await _storeRepository.FindStore(invoice.StoreId); var storeBlob = storeData.GetStoreBlob();