Files
Backend-Api/CompanyManagment.Application/PaymentTransactionApplication.cs
mahan 16c29bc2d0 Add SepehrPaymentGateway and enhance payment tracking
Introduced the SepehrPaymentGateway to replace the previous
payment gateway, AqayePardakht. Added `Rrn` and `DigitalReceipt`
columns to the `PaymentTransactions` table for improved payment
tracking and verification. Updated the Entity Framework model
and mappings to reflect these changes.

Refactored payment transaction logic to support the new gateway,
including creating, verifying, and handling payments. Added new
request/response models for Sepehr gateway integration. Enhanced
error handling and financial statement creation upon successful
payment verification. Removed legacy code and updated dependency
injection for the Parbad library.
2025-11-12 20:59:37 +03:30

113 lines
4.2 KiB
C#

using _0_Framework.Application;
using _0_Framework.Application.PaymentGateway;
using Company.Domain.PaymentTransactionAgg;
using CompanyManagment.App.Contracts.PaymentTransaction;
using Microsoft.Extensions.Options;
using System.Collections.Generic;
using System.Net.Http;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using _0_Framework.Application;
using _0_Framework.Application.PaymentGateway;
using Company.Domain.ContarctingPartyAgg;
using Company.Domain.PaymentTransactionAgg;
using CompanyManagment.App.Contracts.PaymentTransaction;
namespace CompanyManagment.Application;
public class PaymentTransactionApplication : IPaymentTransactionApplication
{
private readonly IPaymentTransactionRepository _paymentTransactionRepository;
private readonly IPaymentGateway _paymentGateway;
private readonly IPersonalContractingPartyRepository _personalContractingPartyRepository;
public PaymentTransactionApplication(IPaymentTransactionRepository paymentTransactionRepository,IHttpClientFactory httpClientFactory, IOptions<AppSettingConfiguration> appSetting, IPersonalContractingPartyRepository personalContractingPartyRepository)
{
_paymentTransactionRepository = paymentTransactionRepository;
_personalContractingPartyRepository = personalContractingPartyRepository;
_paymentGateway = new AqayePardakhtPaymentGateway(httpClientFactory, appSetting);
}
public async Task<List<GetPaymentTransactionListViewModel>> GetPaymentTransactionList(
GetPaymentTransactionListSearchModel searchModel)
{
return await _paymentTransactionRepository.GetPaymentTransactionList(searchModel);
}
public async Task<OperationResult> Create(CreatePaymentTransaction command)
{
var operationResult = new OperationResult();
var contractingPartyName = _personalContractingPartyRepository.GetFullName(command.ContractingPartyId);
if (string.IsNullOrWhiteSpace(contractingPartyName))
{
return operationResult.Failed("مشتری مورد نظر یافت نشد");
}
var entity = new PaymentTransaction(
command.ContractingPartyId,
command.Amount,
contractingPartyName,
command.CallBackUrl,command.Gateway);
await _paymentTransactionRepository.CreateAsync(entity);
await _paymentTransactionRepository.SaveChangesAsync();
return operationResult.Succcedded(entity.id);
}
public async Task<WalletAmountResponse> GetWalletAmount(CancellationToken cancellationToken)
{
var result = await _paymentGateway.GetWalletAmount(cancellationToken);
return result;
}
public async Task<PaymentTransactionDetailsViewModel> GetDetails(long id)
{
var result = await _paymentTransactionRepository.GetDetails(id);
return result;
}
public OperationResult SetFailed(long paymentTransactionId)
{
var op = new OperationResult();
var paymentTransaction = _paymentTransactionRepository.Get(paymentTransactionId);
if (paymentTransaction == null)
{
return op.Failed("تراکنش مورد نظر یافت نشد");
}
paymentTransaction.SetFailed();
_paymentTransactionRepository.SaveChanges();
return op.Succcedded();
}
public OperationResult SetSuccess(long paymentTransactionId,string cardNumber, string bankName, string rrn, string digitalReceipt)
{
var op = new OperationResult();
var paymentTransaction = _paymentTransactionRepository.Get(paymentTransactionId);
if (paymentTransaction == null)
{
return op.Failed("تراکنش مورد نظر یافت نشد");
}
paymentTransaction.SetPaid(cardNumber, bankName,rrn, digitalReceipt);
_paymentTransactionRepository.SaveChanges();
return op.Succcedded();
}
public async Task<OperationResult> SetTransactionId(long id, string transactionId)
{
var paymentTransaction = _paymentTransactionRepository.Get(id);
paymentTransaction.SetTransactionId(transactionId);
await _paymentTransactionRepository.SaveChangesAsync();
return new OperationResult().Succcedded();
}
}