Files
Backend-Api/ServiceHost/Areas/Client/Controllers/FinancialController.cs

73 lines
3.2 KiB
C#

using _0_Framework.Application;
using _0_Framework.Application.PaymentGateway;
using CompanyManagment.App.Contracts.FinancialInvoice;
using CompanyManagment.App.Contracts.FinancialStatment;
using CompanyManagment.App.Contracts.FinancilTransaction;
using CompanyManagment.App.Contracts.PaymentTransaction;
using CompanyManagment.App.Contracts.SepehrPaymentGateway;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using ServiceHost.BaseControllers;
namespace ServiceHost.Areas.Client.Controllers;
public class FinancialController : ClientBaseController
{
private readonly IFinancialStatmentApplication _financialStatementApplication;
private readonly IAuthHelper _authHelper;
private readonly ISepehrPaymentGatewayService _sepehrPaymentGatewayService;
private readonly IFinancialInvoiceApplication _financialInvoiceApplication;
public FinancialController(IFinancialStatmentApplication financialStatementApplication, IAuthHelper authHelper, ISepehrPaymentGatewayService sepehrPaymentGatewayService, IFinancialInvoiceApplication financialInvoiceApplication)
{
_financialStatementApplication = financialStatementApplication;
_authHelper = authHelper;
_sepehrPaymentGatewayService = sepehrPaymentGatewayService;
_financialInvoiceApplication = financialInvoiceApplication;
}
[HttpGet]
public async Task<ActionResult<ClientFinancialStatementViewModel>> GetList(FinancialStatementSearchModel searchModel)
{
var accountId = _authHelper.CurrentAccountId();
var result =await _financialStatementApplication.GetClientFinancialStatement(searchModel,accountId);
return result;
}
[AllowAnonymous]
[HttpPost("preview/{id}")]
public async Task<ActionResult<OperationResult<ClientFinancialStatementViewModel>>> GetStatementDetails(string id)
{
if(!Guid.TryParseExact(id,"N",out _))
return new OperationResult<ClientFinancialStatementViewModel>().Failed("شناسه ارسال شده نامعتبر است");
var result = await _financialStatementApplication.GetDetailsByPublicId(id);
return result;
}
/// <summary>
/// ساخت درگاه پرداخت برای موجودی حساب کلاینت
/// </summary>
[HttpPost("CreatePay")]
[AllowAnonymous]
public async Task<ActionResult<OperationResult<string>>> CreatePay([FromForm] CreateFinancialPayRequest request)
{
var op = new OperationResult<string>();
var gateWayCallBackUrl = Url.Action(
action: "Verify",
controller: "General", // نام کنترلر بدون کلمه‌ی "Controller"
values: null,
protocol: Request.Scheme); // http یا https
// گام 2: ایجاد درگاه پرداخت سپهر
var gatewayResult = await _financialStatementApplication.CreatePaymentGateWayAndCreateInvoice(request, gateWayCallBackUrl);
if (!gatewayResult.IsSuccedded)
{
return op.Failed(gatewayResult.Message);
}
// گام 3: بازگشتی به درگاه پرداخت
return Redirect(gatewayResult.Data.PaymentUrl);
}
}