Api/Netina.Api/Controller/PaymentController.cs

52 lines
2.2 KiB
C#

using Netina.Core.Abstracts;
using Netina.Domain.CommandQueries.Queries;
using Netina.Domain.Models.Claims;
using TypedResults = Microsoft.AspNetCore.Http.TypedResults;
namespace Netina.Api.Controller;
public class PaymentController : ICarterModule
{
public virtual void AddRoutes(IEndpointRouteBuilder app)
{
var group = app.NewVersionedApi("AccountingPayment")
.MapGroup($"api/accounting/pay");
group.MapGet("", GetAllAsync)
.WithDisplayName("GetPayments")
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ViewPayments))
.HasApiVersion(1.0);
//group.MapGet("{id}", GetAsync)
// .WithDisplayName("GetShipping")
// .RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser())
// .HasApiVersion(1.0);
group.MapGet("verify", VerifyPaymentAsync)
.HasApiVersion(1.0);
}
// GET:Get All Entity
public async Task<IResult> GetAllAsync([FromQuery] int page, IMediator mediator, CancellationToken cancellationToken)
=> TypedResults.Ok(await mediator.Send(new GetPaymentsQuery(page), cancellationToken));
// GET:Get An Entity By Id
public async Task<IResult> GetAsync(Guid id, IMediator mediator, CancellationToken cancellationToken)
=> TypedResults.Ok(await mediator.Send(new GetShippingQuery(id), cancellationToken));
// POST:Create Entity
public async Task<IResult> VerifyPaymentAsync([FromQuery] string Authority, [FromQuery] string Status, IPaymentService paymentService, ILogger<PaymentController> logger, CancellationToken cancellationToken)
{
if (Status == "OK")
{
var result = await paymentService.VerifyPaymentAsync(authority: Authority, cancellationToken);
return TypedResults.Redirect($"https://vesmeh.com/purchase-callback?refid={result.Item1}&paymentStatus=true&factorNumber={result.Item2}", true);
}
else
{
return TypedResults.Redirect($"https://vesmeh.com/purchase-callback?refid=0&paymentStatus=false&factorNumber=0", true);
}
}
}