btcpayserver/BTCPayServer/Data/PaymentDataExtensions.cs

55 lines
2.2 KiB
C#
Raw Normal View History

2020-11-16 12:05:15 +09:00
using System.Runtime.InteropServices;
using BTCPayServer.Payments;
using BTCPayServer.Services.Invoices;
using Newtonsoft.Json.Linq;
namespace BTCPayServer.Data
{
public static class PaymentDataExtensions
{
public static void SetBlob(this PaymentData paymentData, PaymentEntity entity)
{
paymentData.Type = entity.GetPaymentMethodId().ToStringNormalized();
paymentData.Blob2 = entity.Network.ToString(entity);
}
Transfer Processors (#3476) * Automated Transfer processors This PR introduces a few things: * Payouts can now be directly nested under a store instead of through a pull payment. * The Wallet Send screen now has an option to "schedule" instead of simply creating a transaction. When you click on schedule, all transaction destinations are converted into approved payouts. Any options relating to fees or coin selection are discarded. * There is a new concept introduced, called "Transfer Processors". Transfer Processors are services for stores that process payouts that are awaiting payment. Each processor specifies which payment methods it can handle. BTCPay Server will have some forms of transfer processors baked in but it has been designed to allow the Plugin System to provide additional processors. * The initial transfer processors provided are "automated processors", for on chain and lightning payment methods. They can be configured to process payouts every X amount of minutes. For on-chain, this means payments are batched into one transaction, resulting in more efficient and cheaper fees for processing. * * fix build * extract * remove magic string stuff * fix error message when scheduling * Paginate migration * add payout count to payment method tab * remove unused var * add protip * optimzie payout migration dramatically * Remove useless double condition * Fix bunch of warnings * Remove warning * Remove warnigns * Rename to Payout processors * fix typo Co-authored-by: Nicolas Dorier <nicolas.dorier@gmail.com>
2022-04-24 05:19:34 +02:00
public static PaymentEntity GetBlob(this PaymentData paymentData, BTCPayNetworkProvider networks)
{
#pragma warning disable CS0618 // Type or member is obsolete
if (paymentData.Blob is not null && paymentData.Blob.Length != 0)
{
var unziped = ZipUtils.Unzip(paymentData.Blob);
var cryptoCode = "BTC";
if (JObject.Parse(unziped).TryGetValue("cryptoCode", out var v) && v.Type == JTokenType.String)
cryptoCode = v.Value<string>();
var network = networks.GetNetwork<BTCPayNetworkBase>(cryptoCode);
PaymentEntity paymentEntity = null;
if (network == null)
{
return null;
}
else
{
paymentEntity = network.ToObject<PaymentEntity>(unziped);
}
paymentEntity.Network = network;
paymentEntity.Accounted = paymentData.Accounted;
return paymentEntity;
}
#pragma warning restore CS0618 // Type or member is obsolete
if (paymentData.Blob2 is not null)
{
if (!PaymentMethodId.TryParse(paymentData.Type, out var pmi))
return null;
var network = networks.GetNetwork<BTCPayNetworkBase>(pmi.CryptoCode);
if (network is null)
return null;
var entity = network.ToObject<PaymentEntity>(paymentData.Blob2);
entity.Network = network;
entity.Accounted = paymentData.Accounted;
return entity;
}
return null;
}
}
}