fix(payment): send result redirects to the frontend + add /payment/result page
CI/CD / CI · Web (tsc) (push) Successful in 1m26s
CI/CD / Deploy · full stack (push) Failing after 28s

This commit is contained in:
soroush.asadi
2026-06-25 13:17:21 +03:30
parent dc1fe11604
commit 3748b1c8d8
3 changed files with 106 additions and 5 deletions
@@ -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 ────────────────────────────────────────────────────────────