complete payment gateway

This commit is contained in:
MahanCh
2025-07-19 13:11:46 +03:30
parent 62bcd4d6b6
commit 64422755f2
3 changed files with 21 additions and 7 deletions

View File

@@ -36,6 +36,9 @@ public interface IFinancialStatmentApplication
public class GetFinancialStatementBalanceAmount
{
/// <summary>
/// مبلغ
/// </summary>
public double Amount { get; set; }
public long ContractingPartyId { get; set; }
}

View File

@@ -56,13 +56,13 @@ public class FinancialController : ClientBaseController
return op.Failed("موجودی حساب شما صفر است");
}
var callBack = baseUrl+ "/CallBack";
var callBack = baseUrl+ "/api/CallBack";
var transactionCommand = new CreatePaymentTransaction()
{
Amount = balanceAmount.Amount,
ContractingPartyId = balanceAmount.ContractingPartyId,
CallBackUrl = callBack
CallBackUrl = baseUrl
};
var transaction = await _paymentTransactionApplication.Create(transactionCommand);

View File

@@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using ServiceHost.BaseControllers;
using System.Globalization;
using _0_Framework.Application.PaymentGateway;
namespace ServiceHost.Controllers;
@@ -12,10 +13,12 @@ public class GeneralController : GeneralBaseController
{
private readonly IPaymentTransactionApplication _paymentTransactionApplication;
private readonly IPaymentGateway _paymentGateway;
public GeneralController(IPaymentTransactionApplication paymentTransactionApplication)
public GeneralController(IPaymentTransactionApplication paymentTransactionApplication,IHttpClientFactory clientFactory)
{
_paymentTransactionApplication = paymentTransactionApplication;
_paymentGateway = new AqayePardakhtPaymentGateway(clientFactory);
}
/// <summary>
@@ -39,9 +42,9 @@ public class GeneralController : GeneralBaseController
});
}
[HttpPost("callback")]
[HttpPost("/api/callback")]
public async Task<IActionResult> OnGetCallBack(string? transid, string? cardnumber, string? tracking_number,
string bank, string invoice_id, string? status)
string bank, string invoice_id, string? status,CancellationToken cancellationToken)
{
if (!long.TryParse(invoice_id, out var paymentTransactionId))
{
@@ -60,10 +63,18 @@ public class GeneralController : GeneralBaseController
return await HandleFailedTransaction(transaction, paymentTransactionId);
}
var verifyCommand = new VerifyPaymentGateWayRequest()
{
Amount = transaction.Amount,
TransactionId = transid
};
var verifyRes =await _paymentGateway.Verify(verifyCommand, cancellationToken);
// اگر استاتوس 1 باشد، تراکنش موفق است
if (status == "1")
if (verifyRes.IsSuccess)
{
var setSuccessResult = _paymentTransactionApplication.SetSuccess(paymentTransactionId, cardnumber, bank);
//TODO : افزودن دریافت درآمد به وضعیت مالی
if (!setSuccessResult.IsSuccedded)
{
return new JsonResult(setSuccessResult);
@@ -90,7 +101,7 @@ public class GeneralController : GeneralBaseController
private string BuildCallbackUrl(string baseUrl, bool isSuccess, long transactionId)
{
var statusCode = isSuccess ? "1" : "0";
return $"{baseUrl}?Status={statusCode}&transactionId={transactionId}";
return $"{baseUrl}/callback?Status={statusCode}&transactionId={transactionId}";
}