2024-04-18 19:19:54 +03:30
|
|
|
|
using Microsoft.Extensions.Options;
|
2024-02-13 17:41:06 +03:30
|
|
|
|
using TypedResults = Microsoft.AspNetCore.Http.TypedResults;
|
2024-02-12 10:46:18 +03:30
|
|
|
|
|
2024-04-28 22:10:54 +03:30
|
|
|
|
namespace Netina.Api.Controllers;
|
2024-02-12 10:46:18 +03:30
|
|
|
|
|
|
|
|
|
|
public class PaymentController : ICarterModule
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void AddRoutes(IEndpointRouteBuilder app)
|
|
|
|
|
|
{
|
|
|
|
|
|
var group = app.NewVersionedApi("AccountingPayment")
|
|
|
|
|
|
.MapGroup($"api/accounting/pay");
|
|
|
|
|
|
|
|
|
|
|
|
group.MapGet("", GetAllAsync)
|
2024-08-16 18:27:54 +03:30
|
|
|
|
.WithDisplayName("Get Payments")
|
2024-04-16 01:07:11 +03:30
|
|
|
|
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ViewPayments))
|
2024-02-12 10:46:18 +03:30
|
|
|
|
.HasApiVersion(1.0);
|
|
|
|
|
|
|
|
|
|
|
|
//group.MapGet("{id}", GetAsync)
|
|
|
|
|
|
// .WithDisplayName("GetShipping")
|
|
|
|
|
|
// .RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser())
|
|
|
|
|
|
// .HasApiVersion(1.0);
|
|
|
|
|
|
|
|
|
|
|
|
group.MapGet("verify", VerifyPaymentAsync)
|
2024-08-16 18:27:54 +03:30
|
|
|
|
.WithDisplayName("Verify Payment")
|
2024-02-12 10:46:18 +03:30
|
|
|
|
.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
|
2024-04-18 19:19:54 +03:30
|
|
|
|
public async Task<IResult> VerifyPaymentAsync([FromQuery] string Authority, [FromQuery] string Status, IPaymentService paymentService, IOptionsSnapshot<SiteSettings> optionsSnapshot, ILogger<PaymentController> logger, CancellationToken cancellationToken)
|
2024-02-12 10:46:18 +03:30
|
|
|
|
{
|
2024-04-18 19:19:54 +03:30
|
|
|
|
var siteUrl = optionsSnapshot.Value.WebSiteUrl;
|
2024-04-10 20:52:32 +03:30
|
|
|
|
if (Status == "OK")
|
2024-02-12 10:46:18 +03:30
|
|
|
|
{
|
2024-04-10 20:52:32 +03:30
|
|
|
|
var result = await paymentService.VerifyPaymentAsync(authority: Authority, cancellationToken);
|
2024-04-18 19:19:54 +03:30
|
|
|
|
return TypedResults.Redirect($"{siteUrl}/purchase-callback?refid={result.Item1}&paymentStatus=true&factorNumber={result.Item2}", true);
|
2024-02-12 10:46:18 +03:30
|
|
|
|
}
|
2024-04-10 20:52:32 +03:30
|
|
|
|
else
|
2024-02-12 10:46:18 +03:30
|
|
|
|
{
|
2024-04-18 19:19:54 +03:30
|
|
|
|
return TypedResults.Redirect($"{siteUrl}/purchase-callback?refid=0&paymentStatus=false&factorNumber=0", true);
|
2024-02-12 10:46:18 +03:30
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|