| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using Application.Abstractions.Data;
- using Application.Abstractions.Messaging;
- using Microsoft.EntityFrameworkCore;
- namespace Application.Features.Admin.Payment.Danal.Confirm.Get;
- public sealed class Handler(IAppDbContext db) : IQueryHandler<Query, Response>
- {
- public async Task<Response> Handle(Query request, CancellationToken ct)
- {
- var confirm = await db.DanalConfirm.AsNoTracking()
- .Include(x => x.Member)
- .Include(x => x.PaymentOrder)
- .FirstOrDefaultAsync(x => x.ID == request.ID, ct)
- ?? throw new InvalidOperationException("다날 결제 내역을 찾을 수 없습니다.");
- var cancel = await db.DanalCancel.AsNoTracking()
- .Where(c => c.PaymentOrderID == confirm.PaymentOrderID && c.ResponseCode == "0000")
- .OrderByDescending(c => c.ID)
- .Select(c => new Response.CancelData
- {
- ID = c.ID,
- CancelType = c.CancelType,
- Amount = c.Amount,
- ResponseCode = c.ResponseCode,
- ResponseMessage = c.ResponseMessage,
- CancelledAmount = c.CancelledAmount,
- CreatedAt = c.CreatedAt
- })
- .FirstOrDefaultAsync(ct);
- return new Response
- {
- Confirm = new Response.ConfirmData
- {
- ID = confirm.ID,
- MemberID = confirm.MemberID,
- MemberEmail = confirm.Member?.Email ?? string.Empty,
- MemberName = confirm.Member?.Name,
- Method = confirm.Method,
- TransactionID = confirm.TransactionID,
- OrderID = confirm.OrderID,
- Amount = confirm.Amount,
- MerchantID = confirm.MerchantID,
- OrderStatus = confirm.PaymentOrder != null ? confirm.PaymentOrder.Status : default,
- OrderPaidAt = confirm.PaymentOrder?.PaidAt,
- OrderCancelledAt = confirm.PaymentOrder?.CancelledAt,
- OrderName = confirm.OrderName,
- ResponseCode = confirm.ResponseCode,
- ResponseMessage = confirm.ResponseMessage,
- TotalAmount = confirm.TotalAmount,
- DiscountAmount = confirm.DiscountAmount,
- UserName = confirm.UserName,
- TransDate = confirm.TransDate,
- TransTime = confirm.TransTime,
- CardCode = confirm.CardCode,
- CardName = confirm.CardName,
- CardNo = confirm.CardNo,
- InstallmentMonths = confirm.InstallmentMonths,
- ApproveNo = confirm.ApproveNo,
- ApprovalDateTime = confirm.ApprovalDateTime,
- AuthKey = confirm.AuthKey,
- AccountNumber = confirm.AccountNumber,
- BankCode = confirm.BankCode,
- UserId = confirm.UserId,
- UserEmail = confirm.UserEmail,
- BankName = confirm.BankName,
- ExpireDate = confirm.ExpireDate,
- ExpireTime = confirm.ExpireTime,
- VirtualAccountNumber = confirm.VirtualAccountNumber,
- UseCashReceipt = confirm.UseCashReceipt,
- CreatedAt = confirm.CreatedAt,
- UpdatedAt = confirm.UpdatedAt
- },
- Cancel = cancel
- };
- }
- }
|