btcpayserver/BTCPayServer/Plugins/Shopify/ShopifyExtensions.cs
Andrew Camilleri 5de93f8cc4
Abstract Store integrations (#2384)
* Decouple Shopify from Store

* Decouple shopify from store blob

* Update BTCPayServer.Tests.csproj

* Make sure shopify obj is set

* make shopify a system plugin
2021-04-08 13:37:05 +09:00

47 lines
1.5 KiB
C#

using BTCPayServer.Abstractions.Contracts;
using BTCPayServer.Abstractions.Services;
using BTCPayServer.Data;
using BTCPayServer.Plugins.Shopify.Models;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NBitcoin;
using NBXplorer;
using Newtonsoft.Json.Linq;
namespace BTCPayServer.Plugins.Shopify
{
public static class ShopifyExtensions
{
public const string StoreBlobKey = "shopify";
public static ShopifyApiClientCredentials CreateShopifyApiCredentials(this ShopifySettings shopify)
{
return new ShopifyApiClientCredentials
{
ShopName = shopify.ShopName,
ApiKey = shopify.ApiKey,
ApiPassword = shopify.Password
};
}
public static ShopifySettings GetShopifySettings(this StoreBlob storeBlob)
{
if (storeBlob.AdditionalData.TryGetValue(StoreBlobKey, out var rawS) && rawS is JObject rawObj)
{
return new Serializer(null).ToObject<ShopifySettings>(rawObj);
}
return null;
}
public static void SetShopifySettings(this StoreBlob storeBlob, ShopifySettings settings)
{
if (settings is null)
{
storeBlob.AdditionalData.Remove(StoreBlobKey);
}
else
{
storeBlob.AdditionalData.AddOrReplace(StoreBlobKey, new Serializer(null).ToString(settings));
}
}
}
}