u
This commit is contained in:
@@ -9,6 +9,7 @@ using FrontOffice.BFF.Package.Protobuf.Protos.Package;
|
||||
using FrontOffice.BFF.User.Protobuf.Protos.User;
|
||||
using FrontOffice.BFF.UserAddress.Protobuf.Protos.UserAddress;
|
||||
using FrontOffice.BFF.UserOrder.Protobuf.Protos.UserOrder;
|
||||
using FrontOffice.BFF.Transaction.Protobuf.Protos.Transaction;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
@@ -55,6 +56,7 @@ public static class ConfigureServices
|
||||
services.AddScoped(CreateAuthenticatedClient<UserContract.UserContractClient>);
|
||||
services.AddScoped(CreateAuthenticatedClient<UserAddressContract.UserAddressContractClient>);
|
||||
services.AddScoped(CreateAuthenticatedClient<UserOrderContract.UserOrderContractClient>);
|
||||
services.AddScoped(CreateAuthenticatedClient<TransactionContract.TransactionContractClient>);
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DateTimeConverterCL" Version="1.0.0" />
|
||||
<PackageReference Include="Foursat.FrontOffice.BFF.Package.Protobuf" Version="0.0.112" />
|
||||
<PackageReference Include="Foursat.FrontOffice.BFF.Transaction.Protobuf" Version="0.0.111" />
|
||||
<PackageReference Include="Foursat.FrontOffice.BFF.User.Protobuf" Version="0.0.115" />
|
||||
<PackageReference Include="Foursat.FrontOffice.BFF.UserAddress.Protobuf" Version="0.0.114" />
|
||||
<PackageReference Include="Foursat.FrontOffice.BFF.UserOrder.Protobuf" Version="0.0.112" />
|
||||
|
||||
190
src/FrontOffice.Main/Pages/Checkout.razor
Normal file
190
src/FrontOffice.Main/Pages/Checkout.razor
Normal file
@@ -0,0 +1,190 @@
|
||||
@attribute [Route(RouteConstants.Checkout.Index + "/{PackageId:long}")]
|
||||
@inject NavigationManager Navigation
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>تکمیل خرید</PageTitle>
|
||||
|
||||
<MudContainer MaxWidth="MaxWidth.Large" Class="py-6">
|
||||
<MudGrid Spacing="4">
|
||||
<!-- Header -->
|
||||
<MudItem xs="12">
|
||||
<MudPaper Elevation="4" Class="mud-elevation-4 pa-6 rounded-2xl mud-theme-surface">
|
||||
<MudStack Spacing="3">
|
||||
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="3">
|
||||
<MudIcon Icon="@Icons.Material.Filled.ShoppingCart" Size="Size.Large" Color="Color.Primary" />
|
||||
<div>
|
||||
<MudText Typo="Typo.h4" Class="fw-600">تکمیل خرید</MudText>
|
||||
<MudText Typo="Typo.body2" Class="mud-text-secondary">مرحله نهایی خرید پکیج</MudText>
|
||||
</div>
|
||||
</MudStack>
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
|
||||
<!-- Package Details -->
|
||||
<MudItem xs="12" md="8">
|
||||
<MudPaper Elevation="4" Class="mud-elevation-4 pa-6 rounded-2xl mud-theme-surface">
|
||||
<MudText Typo="Typo.h5" Class="mb-4 fw-600">جزئیات پکیج</MudText>
|
||||
|
||||
@if (_selectedPackage != null)
|
||||
{
|
||||
<MudStack Spacing="4">
|
||||
<MudCard>
|
||||
<MudCardMedia Image="@_selectedPackage.Image"
|
||||
Title="@_selectedPackage.Title"
|
||||
Height="200" />
|
||||
<MudCardContent>
|
||||
<MudText Typo="Typo.h5" Class="mb-2">@_selectedPackage.Title</MudText>
|
||||
@((MarkupString)_selectedPackage.Body)
|
||||
</MudCardContent>
|
||||
</MudCard>
|
||||
|
||||
<!-- Discount Code Section -->
|
||||
<MudPaper Outlined="true" Class="pa-4 rounded-xl">
|
||||
<MudText Typo="Typo.subtitle1" Class="mb-3 fw-600">کد تخفیف</MudText>
|
||||
<MudStack Row="true" Spacing="2" AlignItems="AlignItems.Stretch">
|
||||
<MudTextField @bind-Value="_discountCode"
|
||||
Label="کد تخفیف"
|
||||
Variant="Variant.Outlined"
|
||||
Class="flex-grow-1"
|
||||
Placeholder="کد تخفیف خود را وارد کنید" />
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Secondary"
|
||||
OnClick="ApplyDiscountCode"
|
||||
Disabled="_isApplyingDiscount">
|
||||
اعمال
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
@if (!string.IsNullOrWhiteSpace(_discountMessage))
|
||||
{
|
||||
<MudText Typo="Typo.caption" Color="@(_discountApplied ? Color.Success : Color.Error)" Class="mt-2">
|
||||
@_discountMessage
|
||||
</MudText>
|
||||
}
|
||||
</MudPaper>
|
||||
</MudStack>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudStack AlignItems="AlignItems.Center" Class="py-8">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Warning" Size="Size.Large" Color="Color.Warning" />
|
||||
<MudText Typo="Typo.body1" Class="mud-text-secondary mt-2">پکیجی انتخاب نشده است.</MudText>
|
||||
<MudButton Variant="Variant.Outlined"
|
||||
Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Filled.ArrowBack"
|
||||
OnClick="() => Navigation.NavigateTo(RouteConstants.Main.MainPage)"
|
||||
Class="mt-2">
|
||||
بازگشت به صفحه اصلی
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
}
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
|
||||
<!-- Order Summary & Address -->
|
||||
<MudItem xs="12" md="4">
|
||||
<MudStack Spacing="4">
|
||||
<!-- Address Selection -->
|
||||
<MudPaper Elevation="4" Class="mud-elevation-4 pa-6 rounded-2xl mud-theme-surface">
|
||||
<MudText Typo="Typo.h5" Class="mb-4 fw-600">انتخاب آدرس</MudText>
|
||||
|
||||
@if (_isLoadingAddresses)
|
||||
{
|
||||
<MudStack AlignItems="AlignItems.Center" Class="py-4">
|
||||
<MudProgressCircular Color="Color.Primary" Indeterminate="true" Size="Size.Medium" />
|
||||
<MudText Typo="Typo.body2" Class="mud-text-secondary mt-2">بارگذاری آدرسها...</MudText>
|
||||
</MudStack>
|
||||
}
|
||||
else if (_addresses.Any())
|
||||
{
|
||||
<MudStack Spacing="2">
|
||||
@foreach (var address in _addresses)
|
||||
{
|
||||
<MudPaper Outlined="@(_selectedAddress?.Id != address.Id)"
|
||||
Elevation="@(_selectedAddress?.Id == address.Id ? 4 : 0)"
|
||||
Class="pa-3 rounded-xl cursor-pointer"
|
||||
Style="@(_selectedAddress?.Id == address.Id ? "border: 2px solid var(--mud-palette-primary);" : "")"
|
||||
OnClick="() => SelectAddress(address)">
|
||||
<MudStack Spacing="1">
|
||||
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="2">
|
||||
<MudRadio T="long" Value="address.Id" Checked="@(_selectedAddress?.Id == address.Id)" />
|
||||
<MudText Typo="Typo.subtitle2" Class="fw-600">@address.Title</MudText>
|
||||
@if (address.IsDefault)
|
||||
{
|
||||
<MudChip T="string" Color="Color.Success" Variant="Variant.Filled" Size="Size.Small">پیشفرض</MudChip>
|
||||
}
|
||||
</MudStack>
|
||||
<MudText Typo="Typo.body2" Class="mud-text-secondary">@address.Address</MudText>
|
||||
<MudText Typo="Typo.caption" Class="mud-text-secondary">کد پستی: @address.PostalCode</MudText>
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
}
|
||||
</MudStack>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudStack AlignItems="AlignItems.Center" Class="py-4">
|
||||
<MudIcon Icon="@Icons.Material.Filled.LocationOff" Size="Size.Large" Color="Color.Default" />
|
||||
<MudText Typo="Typo.body2" Class="mud-text-secondary mt-2">آدرسی ثبت نشده است.</MudText>
|
||||
<MudButton Variant="Variant.Outlined"
|
||||
Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Filled.Add"
|
||||
OnClick="() => Navigation.NavigateTo(RouteConstants.Profile.Index)"
|
||||
Class="mt-2">
|
||||
افزودن آدرس
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
}
|
||||
</MudPaper>
|
||||
|
||||
<!-- Order Summary -->
|
||||
@if (_selectedPackage != null)
|
||||
{
|
||||
<MudPaper Elevation="4" Class="mud-elevation-4 pa-6 rounded-2xl mud-theme-surface">
|
||||
<MudText Typo="Typo.h5" Class="mb-4 fw-600">خلاصه سفارش</MudText>
|
||||
|
||||
<MudStack Spacing="3">
|
||||
<MudStack Row="true" Justify="Justify.SpaceBetween">
|
||||
<MudText Typo="Typo.body1">پکیج @(_selectedPackage.Title)</MudText>
|
||||
<MudText Typo="Typo.body1">@_selectedPackage.Price.ToThousands().ToCurrencyUnitIRT()</MudText>
|
||||
</MudStack>
|
||||
|
||||
@if (_discountApplied && _discountAmount > 0)
|
||||
{
|
||||
<MudStack Row="true" Justify="Justify.SpaceBetween">
|
||||
<MudText Typo="Typo.body2" Color="Color.Success">تخفیف (@_discountCode)</MudText>
|
||||
<MudText Typo="Typo.body2" Color="Color.Success">-@_discountAmount.ToThousands().ToCurrencyUnitIRT()</MudText>
|
||||
</MudStack>
|
||||
}
|
||||
|
||||
<MudDivider />
|
||||
|
||||
<MudStack Row="true" Justify="Justify.SpaceBetween">
|
||||
<MudText Typo="Typo.h6" Class="fw-600">مجموع</MudText>
|
||||
<MudText Typo="Typo.h6" Class="fw-600" Color="Color.Primary">@_finalPrice.ToThousands().ToCurrencyUnitIRT()</MudText>
|
||||
</MudStack>
|
||||
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Success"
|
||||
Size="Size.Large"
|
||||
FullWidth="true"
|
||||
StartIcon="@Icons.Material.Filled.Payment"
|
||||
OnClick="ProcessPayment"
|
||||
Disabled="@(!CanProceedToPayment || _isProcessingPayment)"
|
||||
Class="mt-2">
|
||||
@(_isProcessingPayment ? "در حال پردازش..." : "پرداخت آنلاین")
|
||||
</MudButton>
|
||||
|
||||
@if (!CanProceedToPayment)
|
||||
{
|
||||
<MudText Typo="Typo.caption" Color="Color.Error" Align="Align.Center">
|
||||
لطفاً پکیج و آدرس را انتخاب کنید.
|
||||
</MudText>
|
||||
}
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
}
|
||||
</MudStack>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
</MudContainer>
|
||||
178
src/FrontOffice.Main/Pages/Checkout.razor.cs
Normal file
178
src/FrontOffice.Main/Pages/Checkout.razor.cs
Normal file
@@ -0,0 +1,178 @@
|
||||
using FrontOffice.BFF.Package.Protobuf.Protos.Package;
|
||||
using FrontOffice.BFF.UserAddress.Protobuf.Protos.UserAddress;
|
||||
using FrontOffice.Main.Utilities;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
using Severity = MudBlazor.Severity;
|
||||
|
||||
namespace FrontOffice.Main.Pages;
|
||||
|
||||
public partial class Checkout
|
||||
{
|
||||
[Inject] private PackageContract.PackageContractClient PackageClient { get; set; } = default!;
|
||||
[Inject] private UserAddressContract.UserAddressContractClient UserAddressContract { get; set; } = default!;
|
||||
|
||||
[Parameter] public long? PackageId { get; set; }
|
||||
|
||||
private Pack? _selectedPackage;
|
||||
private List<GetAllUserAddressByFilterResponseModel> _addresses = new();
|
||||
private GetAllUserAddressByFilterResponseModel? _selectedAddress;
|
||||
private bool _isLoadingAddresses;
|
||||
private bool _isProcessingPayment;
|
||||
|
||||
// Discount code
|
||||
private string _discountCode = string.Empty;
|
||||
private bool _isApplyingDiscount;
|
||||
private string _discountMessage = string.Empty;
|
||||
private bool _discountApplied;
|
||||
private long _discountAmount;
|
||||
private long _finalPrice;
|
||||
|
||||
private bool CanProceedToPayment => _selectedPackage != null && _selectedAddress != null;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await LoadPackageDetails();
|
||||
await LoadAddresses();
|
||||
}
|
||||
|
||||
private async Task LoadPackageDetails()
|
||||
{
|
||||
if (PackageId.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await PackageClient.GetPackageAsync(new() { Id = PackageId.Value });
|
||||
if (response != null)
|
||||
{
|
||||
_selectedPackage = new Pack(
|
||||
Id: response.Id,
|
||||
Title: response.Title,
|
||||
Body: response.Description,
|
||||
Image: UrlUtility.DownloadUrl + response.ImagePath,
|
||||
Price: response.Price
|
||||
);
|
||||
_finalPrice = _selectedPackage.Price;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"خطا در بارگذاری پکیج: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadAddresses()
|
||||
{
|
||||
_isLoadingAddresses = true;
|
||||
try
|
||||
{
|
||||
var response = await UserAddressContract.GetAllUserAddressByFilterAsync(request: new());
|
||||
if (response?.Models?.Any() == true)
|
||||
{
|
||||
_addresses = response.Models.ToList();
|
||||
// Select default address if available
|
||||
_selectedAddress = _addresses.FirstOrDefault(a => a.IsDefault) ?? _addresses.First();
|
||||
}
|
||||
else
|
||||
{
|
||||
_addresses = new List<GetAllUserAddressByFilterResponseModel>();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"خطا در بارگذاری آدرسها: {ex.Message}", Severity.Error);
|
||||
_addresses = new List<GetAllUserAddressByFilterResponseModel>();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isLoadingAddresses = false;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectAddress(GetAllUserAddressByFilterResponseModel address)
|
||||
{
|
||||
_selectedAddress = address;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task ApplyDiscountCode()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_discountCode))
|
||||
{
|
||||
_discountMessage = "لطفاً کد تخفیف را وارد کنید.";
|
||||
_discountApplied = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_isApplyingDiscount = true;
|
||||
_discountMessage = string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
// TODO: Implement discount code validation with backend
|
||||
// For now, simulate a discount
|
||||
if (_discountCode.ToUpper() == "TEST10")
|
||||
{
|
||||
_discountAmount = (long)(_selectedPackage!.Price * 0.1); // 10% discount
|
||||
_finalPrice = _selectedPackage!.Price - _discountAmount;
|
||||
_discountMessage = "کد تخفیف با موفقیت اعمال شد.";
|
||||
_discountApplied = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_discountMessage = "کد تخفیف نامعتبر است.";
|
||||
_discountApplied = false;
|
||||
_discountAmount = 0;
|
||||
_finalPrice = _selectedPackage!.Price;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_discountMessage = "خطا در اعمال کد تخفیف.";
|
||||
_discountApplied = false;
|
||||
_discountAmount = 0;
|
||||
_finalPrice = _selectedPackage!.Price;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isApplyingDiscount = false;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ProcessPayment()
|
||||
{
|
||||
if (!CanProceedToPayment || _selectedPackage == null || _selectedAddress == null)
|
||||
{
|
||||
Snackbar.Add("لطفاً پکیج و آدرس را انتخاب کنید.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
_isProcessingPayment = true;
|
||||
|
||||
try
|
||||
{
|
||||
// TODO: Implement payment processing with backend
|
||||
// This is a placeholder for payment integration
|
||||
await Task.Delay(2000); // Simulate payment processing
|
||||
|
||||
Snackbar.Add("پرداخت با موفقیت انجام شد!", Severity.Success);
|
||||
|
||||
// Navigate to success page or order details
|
||||
Navigation.NavigateTo("/order/success");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"خطا در پردازش پرداخت: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isProcessingPayment = false;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private record Pack(long Id, string Title, string Body, string Image, long Price);
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public partial class Index
|
||||
|
||||
private void NavigateToPackage(long packageId)
|
||||
{
|
||||
Navigation.NavigateTo($"{RouteConstants.Package.Detail}/{packageId}");
|
||||
Navigation.NavigateTo($"{RouteConstants.Package.Detail}{packageId}");
|
||||
}
|
||||
|
||||
private record Pack(long Id, string Title, string Body, string Image, long Price);
|
||||
|
||||
@@ -31,4 +31,9 @@ public static class RouteConstants
|
||||
{
|
||||
public const string Index = "/contact";
|
||||
}
|
||||
|
||||
public static class Checkout
|
||||
{
|
||||
public const string Index = "/checkout";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user