using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GoodBooks.PAY.PAYDAL.DTO.Gateway; using GoodBooks.PAY.PAYDAL.Query.Gateway; using Newtonsoft.Json; namespace GoodBooks.PAY.PAYDAL.CustomCode.Checkout { public class CheckoutConfigDAL : ICheckoutConfigDAL { private readonly IQueryExecutor _QueryExecutor; public CheckoutConfigDAL(IQueryExecutor queryExecutor) { _QueryExecutor = queryExecutor; } // ── Get single checkout config by Id ────────────────────────────── public async Task GetCheckoutConfig(int checkoutConfigId, LoginDTO loginDTO) { try { var param = new { CheckoutConfigId = checkoutConfigId, TenantId = loginDTO.ClientId }; var result = await _QueryExecutor.QuerySingleAsync( loginDTO, CheckoutConfigQB.GET_CHECKOUT_CONFIG, param).ConfigureAwait(false); return JsonConvert.SerializeObject(result); } catch (Exception) { throw; } } // ── Get active checkout config for the current tenant ───────────── // Returns TOP 1 by SORTORDER — only one active config per tenant is expected. public async Task GetCheckoutConfigForTenant(LoginDTO loginDTO) { try { var param = new { TenantId = loginDTO.ClientId }; var result = await _QueryExecutor.QuerySingleAsync( loginDTO, CheckoutConfigQB.GET_CHECKOUT_CONFIG_FOR_TENANT, param).ConfigureAwait(false); return JsonConvert.SerializeObject(result); } catch (Exception) { throw; } } // ── Insert new checkout config ──────────────────────────────────── public async Task SaveCheckoutConfig(CheckoutConfigDTO dto, LoginDTO loginDTO) { try { int rows = await _QueryExecutor.ExecuteAsync( loginDTO, CheckoutConfigQB.SAVE_CHECKOUT_CONFIG, dto).ConfigureAwait(false); return rows; } catch (Exception) { throw; } } // ── Update existing checkout config ─────────────────────────────── public async Task UpdateCheckoutConfig(CheckoutConfigDTO dto, LoginDTO loginDTO) { try { int rows = await _QueryExecutor.ExecuteAsync( loginDTO, CheckoutConfigQB.UPDATE_CHECKOUT_CONFIG, dto).ConfigureAwait(false); return rows; } catch (Exception) { throw; } } } }