feat: add wallet api for aqaye pardakht
This commit is contained in:
@@ -4,7 +4,9 @@ using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using System.Security.Policy;
|
||||
using System.Security.Principal;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _0_Framework.Application.PaymentGateway;
|
||||
@@ -12,6 +14,9 @@ namespace _0_Framework.Application.PaymentGateway;
|
||||
public class AqayePardakhtPaymentGateway:IPaymentGateway
|
||||
{
|
||||
private const string Pin = "86EAF2C4D052F7D8759F";
|
||||
private const string AccountNumber = "AP.1042276242";
|
||||
private const string EncryptedKey = "130D2@D2923";
|
||||
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
public AqayePardakhtPaymentGateway(IHttpClientFactory httpClientFactory)
|
||||
@@ -19,7 +24,7 @@ public class AqayePardakhtPaymentGateway:IPaymentGateway
|
||||
_httpClient = httpClientFactory.CreateClient();
|
||||
}
|
||||
|
||||
public async Task<PaymentGatewayResponse> Create(CreatePaymentGatewayRequest command)
|
||||
public async Task<PaymentGatewayResponse> Create(CreatePaymentGatewayRequest command,CancellationToken cancellationToken =default)
|
||||
{
|
||||
var response = await _httpClient.PostAsJsonAsync("https://panel.aqayepardakht.ir/api/v2/create", new
|
||||
{
|
||||
@@ -31,29 +36,29 @@ public class AqayePardakhtPaymentGateway:IPaymentGateway
|
||||
mobile = command.Mobile,
|
||||
email = command.Email,
|
||||
description = command.Description,
|
||||
});
|
||||
}, cancellationToken: cancellationToken);
|
||||
|
||||
var result = await response.Content.ReadFromJsonAsync<PaymentGatewayResponse>();
|
||||
var result = await response.Content.ReadFromJsonAsync<PaymentGatewayResponse>(cancellationToken: cancellationToken);
|
||||
return result;
|
||||
}
|
||||
|
||||
public string GetStartPayUrl(string transactionId) =>
|
||||
$"https://panel.aqayepardakht.ir/startpay/{transactionId}";
|
||||
|
||||
public async Task<PaymentGatewayResponse> Verify(VerifyPaymentGateWayRequest command)
|
||||
public async Task<PaymentGatewayResponse> Verify(VerifyPaymentGateWayRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var response = await _httpClient.PostAsJsonAsync("https://panel.aqayepardakht.ir/api/v2/verify", new
|
||||
{
|
||||
pin = Pin,
|
||||
amount = command.Amount,
|
||||
transid = command.TransactionId,
|
||||
});
|
||||
}, cancellationToken: cancellationToken);
|
||||
|
||||
var result = await response.Content.ReadFromJsonAsync<PaymentGatewayResponse>();
|
||||
var result = await response.Content.ReadFromJsonAsync<PaymentGatewayResponse>(cancellationToken: cancellationToken);
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<PaymentGatewayResponse> CreateSandBox(CreatePaymentGatewayRequest command)
|
||||
public async Task<PaymentGatewayResponse> CreateSandBox(CreatePaymentGatewayRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var response = await _httpClient.PostAsJsonAsync("https://panel.aqayepardakht.ir/api/v2/create", new
|
||||
{
|
||||
@@ -65,12 +70,24 @@ public class AqayePardakhtPaymentGateway:IPaymentGateway
|
||||
mobile = command.Mobile,
|
||||
email = command.Email,
|
||||
description = command.Email,
|
||||
});
|
||||
}, cancellationToken: cancellationToken);
|
||||
|
||||
var result = await response.Content.ReadFromJsonAsync<PaymentGatewayResponse>();
|
||||
var result = await response.Content.ReadFromJsonAsync<PaymentGatewayResponse>(cancellationToken: cancellationToken);
|
||||
return result;
|
||||
}
|
||||
|
||||
public string GetStartPaySandBoxUrl(string transactionId) =>
|
||||
$"https://panel.aqayepardakht.ir/startpay/sandbox/{transactionId}";
|
||||
|
||||
public async Task<WalletAmountResponse> GetWalletAmount(CancellationToken cancellationToken)
|
||||
{
|
||||
var response =await _httpClient.PostAsJsonAsync("https://panel.aqayepardakht.ir/api/v2/getmoney", new
|
||||
{
|
||||
account=AccountNumber,
|
||||
code = EncryptedKey
|
||||
}, cancellationToken: cancellationToken);
|
||||
var jsonString = await response.Content.ReadAsStringAsync(cancellationToken);
|
||||
var result = await response.Content.ReadFromJsonAsync<WalletAmountResponse>(cancellationToken);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,23 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Server.HttpSys;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Server.HttpSys;
|
||||
|
||||
namespace _0_Framework.Application.PaymentGateway;
|
||||
|
||||
public interface IPaymentGateway
|
||||
{
|
||||
Task<PaymentGatewayResponse> Create(CreatePaymentGatewayRequest command);
|
||||
Task<PaymentGatewayResponse> Create(CreatePaymentGatewayRequest command, CancellationToken cancellationToken =default);
|
||||
|
||||
string GetStartPayUrl(string transactionId);
|
||||
Task<PaymentGatewayResponse> Verify(VerifyPaymentGateWayRequest command);
|
||||
Task<PaymentGatewayResponse> CreateSandBox(CreatePaymentGatewayRequest command);
|
||||
|
||||
Task<PaymentGatewayResponse> Verify(VerifyPaymentGateWayRequest command, CancellationToken cancellationToken=default);
|
||||
Task<PaymentGatewayResponse> CreateSandBox(CreatePaymentGatewayRequest command, CancellationToken cancellationToken=default);
|
||||
string GetStartPaySandBoxUrl(string transactionId);
|
||||
Task<WalletAmountResponse> GetWalletAmount(CancellationToken cancellationToken);
|
||||
|
||||
}
|
||||
public class PaymentGatewayResponse
|
||||
@@ -31,6 +32,16 @@ public class PaymentGatewayResponse
|
||||
public string TransactionId { get; set; }
|
||||
}
|
||||
|
||||
public class WalletAmountResponse
|
||||
{
|
||||
[JsonPropertyName("status")]
|
||||
public string Status { get; set; }
|
||||
[JsonPropertyName("money")]
|
||||
public double Amount { get; set; }
|
||||
[JsonPropertyName("code")]
|
||||
public int Code { get; set; }
|
||||
}
|
||||
|
||||
public class CreatePaymentGatewayRequest
|
||||
{
|
||||
public double Amount { get; set; }
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using _0_Framework.Application;
|
||||
using _0_Framework.Application.PaymentGateway;
|
||||
|
||||
namespace CompanyManagment.App.Contracts.PaymentTransaction;
|
||||
|
||||
@@ -23,4 +25,6 @@ public interface IPaymentTransactionApplication
|
||||
/// <returns></returns>
|
||||
Task<OperationResult> Create(CreatePaymentTransaction command);
|
||||
|
||||
Task<WalletAmountResponse> GetWalletAmount(CancellationToken cancellationToken);
|
||||
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
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.PaymentTransactionAgg;
|
||||
using CompanyManagment.App.Contracts.PaymentTransaction;
|
||||
|
||||
@@ -10,10 +13,12 @@ namespace CompanyManagment.Application;
|
||||
public class PaymentTransactionApplication : IPaymentTransactionApplication
|
||||
{
|
||||
private readonly IPaymentTransactionRepository _paymentTransactionRepository;
|
||||
private readonly IPaymentGateway _paymentGateway;
|
||||
|
||||
public PaymentTransactionApplication(IPaymentTransactionRepository paymentTransactionRepository)
|
||||
public PaymentTransactionApplication(IPaymentTransactionRepository paymentTransactionRepository,IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_paymentTransactionRepository = paymentTransactionRepository;
|
||||
_paymentGateway = new AqayePardakhtPaymentGateway(httpClientFactory);
|
||||
}
|
||||
|
||||
public async Task<List<GetPaymentTransactionListViewModel>> GetPaymentTransactionList(
|
||||
@@ -41,4 +46,12 @@ public class PaymentTransactionApplication : IPaymentTransactionApplication
|
||||
await _paymentTransactionRepository.SaveChangesAsync();
|
||||
return operationResult.Succcedded();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<WalletAmountResponse> GetWalletAmount(CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _paymentGateway.GetWalletAmount(cancellationToken);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -20,4 +20,14 @@ public class PaymentTransactionController : AdminBaseController
|
||||
var res = await _paymentTransactionApplication.GetPaymentTransactionList(searchModel);
|
||||
return res;
|
||||
}
|
||||
[HttpGet("wallet-Amount")]
|
||||
public async Task<IActionResult> GetWalletAmount(CancellationToken cancellationToken)
|
||||
{
|
||||
var res = await _paymentTransactionApplication.GetWalletAmount(cancellationToken);
|
||||
if (res.Code!=0)
|
||||
{
|
||||
return BadRequest(res);
|
||||
}
|
||||
return Ok(res);
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
|
||||
ViewData["message"] = "تومام دو";
|
||||
return Page();
|
||||
}
|
||||
public async Task<IActionResult> OnPostPaymentGateWay()
|
||||
public async Task<IActionResult> OnPostPaymentGateWay(CancellationToken cancellationToken)
|
||||
{
|
||||
var command = new CreatePaymentGatewayRequest()
|
||||
{
|
||||
@@ -112,7 +112,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
|
||||
|
||||
|
||||
};
|
||||
var createResponse = await _paymentGateway.CreateSandBox(command);
|
||||
var createResponse = await _paymentGateway.CreateSandBox(command, cancellationToken);
|
||||
|
||||
|
||||
if (createResponse.Status == "success")
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
namespace ServiceHost.BaseControllers;
|
||||
|
||||
[Authorize(Policy = "AdminArea")]
|
||||
//[Authorize(Policy = "AdminArea")]
|
||||
[Area("Admin")]
|
||||
[ApiExplorerSettings(GroupName = "Admin")]
|
||||
[Route("api/[area]/[controller]")]
|
||||
|
||||
Reference in New Issue
Block a user