using GB5Shared.DTO.Framework.Login;
namespace EntitlementBLL.Payment;
///
/// Calls PAY's real HTTP endpoints (Pay/Order.svc) to initiate and check payment for a
/// subscription. Entitlement never references PAYDAL/PAYBLL directly — mirrors
/// EntitlementBLL.Onboarding.ISqlWorkbenchClient's own established shape (no cross-module
/// project reference; a named HttpClient + this module's own local mirror DTOs instead).
/// Docs/Platform-Architecture-Integration-Reference.md §9.1 — the loose-coupling design this
/// implements.
///
public interface IPaySubscriptionClient
{
/// POST /Pay/Order/InitiatePayOrder with SourceDocType=EntitlementSubscription,
/// SourceDocId=SubscriptionId. Returns the new PayOrderId and a checkout URL for the
/// caller to redirect the payer to. Throws if PAY already has an active (non-terminal)
/// order for this subscription — callers should surface that as a real, user-facing
/// error ("a payment is already in progress"), not swallow it.
Task InitiatePaymentAsync(PayInitiatePaymentRequest req, LoginDTO login, CancellationToken ct);
/// GET /Pay/Order/GetPayOrder — resolves a single order's current status
/// (OrderStatus: 1=Created 2=Pending 3=Paid 5=Failed — PAY itself has no named enum for
/// this, confirmed via direct code read; these are the only values PAY's own webhook
/// handler ever writes). Used by both the Dapr subscriber and the reconciliation job.
Task GetPayOrderAsync(int payOrderId, LoginDTO login, CancellationToken ct);
/// GET /Pay/Order/GetPayOrdersBySourceDoc — full payment history for one
/// subscription, newest first. Backs Entitlement's own GetMyPaymentHistory endpoint.
Task> GetPaymentHistoryAsync(int subscriptionId, LoginDTO login, CancellationToken ct);
}
// ── Local mirror DTOs — deliberately NOT shared types with PAYBLL/PAYDAL ───────────────────
public class PayInitiatePaymentRequest
{
public int SubscriptionId { get; set; }
public decimal OrderAmt { get; set; }
public string OrderCurrency { get; set; } = "INR";
public string GatewayCode { get; set; } = string.Empty;
public int CustomerId { get; set; }
public string CustomerName { get; set; } = string.Empty;
public string CustomerEmail { get; set; } = string.Empty;
public string CustomerPhone { get; set; } = string.Empty;
public string CallbackUrl { get; set; } = string.Empty;
}
public class PayInitiateResultDTO
{
public int PayOrderId { get; set; }
public string? CheckoutUrl { get; set; }
}
public class PayOrderStatusDTO
{
public int PayOrderId { get; set; }
public int SourceDocType { get; set; }
public int SourceDocId { get; set; }
public int OrderStatus { get; set; }
public decimal PaidAmt { get; set; }
}
public class PayOrderHistoryItemDTO
{
public int PayOrderId { get; set; }
public string PayOrderNo { get; set; } = string.Empty;
public string OrderCurrency { get; set; } = string.Empty;
public decimal OrderAmt { get; set; }
public decimal NetPayableAmt { get; set; }
public int OrderStatus { get; set; }
public decimal PaidAmt { get; set; }
public string? GatewayCode { get; set; }
public string? GatewayName { get; set; }
public DateTime CreatedOn { get; set; }
}