Auto approve refunds (#3682)

This commit is contained in:
Andrew Camilleri
2022-04-28 13:50:28 +02:00
committed by GitHub
parent 86e53552c0
commit 382fe5cd47

View File

@@ -224,7 +224,7 @@ namespace BTCPayServer.Controllers
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)] [Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
public async Task<IActionResult> Refund(string invoiceId, RefundModel model, CancellationToken cancellationToken) public async Task<IActionResult> Refund(string invoiceId, RefundModel model, CancellationToken cancellationToken)
{ {
using var ctx = _dbContextFactory.CreateContext(); await using var ctx = _dbContextFactory.CreateContext();
var invoice = GetCurrentInvoice(); var invoice = GetCurrentInvoice();
if (invoice == null) if (invoice == null)
@@ -288,21 +288,25 @@ namespace BTCPayServer.Controllers
Name = $"Refund {invoice.Id}", Name = $"Refund {invoice.Id}",
PaymentMethodIds = new[] { paymentMethodId }, PaymentMethodIds = new[] { paymentMethodId },
StoreId = invoice.StoreId, StoreId = invoice.StoreId,
BOLT11Expiration = store.GetStoreBlob().RefundBOLT11Expiration BOLT11Expiration = store.GetStoreBlob().RefundBOLT11Expiration,
//AutoApproveClaims = true
}; };
switch (model.SelectedRefundOption) switch (model.SelectedRefundOption)
{ {
case "RateThen": case "RateThen":
createPullPayment.Currency = paymentMethodId.CryptoCode; createPullPayment.Currency = paymentMethodId.CryptoCode;
createPullPayment.Amount = model.CryptoAmountThen; createPullPayment.Amount = model.CryptoAmountThen;
createPullPayment.AutoApproveClaims = true;
break; break;
case "CurrentRate": case "CurrentRate":
createPullPayment.Currency = paymentMethodId.CryptoCode; createPullPayment.Currency = paymentMethodId.CryptoCode;
createPullPayment.Amount = model.CryptoAmountNow; createPullPayment.Amount = model.CryptoAmountNow;
createPullPayment.AutoApproveClaims = true;
break; break;
case "Fiat": case "Fiat":
createPullPayment.Currency = invoice.Currency; createPullPayment.Currency = invoice.Currency;
createPullPayment.Amount = model.FiatAmount; createPullPayment.Amount = model.FiatAmount;
createPullPayment.AutoApproveClaims = false;
break; break;
case "Custom": case "Custom":
model.Title = "How much to refund?"; model.Title = "How much to refund?";
@@ -348,10 +352,11 @@ namespace BTCPayServer.Controllers
createPullPayment = new CreatePullPayment createPullPayment = new CreatePullPayment
{ {
Name = $"Refund {invoice.Id}", Name = $"Refund {invoice.Id}",
PaymentMethodIds = new[] { paymentMethodId }, PaymentMethodIds = new[] {paymentMethodId},
StoreId = invoice.StoreId, StoreId = invoice.StoreId,
Currency = model.CustomCurrency, Currency = model.CustomCurrency,
Amount = model.CustomAmount Amount = model.CustomAmount,
AutoApproveClaims = paymentMethodId.CryptoCode == model.CustomCurrency
}; };
break; break;
default: default: