From 9297bdefb5dbefb01fbe5502e6a6db541eed678a Mon Sep 17 00:00:00 2001 From: mahan Date: Wed, 15 Oct 2025 10:38:50 +0330 Subject: [PATCH 1/5] feat: add bank inquiry methods and UidBanks enum for bank identification --- 0_Framework/Application/UID/IUidService.cs | 45 ++++++- 0_Framework/Application/UID/UidBanks.cs | 117 ++++++++++++++++++ .../Application/UID/UidBanksExtension.cs | 27 ++++ .../Services/UidService.cs | 23 +++- 4 files changed, 209 insertions(+), 3 deletions(-) create mode 100644 0_Framework/Application/UID/UidBanks.cs create mode 100644 0_Framework/Application/UID/UidBanksExtension.cs diff --git a/0_Framework/Application/UID/IUidService.cs b/0_Framework/Application/UID/IUidService.cs index c2c26bd5..a1ac1e4c 100644 --- a/0_Framework/Application/UID/IUidService.cs +++ b/0_Framework/Application/UID/IUidService.cs @@ -110,6 +110,46 @@ public interface IUidService { Task GetPersonalInfo(string nationalCode , string birthDate); Task IsMachPhoneWithNationalCode(string nationalCode , string phoneNumber); + Task IbanInquiry (string iban); + Task AccountToIban(string accountNumber, UidBanks bank); + Task CardToIban(string cardNumber); +} + +public class CardToNumberResponse:UidBaseResponse +{ + public string Iban { get; set; } +} + +public class AccountToIbanResponse:UidBaseResponse +{ + public string Iban { get; set; } +} + +public class IbanInquiryResponse:UidBaseResponse +{ + public IbanInquiryAccountBasicInformation AccountBasicInformation { get; set; } +} + +public class IbanInquiryAccountBasicInformation +{ + public string Iban { get; set; } + public string AccountNumber { get; set; } + public IbanInquiryBankInformation BankInformation { get; set; } + public string AccountStatus { get; set; } + public List Owners { get; set; } +} + +public class IbanInquiryBankInformation +{ + public string BankName { get; set; } +} + +public class IbanInquiryOwner +{ + public string FirstName { get; set; } + public string LastName { get; set; } + public string NationalIdentifier { get; set; } + public string CustomerType { get; set; } } public class MatchMobileWithNationalCodeResponse @@ -118,4 +158,7 @@ public class MatchMobileWithNationalCodeResponse public ResponseContext ResponseContext { get; set; } } - +public class UidBaseResponse +{ + public ResponseContext ResponseContext { get; set; } +} diff --git a/0_Framework/Application/UID/UidBanks.cs b/0_Framework/Application/UID/UidBanks.cs new file mode 100644 index 00000000..16e0c3d4 --- /dev/null +++ b/0_Framework/Application/UID/UidBanks.cs @@ -0,0 +1,117 @@ +using System.ComponentModel; + +namespace _0_Framework.Application.UID; + +public enum UidBanks +{ + [Description("بانک دی")] + BANK_DEY = 66, + + [Description("بانک سپه")] + BANK_SEPAH = 15, + + [Description("بانک شهر")] + BANK_SHAHR = 61, + + [Description("بانک ملت")] + BANK_MELAT = 12, + + [Description("بانک ملی")] + BANK_MELLI = 17, + + [Description("بانک رفاه کارگران")] + BANK_REFAH = 13, + + [Description("بانک سینا")] + BANK_SINA = 59, + + [Description("بانک مسکن")] + BANK_MASKAN = 14, + + [Description("بانک آینده")] + BANK_AYANDEH = 62, + + [Description("بانک انصار")] + BANK_ANSAR = 63, + + [Description("بانک تجارت")] + BANK_TEJARAT = 18, + + [Description("بانک رسالت")] + BANK_RESALAT = 70, + + [Description("بانک سامان")] + BANK_SAMAN = 56, + + [Description("بانک مرکزی")] + BANK_MARKAZI = 10, + + [Description("بانک سرمایه")] + BANK_SARMAYEH = 58, + + [Description("بانک صادرات")] + BANK_SADERAT = 19, + + [Description("بانک قوامین")] + BANK_GHAVAMIN = 52, + + [Description("بانک پارسیان")] + BANK_PARSIAN = 54, + + [Description("بانک کشاورزی")] + BANK_KESHAVARZI = 16, + + [Description("بانک گردشگری")] + BANK_GARDESHGARI = 64, + + [Description("پست بانک")] + BANK_POST_BANK = 21, + + [Description("بانک پاسارگاد")] + BANK_PASARGAD = 57, + + [Description("بانک کارآفرین")] + BANK_KARAFARIN = 53, + + [Description("بانک خاورمیانه")] + BANK_KHAVARMIANEH = 78, + + [Description("بانک ایران زمین")] + BANK_IRAN_ZAMIN = 69, + + [Description("بانک مهر اقتصاد")] + BANK_MEHR_EQTESAD = 79, + + [Description("بانک صنعت و معدن")] + BANK_SANAT_MADAN = 11, + + [Description("بانک اقتصاد نوین")] + BANK_EGHTESAD_NOVIN = 55, + + [Description("بانک توسعه تعاون")] + BANK_TOSSE_TAAVON = 22, + + [Description("بانک توسعه صادرات")] + BANK_TOSSE_SADERAT = 20, + + [Description("بانک ایران و ونزوئلا")] + BANK_IRAN_VENEZUELA = 95, + + [Description("بانک حکمت ایرانیان")] + BANK_HEKMAT_IRANIAN = 65, + + [Description("بانک قرض الحسنه مهر")] + BANK_GHARZOLHASANEH_MEHR = 60, + + [Description("موسسه مالی و اعتباری ملل")] + BANK_MOASSASE_MELLAL = 75, + + [Description("موسسه مالی و اعتباری نور")] + BANK_MOASSASE_NOOR = 80, + + [Description("موسسه مالی و اعتباری کوثر")] + BANK_MOASSASE_KOSAR = 73, + + [Description("موسسه مالی و اعتباری توسعه")] + BANK_MOASSASE_TOSSE = 51 +} \ No newline at end of file diff --git a/0_Framework/Application/UID/UidBanksExtension.cs b/0_Framework/Application/UID/UidBanksExtension.cs new file mode 100644 index 00000000..98a46f16 --- /dev/null +++ b/0_Framework/Application/UID/UidBanksExtension.cs @@ -0,0 +1,27 @@ +using System; +using System.ComponentModel; +using System.Reflection; + +namespace _0_Framework.Application.UID +{ + public static class UidBanksExtension + { + /// + /// دریافت نام فارسی بانک + /// + /// بانک + /// نام فارسی بانک + public static string GetPersianName(this UidBanks bank) + { + var fieldInfo = bank.GetType().GetField(bank.ToString()); + + if (fieldInfo == null) + return string.Empty; + + var attribute = (DescriptionAttribute)Attribute.GetCustomAttribute( + fieldInfo, typeof(DescriptionAttribute)); + + return attribute?.Description ?? bank.ToString(); + } + } +} diff --git a/CompanyManagment.EFCore/Services/UidService.cs b/CompanyManagment.EFCore/Services/UidService.cs index f6abc73b..e05023f4 100644 --- a/CompanyManagment.EFCore/Services/UidService.cs +++ b/CompanyManagment.EFCore/Services/UidService.cs @@ -14,7 +14,11 @@ public class UidService : IUidService { private readonly HttpClient _httpClient; private readonly IAuthorizedPersonApplication _authorizedPersonApplication; - private const string BaseUrl = "https://json-api.uid.ir/api/inquiry/"; + private const string BaseUrl = "https://json-api.uid.ir/api/"; + + public const string BusinessToken = "5e03dd4e-999d-466f-92d8-7c0b1f66a8e9"; + public const string BusinessId = "98ed67ca-d441-4978-a748-e8bebce010eb"; + public UidService(IAuthorizedPersonApplication authorizedPersonApplication) { @@ -53,7 +57,7 @@ public class UidService : IUidService try { - var requestResult = await _httpClient.PostAsync("person/v2", contentType); + var requestResult = await _httpClient.PostAsync("inquiry/person/v2", contentType); if (!requestResult.IsSuccessStatusCode) return null; var responseResult = await requestResult.Content.ReadFromJsonAsync(); @@ -145,4 +149,19 @@ public class UidService : IUidService var responseResult = await requestResult.Content.ReadFromJsonAsync(); return responseResult; } + + public Task IbanInquiry(string iban) + { + throw new NotImplementedException(); + } + + public Task AccountToIban(string accountNumber, UidBanks bank) + { + throw new NotImplementedException(); + } + + public Task CardToIban(string cardNumber) + { + throw new NotImplementedException(); + } } From 4aa3c10466554cc5100cb5f2dfd9b532c38d9194 Mon Sep 17 00:00:00 2001 From: mahan Date: Wed, 15 Oct 2025 11:57:12 +0330 Subject: [PATCH 2/5] feat: update API endpoint for bank inquiries in UidService --- CompanyManagment.EFCore/Services/UidService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CompanyManagment.EFCore/Services/UidService.cs b/CompanyManagment.EFCore/Services/UidService.cs index e05023f4..cc078ee1 100644 --- a/CompanyManagment.EFCore/Services/UidService.cs +++ b/CompanyManagment.EFCore/Services/UidService.cs @@ -142,7 +142,7 @@ public class UidService : IUidService var json = JsonConvert.SerializeObject(request); var contentType = new StringContent(json, Encoding.UTF8, "application/json"); - var requestResult = await _httpClient.PostAsync("mobile/owner/v2", contentType); + var requestResult = await _httpClient.PostAsync("inquiry/mobile/owner/v2", contentType); if (!requestResult.IsSuccessStatusCode) return null; From 37a6920a745807e3277a168fb94db09a49a94f60 Mon Sep 17 00:00:00 2001 From: mahan Date: Thu, 16 Oct 2025 09:20:47 +0330 Subject: [PATCH 3/5] feat: implement account information retrieval methods in DashboardController and UidService --- 0_Framework/Application/UID/IUidService.cs | 1 + .../Services/UidService.cs | 43 ++++++++++++++++--- .../Admin/Controllers/DashboardController.cs | 25 ++++++++++- 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/0_Framework/Application/UID/IUidService.cs b/0_Framework/Application/UID/IUidService.cs index a1ac1e4c..63599699 100644 --- a/0_Framework/Application/UID/IUidService.cs +++ b/0_Framework/Application/UID/IUidService.cs @@ -118,6 +118,7 @@ public interface IUidService public class CardToNumberResponse:UidBaseResponse { public string Iban { get; set; } + public string CardNumber { get; set; } } public class AccountToIbanResponse:UidBaseResponse diff --git a/CompanyManagment.EFCore/Services/UidService.cs b/CompanyManagment.EFCore/Services/UidService.cs index cc078ee1..bb84c06a 100644 --- a/CompanyManagment.EFCore/Services/UidService.cs +++ b/CompanyManagment.EFCore/Services/UidService.cs @@ -150,18 +150,49 @@ public class UidService : IUidService return responseResult; } - public Task IbanInquiry(string iban) + public async Task IbanInquiry(string iban) { - throw new NotImplementedException(); + var request = new + { + Iban = iban, + RequestContext = new UidRequestContext() + }; + var json = JsonConvert.SerializeObject(request); + var contentType = new StringContent(json, Encoding.UTF8, "application/json"); + var requestResult = await _httpClient.PostAsync("inquiry/iban/v2", contentType); + requestResult.EnsureSuccessStatusCode(); + var responseResult = await requestResult.Content.ReadFromJsonAsync(); + return responseResult; } - public Task AccountToIban(string accountNumber, UidBanks bank) + public async Task AccountToIban(string accountNumber, UidBanks bank) { - throw new NotImplementedException(); + var request = new + { + accountNumber, + bank, + RequestContext = new UidRequestContext() + }; + var json = JsonConvert.SerializeObject(request); + var contentType = new StringContent(json, Encoding.UTF8, "application/json"); + var requestResult = await _httpClient.PostAsync("account-to-iban", contentType); + requestResult.EnsureSuccessStatusCode(); + var responseResult = await requestResult.Content.ReadFromJsonAsync(); + return responseResult; } - public Task CardToIban(string cardNumber) + public async Task CardToIban(string cardNumber) { - throw new NotImplementedException(); + var request = new + { + cardNumber, + RequestContext = new UidRequestContext() + }; + var json = JsonConvert.SerializeObject(request); + var contentType = new StringContent(json, Encoding.UTF8, "application/json"); + var requestResult = await _httpClient.PostAsync("account-to-iban", contentType); + requestResult.EnsureSuccessStatusCode(); + var responseResult = await requestResult.Content.ReadFromJsonAsync(); + return responseResult; } } diff --git a/ServiceHost/Areas/Admin/Controllers/DashboardController.cs b/ServiceHost/Areas/Admin/Controllers/DashboardController.cs index d132095c..49cf1486 100644 --- a/ServiceHost/Areas/Admin/Controllers/DashboardController.cs +++ b/ServiceHost/Areas/Admin/Controllers/DashboardController.cs @@ -1,5 +1,6 @@ using _0_Framework.Application; using _0_Framework.Application.Sms; +using _0_Framework.Application.UID; using AccountManagement.Application.Contracts.Task; using AccountManagement.Application.Contracts.Ticket; using CompanyManagment.App.Contracts.ClientDashboard; @@ -16,14 +17,16 @@ public class DashboardController : AdminBaseController private readonly IHolidayItemApplication _holidayItemApplication; private readonly ITaskApplication _taskApplication; private readonly ITicketApplication _ticketApplication; + private readonly IUidService _uidService; private long UserId; - public DashboardController(ISmsService smsService, IHolidayItemApplication holidayItemApplication, ITaskApplication taskApplication,IAuthHelper authHelper, ITicketApplication ticketApplication) + public DashboardController(ISmsService smsService, IHolidayItemApplication holidayItemApplication, ITaskApplication taskApplication,IAuthHelper authHelper, ITicketApplication ticketApplication, IUidService uidService) { _smsService = smsService; _holidayItemApplication = holidayItemApplication; _taskApplication = taskApplication; _ticketApplication = ticketApplication; + _uidService = uidService; UserId = authHelper.CurrentAccountId(); } [HttpGet] @@ -68,6 +71,26 @@ public class DashboardController : AdminBaseController var result = (int)await _smsService.GetCreditAmount(); return new SmsRemainingResult(result); } + + [HttpGet("account-info")] + public async Task OnGetAccountInfo(string cardNumber) + { + var cardToNumberResponse = await _uidService.CardToIban(cardNumber); + return Ok(cardToNumberResponse); + } + [HttpGet("account-info2")] + public async Task OnGetAccountInfo2(string iban) + { + var cardToNumberResponse = await _uidService.IbanInquiry(iban); + return Ok(cardToNumberResponse); + } + [HttpGet("account-info3")] + public async Task OnGetAccountInfo3(string accountNumber, UidBanks banks) + { + var cardToNumberResponse = await _uidService.AccountToIban(accountNumber, banks); + return Ok(cardToNumberResponse); + } + } public record SmsRemainingResult(int Data); From a5e68cbd90d2fa93b82705da10e3ff022473660d Mon Sep 17 00:00:00 2001 From: mahan Date: Thu, 16 Oct 2025 10:20:02 +0330 Subject: [PATCH 4/5] feat: remove deprecated account info endpoints and update request context structure in UidService --- 0_Framework/Application/UID/IUidService.cs | 8 +++++++- .../Services/UidService.cs | 11 +++++----- .../Admin/Controllers/DashboardController.cs | 20 ------------------- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/0_Framework/Application/UID/IUidService.cs b/0_Framework/Application/UID/IUidService.cs index 63599699..a3350dfa 100644 --- a/0_Framework/Application/UID/IUidService.cs +++ b/0_Framework/Application/UID/IUidService.cs @@ -129,6 +129,8 @@ public class AccountToIbanResponse:UidBaseResponse public class IbanInquiryResponse:UidBaseResponse { public IbanInquiryAccountBasicInformation AccountBasicInformation { get; set; } + [JsonProperty("owners")] + public List Owners { get; set; } } public class IbanInquiryAccountBasicInformation @@ -137,7 +139,7 @@ public class IbanInquiryAccountBasicInformation public string AccountNumber { get; set; } public IbanInquiryBankInformation BankInformation { get; set; } public string AccountStatus { get; set; } - public List Owners { get; set; } + } public class IbanInquiryBankInformation @@ -147,9 +149,13 @@ public class IbanInquiryBankInformation public class IbanInquiryOwner { + [JsonProperty("firstName")] public string FirstName { get; set; } + [JsonProperty("lastName")] public string LastName { get; set; } + [JsonProperty("nationalIdentifier")] public string NationalIdentifier { get; set; } + [JsonProperty("customerType")] public string CustomerType { get; set; } } diff --git a/CompanyManagment.EFCore/Services/UidService.cs b/CompanyManagment.EFCore/Services/UidService.cs index bb84c06a..a23bdfd2 100644 --- a/CompanyManagment.EFCore/Services/UidService.cs +++ b/CompanyManagment.EFCore/Services/UidService.cs @@ -154,13 +154,14 @@ public class UidService : IUidService { var request = new { - Iban = iban, - RequestContext = new UidRequestContext() + iban, + requestContext = new UidRequestContext() }; var json = JsonConvert.SerializeObject(request); var contentType = new StringContent(json, Encoding.UTF8, "application/json"); var requestResult = await _httpClient.PostAsync("inquiry/iban/v2", contentType); requestResult.EnsureSuccessStatusCode(); + //var stringRes =await requestResult.Content.ReadAsStringAsync(); var responseResult = await requestResult.Content.ReadFromJsonAsync(); return responseResult; } @@ -171,7 +172,7 @@ public class UidService : IUidService { accountNumber, bank, - RequestContext = new UidRequestContext() + requestContext = new UidRequestContext() }; var json = JsonConvert.SerializeObject(request); var contentType = new StringContent(json, Encoding.UTF8, "application/json"); @@ -186,11 +187,11 @@ public class UidService : IUidService var request = new { cardNumber, - RequestContext = new UidRequestContext() + requestContext = new UidRequestContext() }; var json = JsonConvert.SerializeObject(request); var contentType = new StringContent(json, Encoding.UTF8, "application/json"); - var requestResult = await _httpClient.PostAsync("account-to-iban", contentType); + var requestResult = await _httpClient.PostAsync("inquiry/card", contentType); requestResult.EnsureSuccessStatusCode(); var responseResult = await requestResult.Content.ReadFromJsonAsync(); return responseResult; diff --git a/ServiceHost/Areas/Admin/Controllers/DashboardController.cs b/ServiceHost/Areas/Admin/Controllers/DashboardController.cs index 49cf1486..5f1d45d1 100644 --- a/ServiceHost/Areas/Admin/Controllers/DashboardController.cs +++ b/ServiceHost/Areas/Admin/Controllers/DashboardController.cs @@ -71,26 +71,6 @@ public class DashboardController : AdminBaseController var result = (int)await _smsService.GetCreditAmount(); return new SmsRemainingResult(result); } - - [HttpGet("account-info")] - public async Task OnGetAccountInfo(string cardNumber) - { - var cardToNumberResponse = await _uidService.CardToIban(cardNumber); - return Ok(cardToNumberResponse); - } - [HttpGet("account-info2")] - public async Task OnGetAccountInfo2(string iban) - { - var cardToNumberResponse = await _uidService.IbanInquiry(iban); - return Ok(cardToNumberResponse); - } - [HttpGet("account-info3")] - public async Task OnGetAccountInfo3(string accountNumber, UidBanks banks) - { - var cardToNumberResponse = await _uidService.AccountToIban(accountNumber, banks); - return Ok(cardToNumberResponse); - } - } public record SmsRemainingResult(int Data); From 81e60948171d222588ff08b2a2e57b259917b50e Mon Sep 17 00:00:00 2001 From: mahan Date: Thu, 16 Oct 2025 13:52:05 +0330 Subject: [PATCH 5/5] feat: add bank inquiry functionality and validation methods for IBAN and card numbers --- 0_Framework/Application/Tools.cs | 8 ++ ...ContractingPartyBankAccountsApplication.cs | 24 +++++ ...ContractingPartyBankAccountsApplication.cs | 94 ++++++++++++++++++- .../PaymentInstrumentController.cs | 21 +---- 4 files changed, 124 insertions(+), 23 deletions(-) diff --git a/0_Framework/Application/Tools.cs b/0_Framework/Application/Tools.cs index 98f58bb9..23afe3cb 100644 --- a/0_Framework/Application/Tools.cs +++ b/0_Framework/Application/Tools.cs @@ -1512,6 +1512,14 @@ public static class Tools #region Mahan + public static bool IsvalidIban(this string iban) + { + return Regex.IsMatch(iban, @"^IR[0-9]{24}$"); + } + public static bool IsValidCardNumber(this string cardNumber) + { + return Regex.IsMatch(cardNumber, @"^[0-9]{16}$"); + } /// /// این متد حروف عربی را به فارسی در میاورد. مثال: علي را به علی تبدیل میکند /// diff --git a/CompanyManagment.App.Contracts/ContractingPartyBankAccounts/IContractingPartyBankAccountsApplication.cs b/CompanyManagment.App.Contracts/ContractingPartyBankAccounts/IContractingPartyBankAccountsApplication.cs index 379f07df..f4864441 100644 --- a/CompanyManagment.App.Contracts/ContractingPartyBankAccounts/IContractingPartyBankAccountsApplication.cs +++ b/CompanyManagment.App.Contracts/ContractingPartyBankAccounts/IContractingPartyBankAccountsApplication.cs @@ -1,8 +1,10 @@ using System.Collections.Generic; using System.Security.AccessControl; +using System.Security.Cryptography; using System.Threading.Tasks; using System.Transactions; using _0_Framework.Application; +using _0_Framework.Application.UID; using CompanyManagment.App.Contracts.OriginalTitle; namespace CompanyManagment.App.Contracts.ContractingPartyBankAccounts; @@ -74,5 +76,27 @@ public interface IContractingPartyBankAccountsApplication /// نام سلکت شده /// Task> ContractingPartyNamesSelectList(string search, string selected); + + /// + /// احراز هویت اطلاعات بانکی طرف حساب + /// + /// + /// + Task InquiryContractingPartyBankDetails(InquiryContractingPartyBankDetailsRequest command); + +} +public class InquiryContractingPartyBankDetailsRequest +{ + public string CardNumber { get; set; } + public string AccountNumber { get; set; } + public string IBan { get; set; } + public UidBanks UidBank { get; set; } +} +public class ContractingPartyBankInquiryResponse +{ + public string FullName { get; set; } + public string Iban { get; set; } + public string AccountNumber { get; set; } + public string CardNumber { get; set; } } diff --git a/CompanyManagment.Application/ContractingPartyBankAccountsApplication.cs b/CompanyManagment.Application/ContractingPartyBankAccountsApplication.cs index e9a81eba..e1e1dc0a 100644 --- a/CompanyManagment.Application/ContractingPartyBankAccountsApplication.cs +++ b/CompanyManagment.Application/ContractingPartyBankAccountsApplication.cs @@ -1,6 +1,10 @@ using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; using System.Threading.Tasks; using _0_Framework.Application; +using _0_Framework.Application.UID; +using _0_Framework.Exceptions; using Company.Domain.ContarctingPartyAgg; using Company.Domain.ContractingPartyBankAccountsAgg; using CompanyManagment.App.Contracts.ContractingPartyBankAccounts; @@ -12,13 +16,15 @@ public class ContractingPartyBankAccountsApplication : IContractingPartyBankAcco { private readonly IContractingPartyBankAccountsRepository _contractingPartyBankAccountsRepository; private readonly IPersonalContractingPartyRepository _personalContractingPartyRepository; + private readonly IUidService _uidService; public ContractingPartyBankAccountsApplication( IContractingPartyBankAccountsRepository contractingPartyBankAccountsRepository, - IPersonalContractingPartyRepository personalContractingPartyRepository) + IPersonalContractingPartyRepository personalContractingPartyRepository, IUidService uidService) { _contractingPartyBankAccountsRepository = contractingPartyBankAccountsRepository; _personalContractingPartyRepository = personalContractingPartyRepository; + _uidService = uidService; } public async Task Create(CreateContractingPartyBankAccounts command) @@ -69,18 +75,19 @@ public class ContractingPartyBankAccountsApplication : IContractingPartyBankAcco if (string.IsNullOrWhiteSpace(command.IBan)) return operationResult.Failed("شماره شبا خود را وارد کنید"); } - else if(string.IsNullOrWhiteSpace(command.CardNumber) && + else if (string.IsNullOrWhiteSpace(command.CardNumber) && string.IsNullOrWhiteSpace(command.AccountNumber) && string.IsNullOrWhiteSpace(command.IBan)) { - return operationResult.Failed(" حداقل یکی از اطلاعات بانکی را وارد کنید: شماره کارت، شماره حساب یا شماره شبا"); + return operationResult.Failed( + " حداقل یکی از اطلاعات بانکی را وارد کنید: شماره کارت، شماره حساب یا شماره شبا"); } if (string.IsNullOrWhiteSpace(command.AccountHolderName)) { return operationResult.Failed("نام صاحب حساب را وارد کنید"); } - + var entity = new ContractingPartyBankAccount(command.ContractingPartyId, command.CardNumber, command.AccountHolderName, command.AccountNumber, command.IBan, command.IsAuth); @@ -130,4 +137,83 @@ public class ContractingPartyBankAccountsApplication : IContractingPartyBankAcco { return await _contractingPartyBankAccountsRepository.ContractingPartyNamesSelectList(search, selected); } + + public async Task InquiryContractingPartyBankDetails( + InquiryContractingPartyBankDetailsRequest command) + { + var iBan = command.IBan; + var cardNumber = command.CardNumber; + var accountNumber = command.AccountNumber; + var uidBank = command.UidBank; + ContractingPartyBankInquiryResponse result = new ContractingPartyBankInquiryResponse(); + if (!string.IsNullOrWhiteSpace(iBan)) + { + if (!iBan.IsvalidIban()) + { + throw new BadRequestException("شماره شبا وارد شده معتبر نمی باشد"); + } + + var response = await _uidService.IbanInquiry(iBan); + if (response.ResponseContext.Status.Code != 0) + { + throw new BadRequestException("خطای احراز هویت. کد خطا: " + response.ResponseContext.Status.Code); + } + + var owner = response.Owners.FirstOrDefault(); + var ownerFirstName = owner != null ? $"{owner.FirstName} {owner.LastName}" : ""; + result.FullName = ownerFirstName; + result.AccountNumber = response.AccountBasicInformation.AccountNumber; + result.Iban = response.AccountBasicInformation.Iban; + } + else if (!string.IsNullOrWhiteSpace(cardNumber)) + { + if (!cardNumber.IsValidCardNumber()) + { + throw new BadRequestException("شماره کارت وارد شده معتبر نمی باشد"); + } + + var bankCardRes = await _uidService.CardToIban(cardNumber); + if (bankCardRes.ResponseContext.Status.Code != 0) + { + throw new BadRequestException("خطای احراز هویت. کد خطا: " + bankCardRes.ResponseContext.Status.Code); + } + + var response = await _uidService.IbanInquiry(bankCardRes.Iban); + if (response.ResponseContext.Status.Code != 0) + { + throw new BadRequestException("خطای احراز هویت. کد خطا: " + response.ResponseContext.Status.Code); + } + + var owner = response.Owners.FirstOrDefault(); + var ownerFirstName = owner != null ? $"{owner.FirstName} {owner.LastName}" : ""; + result.FullName = ownerFirstName; + result.AccountNumber = response.AccountBasicInformation.AccountNumber; + result.CardNumber = cardNumber; + result.Iban = response.AccountBasicInformation.Iban; + } + else if (!string.IsNullOrWhiteSpace(accountNumber)) + { + var accountNumberRes = await _uidService.AccountToIban(accountNumber, uidBank); + if (accountNumberRes.ResponseContext.Status.Code != 0) + { + throw new BadRequestException( + "خطای احراز هویت. کد خطا: " + accountNumberRes.ResponseContext.Status.Code); + } + + var response = await _uidService.IbanInquiry(accountNumberRes.Iban); + + var owner = response.Owners.FirstOrDefault(); + var ownerFirstName = owner != null ? $"{owner.FirstName} {owner.LastName}" : ""; + result.FullName = ownerFirstName; + result.AccountNumber = response.AccountBasicInformation.AccountNumber; + result.Iban = response.AccountBasicInformation.Iban; + } + else + { + throw new BadRequestException( + "حداقل یکی از اطلاعات بانکی را وارد کنید: شماره کارت، شماره حساب یا شماره شبا"); + } + + return result; + } } \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Controllers/PaymentInstrumentController.cs b/ServiceHost/Areas/Admin/Controllers/PaymentInstrumentController.cs index e5d86ca4..961942e7 100644 --- a/ServiceHost/Areas/Admin/Controllers/PaymentInstrumentController.cs +++ b/ServiceHost/Areas/Admin/Controllers/PaymentInstrumentController.cs @@ -229,26 +229,9 @@ public class PaymentInstrumentController:AdminBaseController [HttpPost("bank-account-inquiry")] - public async Task>> GetBankInquiry([FromBody]BankInquiryRequest command) + public async Task> GetBankInquiry([FromBody]InquiryContractingPartyBankDetailsRequest command) { - if ((!string.IsNullOrWhiteSpace(command.AccountNumber) && command.AccountNumber.StartsWith("111111")) || (!string.IsNullOrWhiteSpace(command.CardNumber)&&command.CardNumber.StartsWith("111111")) || (!string.IsNullOrWhiteSpace(command.IBan)&&command.IBan.StartsWith("1111111"))) - { - return new OperationResult().Succcedded(new BankInquiryResponse() - { - AccountNumber = "1111111", - IBan = "111111111111111111111111", - CardNumber = "1111111111111111", - AccountHolderName = "تست تستی", - BankName = "تست بانک", - }); - }else if ((!string.IsNullOrWhiteSpace(command.AccountNumber) && command.AccountNumber.StartsWith("222222")) || (!string.IsNullOrWhiteSpace(command.CardNumber)&&command.CardNumber.StartsWith("222222")) || (!string.IsNullOrWhiteSpace(command.CardNumber)&&command.CardNumber.StartsWith("222222"))) - { - return new OperationResult().Failed("دیتای وارد شده نامعتبر است"); - } - else - { - throw new InternalServerException("ارور سمت سرور"); - } + return await _contractingPartyBankAccountsApplication.InquiryContractingPartyBankDetails(command); } }