fix(payment): send result redirects to the frontend + add /payment/result page
This commit is contained in:
@@ -8,7 +8,7 @@ namespace FlatRender.IdentitySvc.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("v1")]
|
||||
public class PaymentsController(IPaymentService paymentService) : ControllerBase
|
||||
public class PaymentsController(IPaymentService paymentService, IConfiguration config) : ControllerBase
|
||||
{
|
||||
// ── Helpers ───────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -19,6 +19,18 @@ public class PaymentsController(IPaymentService paymentService) : ControllerBase
|
||||
|
||||
private bool IsAdmin => User.FindFirst("is_admin")?.Value == "true";
|
||||
|
||||
// Payment callbacks land on this service (api.flatrender.ir); the result page
|
||||
// lives on the frontend. Prefix relative result paths with the frontend base so
|
||||
// the browser is sent to the site, not the gateway.
|
||||
private IActionResult RedirectFrontend(string path)
|
||||
{
|
||||
var baseUrl = config["Frontend:BaseUrl"] ?? "";
|
||||
var target = string.IsNullOrEmpty(baseUrl) || path.StartsWith("http")
|
||||
? path
|
||||
: baseUrl.TrimEnd('/') + path;
|
||||
return Redirect(target);
|
||||
}
|
||||
|
||||
// ── Listing ───────────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>GET /v1/payments — list the caller's payment history</summary>
|
||||
@@ -62,7 +74,7 @@ public class PaymentsController(IPaymentService paymentService) : ControllerBase
|
||||
[FromQuery] string Status)
|
||||
{
|
||||
var frontendUrl = await paymentService.HandleZarinPalCallbackAsync(Authority, Status);
|
||||
return Redirect(frontendUrl);
|
||||
return RedirectFrontend(frontendUrl);
|
||||
}
|
||||
|
||||
// ── FlatRender Pay broker flow ────────────────────────────────────────────────
|
||||
@@ -80,7 +92,7 @@ public class PaymentsController(IPaymentService paymentService) : ControllerBase
|
||||
[FromQuery] string? id)
|
||||
{
|
||||
var frontendUrl = await paymentService.HandleBrokerCallbackAsync(payment_id, id ?? "");
|
||||
return Redirect(frontendUrl);
|
||||
return RedirectFrontend(frontendUrl);
|
||||
}
|
||||
|
||||
// ── SnapPay flow ──────────────────────────────────────────────────────────────
|
||||
@@ -109,7 +121,7 @@ public class PaymentsController(IPaymentService paymentService) : ControllerBase
|
||||
[FromQuery] string shapSnapStatus)
|
||||
{
|
||||
var frontendUrl = await paymentService.HandleSnapPayCallbackAsync(paymentToken, shapSnapStatus);
|
||||
return Redirect(frontendUrl);
|
||||
return RedirectFrontend(frontendUrl);
|
||||
}
|
||||
|
||||
// ── Tara flow ─────────────────────────────────────────────────────────────────
|
||||
@@ -138,7 +150,7 @@ public class PaymentsController(IPaymentService paymentService) : ControllerBase
|
||||
[FromQuery] string status)
|
||||
{
|
||||
var frontendUrl = await paymentService.HandleTaraCallbackAsync(token, status);
|
||||
return Redirect(frontendUrl);
|
||||
return RedirectFrontend(frontendUrl);
|
||||
}
|
||||
|
||||
// ── Stripe webhook ────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user