From eecdcc11c0be7eec21bdc0dc9bcb2c812219468f Mon Sep 17 00:00:00 2001 From: MahanCh Date: Wed, 16 Jul 2025 11:59:02 +0330 Subject: [PATCH] add dad-mehr api gateway for test --- .../Application}/AppSettingConfiguration.cs | 2 +- .../PaymentGateway/AqayePardakhtPaymentGateway.cs | 15 +++++++++++---- .../PaymentTransactionApplication.cs | 15 ++++++++------- ServiceHost/Areas/Admin/Pages/Shared/_Menu.cshtml | 3 ++- .../Pages/Company/AndroidApk/Index.cshtml.cs | 9 +++++---- 5 files changed, 27 insertions(+), 17 deletions(-) rename {ServiceHost => 0_Framework/Application}/AppSettingConfiguration.cs (67%) diff --git a/ServiceHost/AppSettingConfiguration.cs b/0_Framework/Application/AppSettingConfiguration.cs similarity index 67% rename from ServiceHost/AppSettingConfiguration.cs rename to 0_Framework/Application/AppSettingConfiguration.cs index 3abad3fb..414949f1 100644 --- a/ServiceHost/AppSettingConfiguration.cs +++ b/0_Framework/Application/AppSettingConfiguration.cs @@ -1,4 +1,4 @@ -namespace ServiceHost; +namespace _0_Framework.Application; public class AppSettingConfiguration { diff --git a/0_Framework/Application/PaymentGateway/AqayePardakhtPaymentGateway.cs b/0_Framework/Application/PaymentGateway/AqayePardakhtPaymentGateway.cs index 948910ac..1f2521e6 100644 --- a/0_Framework/Application/PaymentGateway/AqayePardakhtPaymentGateway.cs +++ b/0_Framework/Application/PaymentGateway/AqayePardakhtPaymentGateway.cs @@ -8,27 +8,34 @@ using System.Security.Principal; using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.Options; namespace _0_Framework.Application.PaymentGateway; public class AqayePardakhtPaymentGateway:IPaymentGateway { - private const string Pin = "86EAF2C4D052F7D8759F"; + private static string _pin = "86EAF2C4D052F7D8759F"; private const string AccountNumber = "AP.1042276242"; private const string EncryptedKey = "130D2@D2923"; private readonly HttpClient _httpClient; - public AqayePardakhtPaymentGateway(IHttpClientFactory httpClientFactory) + public AqayePardakhtPaymentGateway(IHttpClientFactory httpClientFactory,IOptions appSetting) { _httpClient = httpClientFactory.CreateClient(); + + if (appSetting.Value.Domain == ".dad-mehr.ir") + { + _pin = "7349F84E81AB584862D9"; + } + } public async Task Create(CreatePaymentGatewayRequest command,CancellationToken cancellationToken =default) { var response = await _httpClient.PostAsJsonAsync("https://panel.aqayepardakht.ir/api/v2/create", new { - pin = Pin, + pin = _pin, amount = command.Amount, callback = command.CallBackUrl, card_number = command.CardNumber, @@ -49,7 +56,7 @@ public class AqayePardakhtPaymentGateway:IPaymentGateway { var response = await _httpClient.PostAsJsonAsync("https://panel.aqayepardakht.ir/api/v2/verify", new { - pin = Pin, + pin = _pin, amount = command.Amount, transid = command.TransactionId, }, cancellationToken: cancellationToken); diff --git a/CompanyManagment.Application/PaymentTransactionApplication.cs b/CompanyManagment.Application/PaymentTransactionApplication.cs index 5bd3d695..bb834b23 100644 --- a/CompanyManagment.Application/PaymentTransactionApplication.cs +++ b/CompanyManagment.Application/PaymentTransactionApplication.cs @@ -1,12 +1,13 @@ -using System.Collections.Generic; +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.PaymentTransactionAgg; -using CompanyManagment.App.Contracts.PaymentTransaction; namespace CompanyManagment.Application; @@ -15,10 +16,10 @@ public class PaymentTransactionApplication : IPaymentTransactionApplication private readonly IPaymentTransactionRepository _paymentTransactionRepository; private readonly IPaymentGateway _paymentGateway; - public PaymentTransactionApplication(IPaymentTransactionRepository paymentTransactionRepository,IHttpClientFactory httpClientFactory) + public PaymentTransactionApplication(IPaymentTransactionRepository paymentTransactionRepository,IHttpClientFactory httpClientFactory, IOptions appSetting) { _paymentTransactionRepository = paymentTransactionRepository; - _paymentGateway = new AqayePardakhtPaymentGateway(httpClientFactory); + _paymentGateway = new AqayePardakhtPaymentGateway(httpClientFactory, appSetting); } public async Task> GetPaymentTransactionList( diff --git a/ServiceHost/Areas/Admin/Pages/Shared/_Menu.cshtml b/ServiceHost/Areas/Admin/Pages/Shared/_Menu.cshtml index c045b6e3..99c516e7 100644 --- a/ServiceHost/Areas/Admin/Pages/Shared/_Menu.cshtml +++ b/ServiceHost/Areas/Admin/Pages/Shared/_Menu.cshtml @@ -1,4 +1,5 @@ -@using AccountManagement.Domain.TicketAccessAccountAgg +@using _0_Framework.Application +@using AccountManagement.Domain.TicketAccessAccountAgg @using Microsoft.AspNetCore.Mvc.TagHelpers @using Microsoft.Extensions.Options @inject _0_Framework.Application.IAuthHelper AuthHelper; diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs b/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs index b40eb443..5e70ad03 100644 --- a/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs +++ b/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs @@ -15,6 +15,7 @@ using Microsoft.EntityFrameworkCore; using System.Net.Http; using System.Text.Json.Serialization; using _0_Framework.Application.PaymentGateway; +using Microsoft.Extensions.Options; using static ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk.IndexModel2; namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk @@ -32,13 +33,13 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk [BindProperty] public IFormFile File { get; set; } - public IndexModel(IAndroidApkVersionApplication application, IRollCallDomainService rollCallDomainService, CompanyContext context, AccountContext accountContext, IHttpClientFactory httpClientFactory) + public IndexModel(IAndroidApkVersionApplication application, IRollCallDomainService rollCallDomainService, CompanyContext context, AccountContext accountContext, IHttpClientFactory httpClientFactory,IOptions appSetting) { _application = application; _rollCallDomainService = rollCallDomainService; _context = context; _accountContext = accountContext; - _paymentGateway = new AqayePardakhtPaymentGateway(httpClientFactory); + _paymentGateway = new AqayePardakhtPaymentGateway(httpClientFactory, appSetting); } public void OnGet() @@ -112,12 +113,12 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk }; - var createResponse = await _paymentGateway.CreateSandBox(command, cancellationToken); + var createResponse = await _paymentGateway.Create(command, cancellationToken); if (createResponse.Status == "success") { - return Redirect(_paymentGateway.GetStartPaySandBoxUrl(createResponse.TransactionId)); + return Redirect(_paymentGateway.GetStartPayUrl(createResponse.TransactionId)); } //TranslateCode(result?.ErrorCode);