| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using Application.Abstractions.Messaging;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Mvc.RazorPages;
- using System.ComponentModel.DataAnnotations;
- namespace Admin.Pages.Payments.Toss.Confirm;
- public class ViewModel(IMediator mediator) : PageModel
- {
- [BindProperty(SupportsGet = true)]
- public int ID { get; set; }
- [BindProperty]
- public CancelInput Input { get; set; } = new();
- public sealed class CancelInput
- {
- [Display(Name = "취소 요청자")]
- [MaxLength(20)]
- public string? CancelRequester { get; set; }
- [Display(Name = "취소 사유")]
- [MaxLength(200)]
- public string? CancelReason { get; set; }
- }
- public GetTossConfirm.Response? Data { get; set; }
- public async Task<IActionResult> OnGetAsync(CancellationToken ct)
- {
- try
- {
- Data = await mediator.Send(new GetTossConfirm.Query(ID), ct);
- return Page();
- }
- catch (Exception e)
- {
- TempData["ErrorMessages"] = e.Message;
- return RedirectToPage("/Payments/Toss/Confirm/Index");
- }
- }
- public async Task<IActionResult> OnPostCancelAsync(CancellationToken ct)
- {
- var result = await mediator.Send(new CancelTossConfirm.Command(
- ID,
- Input.CancelRequester,
- Input.CancelReason
- ), ct);
- if (result.IsSuccess)
- {
- TempData["SuccessMessage"] = "토스 결제 취소가 완료되었습니다.";
- }
- else
- {
- TempData["ErrorMessages"] = result.Error?.Description ?? "취소에 실패했습니다.";
- }
- return Redirect($"/Payments/Toss/Confirm/View/{ID}{Request.QueryString}");
- }
- }
|