mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2026-01-04 22:54:20 +01:00
Removing dynamic variables from Shopify api interactions
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
}
|
||||
13
BTCPayServer/Services/Shopify/ApiModels/OrdersCountResp.cs
Normal file
13
BTCPayServer/Services/Shopify/ApiModels/OrdersCountResp.cs
Normal file
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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<TransactionDataHolder> transactions { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -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<dynamic> 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,
|
||||
|
||||
@@ -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<dynamic> TransactionsList(string orderId)
|
||||
public async Task<TransactionsListResp> 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<TransactionsListResp>(strResp);
|
||||
|
||||
return parsed;
|
||||
}
|
||||
|
||||
public async Task<dynamic> TransactionCreate(string orderId, TransactionCreate txnCreate)
|
||||
public async Task<TransactionsCreateResp> 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<TransactionsCreateResp>(strResp);
|
||||
}
|
||||
|
||||
public async Task<int> OrdersCount()
|
||||
public async Task<long> 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<OrdersCountResp>(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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user