mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 14:04:26 +01:00
Authorize invoice refund route
The customer gets a pull payment route to initiate the refund, so this one is only for merchants and needs to be authorized.
This commit is contained in:
committed by
Andrew Camilleri
parent
b68eae6f7d
commit
a4fa61e5f6
@@ -157,7 +157,7 @@ namespace BTCPayServer.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("invoices/{invoiceId}/refund")]
|
[HttpGet("invoices/{invoiceId}/refund")]
|
||||||
[AllowAnonymous]
|
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
||||||
public async Task<IActionResult> Refund([FromServices]IEnumerable<IPayoutHandler> payoutHandlers, string invoiceId, CancellationToken cancellationToken)
|
public async Task<IActionResult> Refund([FromServices]IEnumerable<IPayoutHandler> payoutHandlers, string invoiceId, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
await using var ctx = _dbContextFactory.CreateContext();
|
await using var ctx = _dbContextFactory.CreateContext();
|
||||||
@@ -183,8 +183,6 @@ namespace BTCPayServer.Controllers
|
|||||||
new { pullPaymentId = ppId });
|
new { pullPaymentId = ppId });
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpContext.SetStoreData(invoice.StoreData);
|
|
||||||
|
|
||||||
var paymentMethods = invoice.GetBlob(_NetworkProvider).GetPaymentMethods();
|
var paymentMethods = invoice.GetBlob(_NetworkProvider).GetPaymentMethods();
|
||||||
var pmis = paymentMethods.Select(method => method.GetId()).ToList();
|
var pmis = paymentMethods.Select(method => method.GetId()).ToList();
|
||||||
var options = (await payoutHandlers.GetSupportedPaymentMethods(invoice.StoreData)).Where(id => pmis.Contains(id)).ToList();
|
var options = (await payoutHandlers.GetSupportedPaymentMethods(invoice.StoreData)).Where(id => pmis.Contains(id)).ToList();
|
||||||
@@ -203,11 +201,14 @@ namespace BTCPayServer.Controllers
|
|||||||
.Select(p => p?.GetPaymentMethodId())
|
.Select(p => p?.GetPaymentMethodId())
|
||||||
.FirstOrDefault(p => p != null && options.Contains(p));
|
.FirstOrDefault(p => p != null && options.Contains(p));
|
||||||
// TODO: What if no option?
|
// TODO: What if no option?
|
||||||
var refund = new RefundModel();
|
var refund = new RefundModel
|
||||||
refund.Title = "Select a payment method";
|
{
|
||||||
refund.AvailablePaymentMethods =
|
Title = "Select a payment method",
|
||||||
new SelectList(options.Select(id => new SelectListItem(id.ToPrettyString(), id.ToString())), "Value", "Text");
|
AvailablePaymentMethods =
|
||||||
refund.SelectedPaymentMethod = defaultRefund?.ToString() ?? options.First().ToString();
|
new SelectList(options.Select(id => new SelectListItem(id.ToPrettyString(), id.ToString())),
|
||||||
|
"Value", "Text"),
|
||||||
|
SelectedPaymentMethod = defaultRefund?.ToString() ?? options.First().ToString()
|
||||||
|
};
|
||||||
|
|
||||||
// Nothing to select, skip to next
|
// Nothing to select, skip to next
|
||||||
if (refund.AvailablePaymentMethods.Count() == 1)
|
if (refund.AvailablePaymentMethods.Count() == 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user