2020-06-28 21:44:35 -05:00
|
|
|
using System;
|
2018-02-19 02:38:03 +09:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using BTCPayServer.Payments;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Services.Invoices
|
|
|
|
{
|
2018-02-19 15:09:05 +09:00
|
|
|
public class PaymentMethodDictionary : IEnumerable<PaymentMethod>
|
2018-02-19 02:38:03 +09:00
|
|
|
{
|
2020-06-28 22:07:48 -05:00
|
|
|
readonly Dictionary<PaymentMethodId, PaymentMethod> _Inner = new Dictionary<PaymentMethodId, PaymentMethod>();
|
2018-02-19 15:09:05 +09:00
|
|
|
public PaymentMethodDictionary()
|
2018-02-19 02:38:03 +09:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-19 15:09:05 +09:00
|
|
|
public PaymentMethod this[PaymentMethodId index]
|
2018-02-19 02:38:03 +09:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return _Inner[index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-19 15:09:05 +09:00
|
|
|
public void Add(PaymentMethod paymentMethod)
|
2018-02-19 02:38:03 +09:00
|
|
|
{
|
2018-02-19 15:09:05 +09:00
|
|
|
_Inner.Add(paymentMethod.GetId(), paymentMethod);
|
2018-02-19 02:38:03 +09:00
|
|
|
}
|
|
|
|
|
2018-02-19 15:09:05 +09:00
|
|
|
public void Remove(PaymentMethod paymentMethod)
|
2018-02-19 02:38:03 +09:00
|
|
|
{
|
2018-02-19 15:09:05 +09:00
|
|
|
_Inner.Remove(paymentMethod.GetId());
|
2018-02-19 02:38:03 +09:00
|
|
|
}
|
2018-02-19 15:09:05 +09:00
|
|
|
public bool TryGetValue(PaymentMethodId paymentMethodId, out PaymentMethod data)
|
2018-02-19 02:38:03 +09:00
|
|
|
{
|
2021-12-28 17:39:54 +09:00
|
|
|
ArgumentNullException.ThrowIfNull(paymentMethodId);
|
2018-02-19 15:09:05 +09:00
|
|
|
return _Inner.TryGetValue(paymentMethodId, out data);
|
2018-02-19 02:38:03 +09:00
|
|
|
}
|
|
|
|
|
2018-02-19 15:09:05 +09:00
|
|
|
public void AddOrReplace(PaymentMethod paymentMethod)
|
2018-02-19 02:38:03 +09:00
|
|
|
{
|
2018-02-19 15:09:05 +09:00
|
|
|
var key = paymentMethod.GetId();
|
2018-02-19 02:38:03 +09:00
|
|
|
_Inner.Remove(key);
|
2018-02-19 15:09:05 +09:00
|
|
|
_Inner.Add(key, paymentMethod);
|
2018-02-19 02:38:03 +09:00
|
|
|
}
|
|
|
|
|
2018-02-19 15:09:05 +09:00
|
|
|
public IEnumerator<PaymentMethod> GetEnumerator()
|
2018-02-19 02:38:03 +09:00
|
|
|
{
|
|
|
|
return _Inner.Values.GetEnumerator();
|
|
|
|
}
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
{
|
|
|
|
return GetEnumerator();
|
|
|
|
}
|
|
|
|
|
2018-02-19 15:09:05 +09:00
|
|
|
public PaymentMethod TryGet(PaymentMethodId paymentMethodId)
|
2018-02-19 02:38:03 +09:00
|
|
|
{
|
2021-12-28 17:39:54 +09:00
|
|
|
ArgumentNullException.ThrowIfNull(paymentMethodId);
|
2018-02-19 15:09:05 +09:00
|
|
|
_Inner.TryGetValue(paymentMethodId, out var value);
|
2018-02-19 02:38:03 +09:00
|
|
|
return value;
|
|
|
|
}
|
2019-06-04 08:59:01 +09:00
|
|
|
public PaymentMethod TryGet(string network, PaymentType paymentType)
|
2018-02-19 02:38:03 +09:00
|
|
|
{
|
2021-12-28 17:39:54 +09:00
|
|
|
ArgumentNullException.ThrowIfNull(network);
|
2018-02-19 15:09:05 +09:00
|
|
|
var id = new PaymentMethodId(network, paymentType);
|
2018-02-19 02:38:03 +09:00
|
|
|
return TryGet(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|