94 lines
3.7 KiB
C#
94 lines
3.7 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Swashbuckle.AspNetCore.Annotations;
|
|
using cuqmbr.TravelGuide.Domain.Enums;
|
|
using cuqmbr.TravelGuide.Application.Payments;
|
|
using cuqmbr.TravelGuide.Application.Payments.LiqPay
|
|
.TicketGroups.Models;
|
|
using cuqmbr.TravelGuide.Application.Payments.LiqPay
|
|
.TicketGroups.ViewModels;
|
|
using cuqmbr.TravelGuide.Application.Payments.LiqPay
|
|
.TicketGroups.Commands.GetPaymentLink;
|
|
using cuqmbr.TravelGuide.Application.Payments.LiqPay
|
|
.TicketGroups.Commands.ProcessCallback;
|
|
|
|
namespace cuqmbr.TravelGuide.HttpApi.Controllers;
|
|
|
|
[Route("payments")]
|
|
public class PaymentController : ControllerBase
|
|
{
|
|
[HttpPost("liqPay/ticket/getLink")]
|
|
[SwaggerOperation("Get payment link for provided ticket")]
|
|
[SwaggerResponse(
|
|
StatusCodes.Status200OK, "Successfuly created",
|
|
typeof(PaymentLinkDto))]
|
|
[SwaggerResponse(
|
|
StatusCodes.Status400BadRequest, "Input data validation error",
|
|
typeof(HttpValidationProblemDetails))]
|
|
[SwaggerResponse(
|
|
StatusCodes.Status401Unauthorized, "Unauthorized to perform an action",
|
|
typeof(ProblemDetails))]
|
|
[SwaggerResponse(
|
|
StatusCodes.Status403Forbidden,
|
|
"Not enough privileges to perform an action",
|
|
typeof(ProblemDetails))]
|
|
[SwaggerResponse(
|
|
StatusCodes.Status500InternalServerError, "Internal server error",
|
|
typeof(ProblemDetails))]
|
|
public async Task<ActionResult<PaymentLinkDto>> LiqPayTicketGetLink(
|
|
[FromBody] TicketGroupPaymentViewModel viewModel,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
return StatusCode(
|
|
StatusCodes.Status200OK,
|
|
await Mediator.Send(
|
|
new GetPaymentLinkCommand()
|
|
{
|
|
PassangerFirstName = viewModel.PassangerFirstName,
|
|
PassangerLastName = viewModel.PassangerLastName,
|
|
PassangerPatronymic = viewModel.PassangerPatronymic,
|
|
PassangerSex = Sex.FromName(viewModel.PassangerSex),
|
|
PassangerBirthDate = viewModel.PassangerBirthDate,
|
|
PassangerEmail = viewModel.PassangerEmail,
|
|
Tickets = viewModel.Tickets.Select(e =>
|
|
new TicketGroupPaymentTicketModel()
|
|
{
|
|
DepartureRouteAddressGuid = e.DepartureRouteAddressUuid,
|
|
ArrivalRouteAddressGuid = e.ArrivalRouteAddressUuid,
|
|
Order = e.Order,
|
|
VehicleEnrollmentGuid = e.VehicleEnrollmentUuid
|
|
})
|
|
.ToArray(),
|
|
ResultPath = viewModel.ResultPath
|
|
},
|
|
cancellationToken));
|
|
}
|
|
|
|
[Consumes("application/x-www-form-urlencoded")]
|
|
[HttpPost("liqPay/ticket/callback")]
|
|
[SwaggerOperation("Process LiqPay callback for ticket")]
|
|
[SwaggerResponse(
|
|
StatusCodes.Status200OK, "Successfuly processed")]
|
|
[SwaggerResponse(
|
|
StatusCodes.Status400BadRequest, "Input data validation error",
|
|
typeof(HttpValidationProblemDetails))]
|
|
[SwaggerResponse(
|
|
StatusCodes.Status403Forbidden,
|
|
"Not enough privileges to perform an action",
|
|
typeof(ProblemDetails))]
|
|
[SwaggerResponse(
|
|
StatusCodes.Status500InternalServerError, "Internal server error",
|
|
typeof(ProblemDetails))]
|
|
public async Task LiqPayTicketCallback(
|
|
[FromForm] CallbackViewModel viewModel,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
await Mediator.Send(
|
|
new ProcessCallbackCommand()
|
|
{
|
|
Data = viewModel.Data,
|
|
Signature = viewModel.Signature
|
|
},
|
|
cancellationToken);
|
|
}
|
|
}
|