(Feat) : Allowed updating payment requests as settled

Signed-off-by: Abhijay jain <Abhijay007j@gmail.com>
This commit is contained in:
Abhijay jain
2025-07-03 00:04:34 +05:30
parent 22f06893b9
commit bc1cebd2d1
3 changed files with 78 additions and 1 deletions

View File

@@ -465,6 +465,48 @@ namespace BTCPayServer.Controllers
return NotFound();
}
[HttpPost("{payReqId}/changestate/{newState}")]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie, Policy = Policies.CanModifyPaymentRequests)]
public async Task<IActionResult> ChangePaymentRequestState(string payReqId, string newState)
{
if (string.IsNullOrWhiteSpace(payReqId) || string.IsNullOrWhiteSpace(newState))
{
return BadRequest("Invalid parameters");
}
var paymentRequest = await _PaymentRequestRepository.FindPaymentRequest(payReqId, GetUserId());
var model = new PaymentRequestStateChangeModel();
if (paymentRequest == null)
{
model.NotFound = true;
return NotFound(model);
}
if (newState == "completed")
{
await _PaymentRequestRepository.UpdatePaymentRequestStatus(payReqId, PaymentRequestStatus.Completed);
model.StatusString = "Settled";
}
else if (newState == "expired")
{
await _PaymentRequestRepository.UpdatePaymentRequestStatus(payReqId, PaymentRequestStatus.Expired);
model.StatusString = "Expired";
}
else
{
return BadRequest($"Invalid state: {newState}");
}
return Json(model);
}
public class PaymentRequestStateChangeModel
{
public bool NotFound { get; set; }
public string? StatusString { get; set; }
}
private string GetUserId() => _UserManager.GetUserId(User);
private StoreData GetCurrentStore() => HttpContext.GetStoreData();