a2e1e1fead
- FrontOffice.Main.csproj: switch to ProjectReference for CMS Protobuf - MagicWallet.razor.cs: update default record with PurchaseCycleCount - WalletService.cs: add PurchaseCycleCount to MagicWalletStatus record - Profile/Index.razor.cs: load _purchaseCycleCount from MagicWalletStatus - Profile/Index.razor: conditional purchase dialog (IPG vs Daya by cycle) - Licenses.razor: fix grid column size xs=6
80 lines
2.3 KiB
C#
80 lines
2.3 KiB
C#
using DateTimeConverterCL;
|
|
using FrontOffice.Main.Utilities;
|
|
using Microsoft.AspNetCore.Components;
|
|
using MudBlazor;
|
|
|
|
namespace FrontOffice.Main.Pages.Profile;
|
|
|
|
public partial class MagicWallet : ComponentBase
|
|
{
|
|
private MagicWalletStatus _status = new(0, 0, 0, 0, 0, 0, null, 0);
|
|
private bool _isLoading = true;
|
|
private bool _isProcessing;
|
|
private long _chargeAmount;
|
|
private double _progressPercent;
|
|
private string? _paymentResult;
|
|
|
|
private readonly long[] _presetAmounts = { 1_000_000, 5_000_000, 10_000_000, 20_000_000, 50_000_000, 100_000_000 };
|
|
|
|
[SupplyParameterFromQuery(Name = "payment")]
|
|
public string? PaymentQueryParam { get; set; }
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
_paymentResult = PaymentQueryParam;
|
|
await LoadStatus();
|
|
}
|
|
|
|
private async Task LoadStatus()
|
|
{
|
|
_isLoading = true;
|
|
_status = await WalletService.GetMagicWalletStatusAsync();
|
|
|
|
_progressPercent = _status.MagicMaxDeposit > 0
|
|
? (double)_status.MagicTotalDeposited / _status.MagicMaxDeposit * 100
|
|
: 0;
|
|
|
|
_isLoading = false;
|
|
}
|
|
|
|
private async Task StartMagicCharge()
|
|
{
|
|
if (_chargeAmount <= 0 || _isProcessing) return;
|
|
|
|
_isProcessing = true;
|
|
StateHasChanged();
|
|
|
|
try
|
|
{
|
|
// تبدیل تومان به ریال
|
|
var amountInRial = _chargeAmount * 10;
|
|
|
|
var (success, gatewayUrl, error) = await WalletService.InitiateMagicChargeAsync(amountInRial);
|
|
|
|
if (success && !string.IsNullOrEmpty(gatewayUrl))
|
|
{
|
|
Navigation.NavigateTo(gatewayUrl, forceLoad: true);
|
|
}
|
|
else
|
|
{
|
|
Snackbar.Add(error ?? "خطا در ایجاد درخواست پرداخت", Severity.Error);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Snackbar.Add($"خطا: {ex.Message}", Severity.Error);
|
|
}
|
|
finally
|
|
{
|
|
_isProcessing = false;
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
|
|
private static string FormatPrice(long priceInRial)
|
|
=> string.Format("{0:N0} تومان", priceInRial / 10);
|
|
|
|
private static string FormatToman(long toman)
|
|
=> string.Format("{0:N0} تومان", toman);
|
|
}
|