using GB5Shared.DTO.Framework.Login; using GoodBooks.PAY.PAYDAL.DTO.Cashback; using Microsoft.Extensions.Logging; using System.Net.Http.Json; namespace GoodBooks.PAY.PAYBLL.Integration { public class FinanceIntegrationService : IFinanceIntegrationService { private readonly IHttpClientFactory _httpClientFactory; private readonly ILogger _logger; public FinanceIntegrationService( IHttpClientFactory httpClientFactory, ILogger logger) { _httpClientFactory = httpClientFactory; _logger = logger; } public async Task PostCreditNoteAsync( CashbackLedgerDTO cashback, LoginDTO login, CancellationToken ct) { var client = _httpClientFactory.CreateClient("FinanceModule"); var payload = new { cashback.CashbackLedgerId, cashback.PayOrderId, cashback.CashbackRuleId, cashback.CustomerId, cashback.CashbackAmt, cashback.PayoutMode, cashback.ScheduledPayoutOn, ClientId = login.ClientId, DatabaseName = login.DatabaseName }; var response = await client .PostAsJsonAsync("/Finance/CreditNote/PostCashbackCreditNote", payload, ct) .ConfigureAwait(false); // Throw on failure — caller (CashbackLedgerBLL) is responsible for retry/error handling response.EnsureSuccessStatusCode(); } public async Task NotifyPaymentSettledAsync( int payOrderId, decimal amount, LoginDTO login, CancellationToken ct) { try { var client = _httpClientFactory.CreateClient("FinanceModule"); var payload = new { PayOrderId = payOrderId, Amount = amount, ClientId = login.ClientId, DatabaseName = login.DatabaseName }; await client .PostAsJsonAsync("/Finance/Payment/NotifySettled", payload, ct) .ConfigureAwait(false); } catch (Exception ex) { // Non-fatal — outbox retry loop handles eventual delivery _logger.LogWarning(ex, "NotifyPaymentSettled failed for PayOrderId {PayOrderId}; outbox will retry", payOrderId); } } } }