diff --git a/0_Framework/Application/PaymentGateway/AqayePardakhtPaymentGateway.cs b/0_Framework/Application/PaymentGateway/AqayePardakhtPaymentGateway.cs index 7405d5b2..948910ac 100644 --- a/0_Framework/Application/PaymentGateway/AqayePardakhtPaymentGateway.cs +++ b/0_Framework/Application/PaymentGateway/AqayePardakhtPaymentGateway.cs @@ -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 Create(CreatePaymentGatewayRequest command) + public async Task 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(); + var result = await response.Content.ReadFromJsonAsync(cancellationToken: cancellationToken); return result; } public string GetStartPayUrl(string transactionId) => $"https://panel.aqayepardakht.ir/startpay/{transactionId}"; - public async Task Verify(VerifyPaymentGateWayRequest command) + public async Task 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(); + var result = await response.Content.ReadFromJsonAsync(cancellationToken: cancellationToken); return result; } - public async Task CreateSandBox(CreatePaymentGatewayRequest command) + public async Task 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(); + var result = await response.Content.ReadFromJsonAsync(cancellationToken: cancellationToken); return result; } public string GetStartPaySandBoxUrl(string transactionId) => $"https://panel.aqayepardakht.ir/startpay/sandbox/{transactionId}"; + + public async Task 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(cancellationToken); + return result; + } } \ No newline at end of file diff --git a/0_Framework/Application/PaymentGateway/IPaymentGateway.cs b/0_Framework/Application/PaymentGateway/IPaymentGateway.cs index cc3d14a4..c4b80ba3 100644 --- a/0_Framework/Application/PaymentGateway/IPaymentGateway.cs +++ b/0_Framework/Application/PaymentGateway/IPaymentGateway.cs @@ -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 Create(CreatePaymentGatewayRequest command); + Task Create(CreatePaymentGatewayRequest command, CancellationToken cancellationToken =default); string GetStartPayUrl(string transactionId); - Task Verify(VerifyPaymentGateWayRequest command); - Task CreateSandBox(CreatePaymentGatewayRequest command); - + Task Verify(VerifyPaymentGateWayRequest command, CancellationToken cancellationToken=default); + Task CreateSandBox(CreatePaymentGatewayRequest command, CancellationToken cancellationToken=default); string GetStartPaySandBoxUrl(string transactionId); + Task 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; } diff --git a/CompanyManagment.App.Contracts/PaymentTransaction/IPaymentTransactionApplication.cs b/CompanyManagment.App.Contracts/PaymentTransaction/IPaymentTransactionApplication.cs index 891b6263..b871b1a7 100644 --- a/CompanyManagment.App.Contracts/PaymentTransaction/IPaymentTransactionApplication.cs +++ b/CompanyManagment.App.Contracts/PaymentTransaction/IPaymentTransactionApplication.cs @@ -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 /// Task Create(CreatePaymentTransaction command); + Task GetWalletAmount(CancellationToken cancellationToken); + } \ No newline at end of file diff --git a/CompanyManagment.Application/PaymentTransactionApplication.cs b/CompanyManagment.Application/PaymentTransactionApplication.cs index c856d4d1..5bd3d695 100644 --- a/CompanyManagment.Application/PaymentTransactionApplication.cs +++ b/CompanyManagment.Application/PaymentTransactionApplication.cs @@ -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> GetPaymentTransactionList( @@ -41,4 +46,12 @@ public class PaymentTransactionApplication : IPaymentTransactionApplication await _paymentTransactionRepository.SaveChangesAsync(); return operationResult.Succcedded(); } + + + + public async Task GetWalletAmount(CancellationToken cancellationToken) + { + var result = await _paymentGateway.GetWalletAmount(cancellationToken); + return result; + } } \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Controllers/PaymentTransactionController.cs b/ServiceHost/Areas/Admin/Controllers/PaymentTransactionController.cs index dec6a4ec..37b13dba 100644 --- a/ServiceHost/Areas/Admin/Controllers/PaymentTransactionController.cs +++ b/ServiceHost/Areas/Admin/Controllers/PaymentTransactionController.cs @@ -20,4 +20,14 @@ public class PaymentTransactionController : AdminBaseController var res = await _paymentTransactionApplication.GetPaymentTransactionList(searchModel); return res; } + [HttpGet("wallet-Amount")] + public async Task GetWalletAmount(CancellationToken cancellationToken) + { + var res = await _paymentTransactionApplication.GetWalletAmount(cancellationToken); + if (res.Code!=0) + { + return BadRequest(res); + } + return Ok(res); + } } \ No newline at end of file diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs b/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs index be47225b..b40eb443 100644 --- a/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs +++ b/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs @@ -101,7 +101,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk ViewData["message"] = "تومام دو"; return Page(); } - public async Task OnPostPaymentGateWay() + public async Task 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") diff --git a/ServiceHost/BaseControllers/AdminBaseController.cs b/ServiceHost/BaseControllers/AdminBaseController.cs index 2ba56a71..3b046fc4 100644 --- a/ServiceHost/BaseControllers/AdminBaseController.cs +++ b/ServiceHost/BaseControllers/AdminBaseController.cs @@ -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]")]