2018-02-18 18:38:03 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using BTCPayServer.Payments;
|
|
|
|
|
|
|
|
|
|
namespace BTCPayServer.Services.Invoices
|
|
|
|
|
{
|
2018-02-19 07:09:05 +01:00
|
|
|
|
public class PaymentMethodDictionary : IEnumerable<PaymentMethod>
|
2018-02-18 18:38:03 +01:00
|
|
|
|
{
|
2018-02-19 07:09:05 +01:00
|
|
|
|
Dictionary<PaymentMethodId, PaymentMethod> _Inner = new Dictionary<PaymentMethodId, PaymentMethod>();
|
|
|
|
|
public PaymentMethodDictionary()
|
2018-02-18 18:38:03 +01:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-19 07:09:05 +01:00
|
|
|
|
public PaymentMethod this[PaymentMethodId index]
|
2018-02-18 18:38:03 +01:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _Inner[index];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-19 07:09:05 +01:00
|
|
|
|
public void Add(PaymentMethod paymentMethod)
|
2018-02-18 18:38:03 +01:00
|
|
|
|
{
|
2018-02-19 07:09:05 +01:00
|
|
|
|
_Inner.Add(paymentMethod.GetId(), paymentMethod);
|
2018-02-18 18:38:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-19 07:09:05 +01:00
|
|
|
|
public void Remove(PaymentMethod paymentMethod)
|
2018-02-18 18:38:03 +01:00
|
|
|
|
{
|
2018-02-19 07:09:05 +01:00
|
|
|
|
_Inner.Remove(paymentMethod.GetId());
|
2018-02-18 18:38:03 +01:00
|
|
|
|
}
|
2018-02-19 07:09:05 +01:00
|
|
|
|
public bool TryGetValue(PaymentMethodId paymentMethodId, out PaymentMethod data)
|
2018-02-18 18:38:03 +01:00
|
|
|
|
{
|
2018-02-19 07:09:05 +01:00
|
|
|
|
if (paymentMethodId == null)
|
|
|
|
|
throw new ArgumentNullException(nameof(paymentMethodId));
|
|
|
|
|
return _Inner.TryGetValue(paymentMethodId, out data);
|
2018-02-18 18:38:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-19 07:09:05 +01:00
|
|
|
|
public void AddOrReplace(PaymentMethod paymentMethod)
|
2018-02-18 18:38:03 +01:00
|
|
|
|
{
|
2018-02-19 07:09:05 +01:00
|
|
|
|
var key = paymentMethod.GetId();
|
2018-02-18 18:38:03 +01:00
|
|
|
|
_Inner.Remove(key);
|
2018-02-19 07:09:05 +01:00
|
|
|
|
_Inner.Add(key, paymentMethod);
|
2018-02-18 18:38:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-19 07:09:05 +01:00
|
|
|
|
public IEnumerator<PaymentMethod> GetEnumerator()
|
2018-02-18 18:38:03 +01:00
|
|
|
|
{
|
|
|
|
|
return _Inner.Values.GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
|
{
|
|
|
|
|
return GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-19 07:09:05 +01:00
|
|
|
|
public PaymentMethod TryGet(PaymentMethodId paymentMethodId)
|
2018-02-18 18:38:03 +01:00
|
|
|
|
{
|
2018-02-19 07:09:05 +01:00
|
|
|
|
if (paymentMethodId == null)
|
|
|
|
|
throw new ArgumentNullException(nameof(paymentMethodId));
|
|
|
|
|
_Inner.TryGetValue(paymentMethodId, out var value);
|
2018-02-18 18:38:03 +01:00
|
|
|
|
return value;
|
|
|
|
|
}
|
2019-06-04 01:59:01 +02:00
|
|
|
|
public PaymentMethod TryGet(string network, PaymentType paymentType)
|
2018-02-18 18:38:03 +01:00
|
|
|
|
{
|
|
|
|
|
if (network == null)
|
|
|
|
|
throw new ArgumentNullException(nameof(network));
|
2018-02-19 07:09:05 +01:00
|
|
|
|
var id = new PaymentMethodId(network, paymentType);
|
2018-02-18 18:38:03 +01:00
|
|
|
|
return TryGet(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|