From 61fd805c7593c54c68e32bdbbb0f22e500851c53 Mon Sep 17 00:00:00 2001 From: masoodafar-web Date: Sun, 23 Aug 2026 23:01:39 +0330 Subject: [PATCH] feat(profile): enhance withdrawal request processing with IBAN normalization - Implemented a new method to normalize Iranian IBANs, ensuring they are formatted correctly before processing withdrawal requests. - Added validation to provide user feedback if the IBAN format is invalid, improving the user experience during withdrawal submissions. - Updated the withdrawal request logic to utilize the normalized IBAN, enhancing the reliability of the withdrawal process. These changes improve the accuracy and usability of the withdrawal request feature, ensuring users can submit valid IBANs effectively. --- src/FrontOffice.Main/Pages/Checkout.razor.cs | 2 - .../Pages/Profile/WithdrawalRequests.razor.cs | 37 ++++++++++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/FrontOffice.Main/Pages/Checkout.razor.cs b/src/FrontOffice.Main/Pages/Checkout.razor.cs index 24b12f8..aeaf1a6 100644 --- a/src/FrontOffice.Main/Pages/Checkout.razor.cs +++ b/src/FrontOffice.Main/Pages/Checkout.razor.cs @@ -1,7 +1,6 @@ using CMSMicroservice.Protobuf.Protos.Package; using FrontOffice.Main.Utilities; using Microsoft.AspNetCore.Components; -using Microsoft.JSInterop; using MudBlazor; using Severity = MudBlazor.Severity; @@ -11,7 +10,6 @@ public partial class Checkout { [Inject] private PackageService PackageService { get; set; } = default!; [Inject] private PackageContract.PackageContractClient PackageClient { get; set; } = default!; - [Inject] private IJSRuntime JSRuntime { get; set; } = default!; [Parameter] public long? PackageId { get; set; } diff --git a/src/FrontOffice.Main/Pages/Profile/WithdrawalRequests.razor.cs b/src/FrontOffice.Main/Pages/Profile/WithdrawalRequests.razor.cs index 5866666..2370755 100644 --- a/src/FrontOffice.Main/Pages/Profile/WithdrawalRequests.razor.cs +++ b/src/FrontOffice.Main/Pages/Profile/WithdrawalRequests.razor.cs @@ -58,8 +58,19 @@ public partial class WithdrawalRequests : ComponentBase try { _isSubmittingWithdrawal = true; - _withdrawIban=_withdrawIban!.Trim().ToUpper().Replace("IR", "").Replace(" ", ""); - await WalletService.RequestWithdrawalAsync(_selectedPayout.Id, _withdrawMethod, "IR"+_withdrawIban); + + string? normalizedIban = null; + if (_withdrawMethod == WithdrawalMethodClient.Cash) + { + normalizedIban = NormalizeIranianIban(_withdrawIban); + if (normalizedIban is null) + { + Snackbar.Add("فرمت شماره شبا معتبر نیست. باید IR و ۲۴ رقم باشد (خط تیره اختیاری است).", Severity.Warning); + return; + } + } + + await WalletService.RequestWithdrawalAsync(_selectedPayout.Id, _withdrawMethod, normalizedIban); Snackbar.Add("درخواست برداشت ثبت شد.", Severity.Success); // بروزرسانی لیست @@ -125,4 +136,26 @@ public partial class WithdrawalRequests : ComponentBase 1 => "الماس", _ => "-" }; + + /// + /// فاصله و خط تیره را حذف می‌کند و شبا را به شکل IR + ۲۴ رقم برمی‌گرداند. + /// + private static string? NormalizeIranianIban(string? iban) + { + if (string.IsNullOrWhiteSpace(iban)) + return null; + + var normalized = iban.Trim().ToUpperInvariant() + .Replace(" ", "", StringComparison.Ordinal) + .Replace("-", "", StringComparison.Ordinal); + + if (normalized.StartsWith("IR", StringComparison.Ordinal)) + normalized = normalized[2..]; + + normalized = "IR" + normalized; + + return System.Text.RegularExpressions.Regex.IsMatch(normalized, @"^IR\d{24}$") + ? normalized + : null; + } }