u
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="3">
|
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="3">
|
||||||
<MudIcon Icon="@Icons.Material.Filled.ShoppingCart" Size="Size.Large" Color="Color.Primary" />
|
<MudIcon Icon="@Icons.Material.Filled.ShoppingCart" Size="Size.Large" Color="Color.Primary" />
|
||||||
<div>
|
<div>
|
||||||
<MudText Typo="Typo.h4" >تکمیل خرید</MudText>
|
<MudText Typo="Typo.h4">تکمیل خرید</MudText>
|
||||||
<MudText Typo="Typo.body2" Class="mud-text-secondary">مرحله نهایی خرید پکیج</MudText>
|
<MudText Typo="Typo.body2" Class="mud-text-secondary">مرحله نهایی خرید پکیج</MudText>
|
||||||
</div>
|
</div>
|
||||||
</MudStack>
|
</MudStack>
|
||||||
@@ -86,29 +86,41 @@
|
|||||||
Elevation="@(_selectedAddress?.Id == address.Id ? 4 : 0)"
|
Elevation="@(_selectedAddress?.Id == address.Id ? 4 : 0)"
|
||||||
Class="pa-3 rounded-xl cursor-pointer"
|
Class="pa-3 rounded-xl cursor-pointer"
|
||||||
Style="@(_selectedAddress?.Id == address.Id ? "border: 2px solid var(--mud-palette-primary);" : "")"
|
Style="@(_selectedAddress?.Id == address.Id ? "border: 2px solid var(--mud-palette-primary);" : "")"
|
||||||
OnClick="() => SelectAddress(address)">
|
@onclick="() => SetAddressAsDefault(address.Id)">
|
||||||
<MudStack Spacing="1">
|
<MudStack Spacing="1">
|
||||||
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="2">
|
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="2">
|
||||||
<MudRadio T="long" Value="address.Id" Checked="@(_selectedAddress?.Id == address.Id)" />
|
<MudCheckBox @bind-Value="address.IsDefault"
|
||||||
<MudText Typo="Typo.subtitle2">@address.Title</MudText>
|
Disabled="true"
|
||||||
|
Color="Color.Primary" />
|
||||||
|
<MudText Typo="Typo.subtitle2">@(address.Title)</MudText>
|
||||||
@if (address.IsDefault)
|
@if (address.IsDefault)
|
||||||
{
|
{
|
||||||
<MudChip T="string" Color="Color.Success" Variant="Variant.Filled" Size="Size.Small">پیشفرض</MudChip>
|
<MudChip T="string" Color="Color.Success" Variant="Variant.Filled" Size="Size.Small">پیشفرض</MudChip>
|
||||||
}
|
}
|
||||||
@if (!address.IsDefault)
|
@if (!address.IsDefault)
|
||||||
{
|
{
|
||||||
<MudButton Variant="Variant.Text"
|
@if (_isSettingDefaultAddress && _settingDefaultAddressId == address.Id)
|
||||||
Color="Color.Primary"
|
{
|
||||||
Size="Size.Small"
|
<MudProgressCircular Size="Size.Small" Color="Color.Primary" Indeterminate="true" />
|
||||||
OnClick="() => SetAddressAsDefault(address.Id)">
|
}
|
||||||
تنظیم به عنوان پیشفرض
|
else
|
||||||
</MudButton>
|
{
|
||||||
|
<MudButton Variant="Variant.Text"
|
||||||
|
Color="Color.Primary"
|
||||||
|
Size="Size.Small"
|
||||||
|
OnClick="() => SetAddressAsDefault(address.Id)">
|
||||||
|
تنظیم به عنوان پیشفرض
|
||||||
|
</MudButton>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</MudStack>
|
</MudStack>
|
||||||
<MudText Typo="Typo.body2" Class="mud-text-secondary">@address.Address</MudText>
|
<MudStack Row="true">
|
||||||
<MudText Typo="Typo.caption" Class="mud-text-secondary">کد پستی: @address.PostalCode</MudText>
|
<MudText Typo="Typo.body2" Class="mud-text-secondary">@(address.Address)</MudText>
|
||||||
|
<MudSpacer />
|
||||||
|
<MudText Typo="Typo.caption" Class="mud-text-secondary">کد پستی: @(address.PostalCode)</MudText>
|
||||||
</MudStack>
|
</MudStack>
|
||||||
</MudPaper>
|
</MudStack>
|
||||||
|
</MudPaper>
|
||||||
}
|
}
|
||||||
</MudStack>
|
</MudStack>
|
||||||
}
|
}
|
||||||
@@ -140,23 +152,22 @@
|
|||||||
<MudPaper Elevation="4" Class="pa-6">
|
<MudPaper Elevation="4" Class="pa-6">
|
||||||
<MudText Typo="Typo.h5" Class="mb-4">کد تخفیف</MudText>
|
<MudText Typo="Typo.h5" Class="mb-4">کد تخفیف</MudText>
|
||||||
<MudStack Spacing="3">
|
<MudStack Spacing="3">
|
||||||
<MudStack Row="true" Spacing="2" AlignItems="AlignItems.Stretch">
|
<MudTextField @bind-Value="_discountCode"
|
||||||
<MudTextField @bind-Value="_discountCode"
|
Label="کد تخفیف"
|
||||||
Label="کد تخفیف"
|
Variant="Variant.Outlined"
|
||||||
Variant="Variant.Outlined"
|
Class="flex-grow-1"
|
||||||
Class="flex-grow-1"
|
Placeholder="کد تخفیف خود را وارد کنید" />
|
||||||
Placeholder="کد تخفیف خود را وارد کنید" />
|
|
||||||
<MudButton Variant="Variant.Filled"
|
<MudButton Variant="Variant.Filled"
|
||||||
Color="Color.Secondary"
|
Color="Color.Secondary"
|
||||||
OnClick="ApplyDiscountCode"
|
OnClick="ApplyDiscountCode"
|
||||||
Disabled="_isApplyingDiscount">
|
Disabled="_isApplyingDiscount">
|
||||||
اعمال
|
اعمال
|
||||||
</MudButton>
|
</MudButton>
|
||||||
</MudStack>
|
|
||||||
@if (!string.IsNullOrWhiteSpace(_discountMessage))
|
@if (!string.IsNullOrWhiteSpace(_discountMessage))
|
||||||
{
|
{
|
||||||
<MudText Typo="Typo.caption" Color="@(_discountApplied ? Color.Success : Color.Error)" Class="mt-2">
|
<MudText Typo="Typo.caption" Color="@(_discountApplied ? Color.Success : Color.Error)" Class="mt-2">
|
||||||
@_discountMessage
|
@(_discountMessage)
|
||||||
</MudText>
|
</MudText>
|
||||||
}
|
}
|
||||||
</MudStack>
|
</MudStack>
|
||||||
@@ -170,37 +181,37 @@
|
|||||||
|
|
||||||
<MudStack Spacing="3">
|
<MudStack Spacing="3">
|
||||||
<MudStack Row="true" Justify="Justify.SpaceBetween">
|
<MudStack Row="true" Justify="Justify.SpaceBetween">
|
||||||
<MudText Typo="Typo.body1">پکیج @(_selectedPackage.Title)</MudText>
|
<MudText Typo="Typo.body1">@(_selectedPackage.Title)</MudText>
|
||||||
<MudText Typo="Typo.body1">@_selectedPackage.Price.ToThousands().ToCurrencyUnitIRT()</MudText>
|
<MudText Typo="Typo.body1">@(_selectedPackage.Price.ToThousands().ToCurrencyUnitIRT())</MudText>
|
||||||
</MudStack>
|
</MudStack>
|
||||||
|
|
||||||
@if (_discountApplied && _discountAmount > 0)
|
@if (_discountApplied && _discountAmount > 0)
|
||||||
{
|
{
|
||||||
<MudStack Row="true" Justify="Justify.SpaceBetween">
|
<MudStack Row="true" Justify="Justify.SpaceBetween">
|
||||||
<MudText Typo="Typo.body2" Color="Color.Success">تخفیف (@_discountCode)</MudText>
|
<MudText Typo="Typo.body2" Color="Color.Success">تخفیف (@(_discountCode))</MudText>
|
||||||
<MudText Typo="Typo.body2" Color="Color.Success">-@_discountAmount.ToThousands().ToCurrencyUnitIRT()</MudText>
|
<MudText Typo="Typo.body2" Color="Color.Success">-@(_discountAmount.ToThousands().ToCurrencyUnitIRT())</MudText>
|
||||||
</MudStack>
|
</MudStack>
|
||||||
}
|
}
|
||||||
|
|
||||||
<MudDivider />
|
<MudDivider />
|
||||||
|
|
||||||
<MudStack Row="true" Justify="Justify.SpaceBetween">
|
<MudStack Row="true" Justify="Justify.SpaceBetween">
|
||||||
<MudText Typo="Typo.h6" >مجموع</MudText>
|
<MudText Typo="Typo.h6">مجموع</MudText>
|
||||||
<MudText Typo="Typo.h6" Color="Color.Primary">@_finalPrice.ToThousands().ToCurrencyUnitIRT()</MudText>
|
<MudText Typo="Typo.h6" Color="Color.Primary">@(_finalPrice.ToThousands().ToCurrencyUnitIRT())</MudText>
|
||||||
</MudStack>
|
</MudStack>
|
||||||
|
|
||||||
<MudButton Variant="Variant.Filled"
|
<MudButton Variant="Variant.Filled"
|
||||||
Color="Color.Success"
|
Color="Color.Success"
|
||||||
Size="Size.Large"
|
Size="Size.Large"
|
||||||
FullWidth="true"
|
FullWidth="true"
|
||||||
StartIcon="@Icons.Material.Filled.Payment"
|
StartIcon="@Icons.Material.Filled.Payment"
|
||||||
OnClick="ProcessPayment"
|
OnClick="ProcessPayment"
|
||||||
Disabled="@(!CanProceedToPayment || _isProcessingPayment)"
|
Disabled="@(!CanProceedToPayment || _isProcessingPayment)"
|
||||||
Class="mt-2">
|
Class="mt-2">
|
||||||
@(_isProcessingPayment ? "در حال پردازش..." : "پرداخت آنلاین")
|
@(_isProcessingPayment ? "در حال پردازش..." : "پرداخت آنلاین")
|
||||||
</MudButton>
|
</MudButton>
|
||||||
|
|
||||||
@if (!CanProceedToPayment)
|
@if (!CanProceedToPayment)
|
||||||
{
|
{
|
||||||
<MudText Typo="Typo.caption" Color="Color.Error" Align="Align.Center">
|
<MudText Typo="Typo.caption" Color="Color.Error" Align="Align.Center">
|
||||||
لطفاً پکیج و آدرس را انتخاب کنید.
|
لطفاً پکیج و آدرس را انتخاب کنید.
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ public partial class Checkout
|
|||||||
private long _discountAmount;
|
private long _discountAmount;
|
||||||
private long _finalPrice;
|
private long _finalPrice;
|
||||||
|
|
||||||
|
// Address management
|
||||||
|
private bool _isSettingDefaultAddress;
|
||||||
|
private long? _settingDefaultAddressId;
|
||||||
|
|
||||||
private bool CanProceedToPayment => _selectedPackage != null && _selectedAddress != null;
|
private bool CanProceedToPayment => _selectedPackage != null && _selectedAddress != null;
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
@@ -96,14 +100,13 @@ public partial class Checkout
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SelectAddress(GetAllUserAddressByFilterResponseModel address)
|
|
||||||
{
|
|
||||||
_selectedAddress = address;
|
|
||||||
StateHasChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task SetAddressAsDefault(long addressId)
|
private async Task SetAddressAsDefault(long addressId)
|
||||||
{
|
{
|
||||||
|
if (_isSettingDefaultAddress) return;
|
||||||
|
|
||||||
|
_isSettingDefaultAddress = true;
|
||||||
|
_settingDefaultAddressId = addressId;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await UserAddressContract.SetAddressAsDefaultAsync(new() { Id = addressId });
|
await UserAddressContract.SetAddressAsDefaultAsync(new() { Id = addressId });
|
||||||
@@ -114,6 +117,12 @@ public partial class Checkout
|
|||||||
{
|
{
|
||||||
Snackbar.Add($"خطا در تغییر آدرس پیشفرض: {ex.Message}", Severity.Error);
|
Snackbar.Add($"خطا در تغییر آدرس پیشفرض: {ex.Message}", Severity.Error);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_isSettingDefaultAddress = false;
|
||||||
|
_settingDefaultAddressId = null;
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ApplyDiscountCode()
|
private async Task ApplyDiscountCode()
|
||||||
@@ -163,6 +172,9 @@ public partial class Checkout
|
|||||||
|
|
||||||
private async Task ProcessPayment()
|
private async Task ProcessPayment()
|
||||||
{
|
{
|
||||||
|
Snackbar.Add("درگاه پرداخت متصل نیست! لطفا در زمان دیگری مجددا تلاش فرمایید!", Severity.Warning);
|
||||||
|
return;
|
||||||
|
|
||||||
if (!CanProceedToPayment || _selectedPackage == null || _selectedAddress == null)
|
if (!CanProceedToPayment || _selectedPackage == null || _selectedAddress == null)
|
||||||
{
|
{
|
||||||
Snackbar.Add("لطفاً پکیج و آدرس را انتخاب کنید.", Severity.Warning);
|
Snackbar.Add("لطفاً پکیج و آدرس را انتخاب کنید.", Severity.Warning);
|
||||||
@@ -186,9 +198,7 @@ public partial class Checkout
|
|||||||
var paymentResponse = await TransactionContract.PaymentRequestAsync(paymentRequest);
|
var paymentResponse = await TransactionContract.PaymentRequestAsync(paymentRequest);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(paymentResponse.PaymentGWUrl))
|
if (string.IsNullOrEmpty(paymentResponse.PaymentGWUrl))
|
||||||
{
|
Snackbar.Add("آدرس درگاه پرداخت دریافت نشد.", Severity.Error);
|
||||||
throw new Exception("آدرس درگاه پرداخت دریافت نشد.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 2: Create user order
|
// Step 2: Create user order
|
||||||
var orderRequest = new CreateNewUserOrderRequest
|
var orderRequest = new CreateNewUserOrderRequest
|
||||||
|
|||||||
Reference in New Issue
Block a user