phase 7 blockers

This commit is contained in:
hamid
2026-08-02 22:30:24 +03:30
parent 9a55846df3
commit 90e0cdcc34
7 changed files with 104 additions and 10 deletions
@@ -1,23 +1,28 @@
#nullable enable
using System.Net;
using Baya.Application.Contracts.Payments;
namespace Baya.Infrastructure.CrossCutting.Seams;
/// <summary>
/// Deterministic mock <see cref="IPaymentProvider"/> — no external call. <see cref="InitPaymentAsync"/> returns
/// a stable fake reference derived from the request + idempotency key and a fake redirect URL;
/// <see cref="VerifyAsync"/> instantly succeeds and echoes the expected amount (the server-side re-check always
/// passes in the mock); <see cref="RefundAsync"/> always succeeds (so b11 can call it). A real
/// ZarinPal/Sadad/Vandar/Jibit adapter (acquirer-with-تسهیم, Shaparak reference, sandbox flag from the
/// gateway's encrypted config) replaces this registration only — no mock behaviour is baked into a handler.
/// a stable fake reference derived from the request + idempotency key, and an app-relative <c>redirectUrl</c>
/// pointing at the client's mock-gateway harness (<c>bookings/checkout/gateway</c>, `ROUTES.CHECKOUT_GATEWAY`) —
/// the client's `initiatePayment` success handler already branches on an absolute vs. relative URL, so this
/// harness round-trips without a real PSP; <see cref="VerifyAsync"/> instantly succeeds and echoes the expected
/// amount (the server-side re-check always passes in the mock); <see cref="RefundAsync"/> always succeeds (so
/// b11 can call it). A real ZarinPal/Sadad/Vandar/Jibit adapter (acquirer-with-تسهیم, Shaparak reference,
/// sandbox flag from the gateway's encrypted config) replaces this registration only — no mock behaviour is
/// baked into a handler.
/// </summary>
public sealed class MockPaymentProvider : IPaymentProvider
{
public ValueTask<PaymentInitResult> InitPaymentAsync(long bookingRequestId, long amountIrr, string idempotencyKey, CancellationToken cancellationToken = default)
{
var reference = $"mock-ref-{bookingRequestId}-{idempotencyKey}";
var redirectUrl = $"/bookings/checkout/gateway?request_id={bookingRequestId}&transaction_id={WebUtility.UrlEncode(reference)}";
return ValueTask.FromResult(new PaymentInitResult(
RedirectUrl: $"https://mock-psp.local/pay/{reference}",
RedirectUrl: redirectUrl,
GatewayReferenceCode: reference));
}