complete payment gateway
This commit is contained in:
@@ -36,6 +36,9 @@ public interface IFinancialStatmentApplication
|
||||
|
||||
public class GetFinancialStatementBalanceAmount
|
||||
{
|
||||
/// <summary>
|
||||
/// مبلغ
|
||||
/// </summary>
|
||||
public double Amount { get; set; }
|
||||
public long ContractingPartyId { get; set; }
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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}";
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user