Add Value Criteria For Payment Method

I upgrade lightning max/bitcoin min to support better control in store. Now can have setting only enable specific payment method only if value high/low I think make code simple more too and backward compatible
This commit is contained in:
XPayServer
2020-09-15 11:09:09 +02:00
parent 7e60328cff
commit e276443d2d
13 changed files with 234 additions and 377 deletions

View File

@@ -49,6 +49,44 @@ namespace BTCPayServer.Data
return result;
}
public static List<PaymentMethodCriteria> GetPaymentMethodCriteria(this StoreData storeData, BTCPayNetworkProvider networkProvider,StoreBlob storeBlob = null)
{
#pragma warning disable 612
storeBlob ??= storeData.GetStoreBlob();
return storeData.GetEnabledPaymentIds(networkProvider).Select(paymentMethodId=>
{
var matchedFromBlob =
storeBlob.PaymentMethodCriteria?.SingleOrDefault(criteria => criteria.PaymentMethod == paymentMethodId && criteria.Value != null);
if (matchedFromBlob is null && paymentMethodId.PaymentType == LightningPaymentType.Instance && storeBlob.LightningMaxValue != null)
{
return new PaymentMethodCriteria()
{
Above = false,
PaymentMethod = paymentMethodId,
Value = storeBlob.LightningMaxValue
};
}
if (matchedFromBlob is null && paymentMethodId.PaymentType == BitcoinPaymentType.Instance && storeBlob.OnChainMinValue != null)
{
return new PaymentMethodCriteria()
{
Above = true,
PaymentMethod = paymentMethodId,
Value = storeBlob.OnChainMinValue
};
}
return new PaymentMethodCriteria()
{
PaymentMethod = paymentMethodId,
Above = matchedFromBlob?.Above??true,
Value = matchedFromBlob?.Value
};
}).ToList();
#pragma warning restore 612
}
public static bool SetStoreBlob(this StoreData storeData, StoreBlob storeBlob)
{
var original = new Serializer(null).ToString(storeData.GetStoreBlob());