Require non interactivity for boltcard payments (#6289)

This commit is contained in:
Nicolas Dorier
2024-10-18 14:09:41 +09:00
committed by GitHub
parent 6dfb369b55
commit 8e098710c1
2 changed files with 13 additions and 3 deletions

View File

@@ -65,6 +65,6 @@ public class UIBoltcardController : Controller
if (!cardKey.CheckSunMac(c, piccData)) if (!cardKey.CheckSunMac(c, piccData))
return BadRequest(new LNUrlStatusResponse { Status = "ERROR", Reason = "Replayed or expired query" }); return BadRequest(new LNUrlStatusResponse { Status = "ERROR", Reason = "Replayed or expired query" });
LNURLController.ControllerContext.HttpContext = HttpContext; LNURLController.ControllerContext.HttpContext = HttpContext;
return await LNURLController.GetLNURLForPullPayment("BTC", registration.PullPaymentId, pr, $"{p}-{c}", cancellationToken); return await LNURLController.GetLNURLForPullPayment("BTC", registration.PullPaymentId, pr, $"{p}-{c}", true, cancellationToken);
} }
} }

View File

@@ -102,11 +102,11 @@ namespace BTCPayServer
[HttpGet("withdraw/pp/{pullPaymentId}")] [HttpGet("withdraw/pp/{pullPaymentId}")]
public Task<IActionResult> GetLNURLForPullPayment(string cryptoCode, string pullPaymentId, [FromQuery] string pr, CancellationToken cancellationToken) public Task<IActionResult> GetLNURLForPullPayment(string cryptoCode, string pullPaymentId, [FromQuery] string pr, CancellationToken cancellationToken)
{ {
return GetLNURLForPullPayment(cryptoCode, pullPaymentId, pr, pullPaymentId, cancellationToken); return GetLNURLForPullPayment(cryptoCode, pullPaymentId, pr, pullPaymentId, false, cancellationToken);
} }
[NonAction] [NonAction]
internal async Task<IActionResult> GetLNURLForPullPayment(string cryptoCode, string pullPaymentId, string pr, string k1, CancellationToken cancellationToken) internal async Task<IActionResult> GetLNURLForPullPayment(string cryptoCode, string pullPaymentId, string pr, string k1, bool nonInteractiveOnly, CancellationToken cancellationToken)
{ {
var network = GetNetwork(cryptoCode); var network = GetNetwork(cryptoCode);
if (network is null || !network.SupportLightning) if (network is null || !network.SupportLightning)
@@ -175,8 +175,18 @@ namespace BTCPayServer
}); });
var processorBlob = processors.FirstOrDefault()?.HasTypedBlob<LightningAutomatedPayoutBlob>().GetBlob(); var processorBlob = processors.FirstOrDefault()?.HasTypedBlob<LightningAutomatedPayoutBlob>().GetBlob();
var instantProcessing = processorBlob?.ProcessNewPayoutsInstantly is true; var instantProcessing = processorBlob?.ProcessNewPayoutsInstantly is true;
if (nonInteractiveOnly && !instantProcessing)
{
return BadRequest(new LNUrlStatusResponse { Status = "ERROR", Reason = "Payment cancelled: The payer must activate the lightning automated payment process and must check \"Process approved payouts instantly\"." });
}
var interval = processorBlob?.Interval.TotalMinutes; var interval = processorBlob?.Interval.TotalMinutes;
var autoApprove = pp.GetBlob().AutoApproveClaims; var autoApprove = pp.GetBlob().AutoApproveClaims;
if (nonInteractiveOnly && !autoApprove)
{
return BadRequest(new LNUrlStatusResponse { Status = "ERROR", Reason = "Payment cancelled: The payer must activate \"Automatically approve claims\" in the settings of the pull payment." });
}
var claimResponse = await _pullPaymentHostedService.Claim(new ClaimRequest var claimResponse = await _pullPaymentHostedService.Claim(new ClaimRequest
{ {
Destination = new BoltInvoiceClaimDestination(pr, result), Destination = new BoltInvoiceClaimDestination(pr, result),