From 1ce7b31d8e9c5f98cc56ed3621b327e6cf844fc1 Mon Sep 17 00:00:00 2001 From: Kira Date: Thu, 15 Sep 2022 13:37:54 -0700 Subject: [PATCH] Checkout functionality, including PayPal payment portal. --- ShopOnline.Web/Pages/Checkout.razor | 68 +++++++++++++++++++++++++ ShopOnline.Web/Pages/CheckoutBase.cs | 63 +++++++++++++++++++++++ ShopOnline.Web/Pages/ShoppingCart.razor | 2 +- ShopOnline.Web/wwwroot/index.html | 58 +++++++++++++++++++++ 4 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 ShopOnline.Web/Pages/Checkout.razor create mode 100644 ShopOnline.Web/Pages/CheckoutBase.cs diff --git a/ShopOnline.Web/Pages/Checkout.razor b/ShopOnline.Web/Pages/Checkout.razor new file mode 100644 index 0000000..af2045b --- /dev/null +++ b/ShopOnline.Web/Pages/Checkout.razor @@ -0,0 +1,68 @@ +@page "/Checkout" +@inherits CheckoutBase + +

Checkout

+ + @if (ShoppingCartItems.Count() == 0) + { +

You currently have no items in your shopping cart.

+ } + else + { +
+
+
+

Payment Method

+
+ + +
+
+
+ @if (ShoppingCartItems == null) + { +
+
+ +
+
+ } + else + { +
+

Payment Summary

+ @if (ShoppingCartItems.Count() > 0) + { + + + + + + + + + @foreach (var item in ShoppingCartItems) + { + + + + + } + + + + + +
ProductPrice
@item.Quantity x @item.ProductName@item.TotalPrice.ToString("C")
Total@PaymentAmount.ToString("C")
+ } + else + { +

You currently have no items in your shopping cart.

+ } +
+ } +
+
+ } + + diff --git a/ShopOnline.Web/Pages/CheckoutBase.cs b/ShopOnline.Web/Pages/CheckoutBase.cs new file mode 100644 index 0000000..932c095 --- /dev/null +++ b/ShopOnline.Web/Pages/CheckoutBase.cs @@ -0,0 +1,63 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using ShopOnline.Models.Dtos; +using ShopOnline.Web.Services.Contracts; + +namespace ShopOnline.Web.Pages +{ + public class CheckoutBase:ComponentBase + { + [Inject] + public IJSRuntime Js { get; set; } + + protected IEnumerable ShoppingCartItems { get; set; } + + protected int TotalQuantity { get; set; } + + protected string PaymentDescription { get; set; } + + protected decimal PaymentAmount { get; set; } + + [Inject] + public IShoppingCartService ShoppingCartService { get; set; } + + protected override async Task OnInitializedAsync() + { + try + { + ShoppingCartItems = await ShoppingCartService.GetItems(HardCoded.UserId); + + if(ShoppingCartItems != null) + { + Guid orderGuid = Guid.NewGuid(); + + PaymentAmount = ShoppingCartItems.Sum(p => p.TotalPrice); + TotalQuantity = ShoppingCartItems.Sum(p => p.Quantity); + PaymentDescription = $"O_{HardCoded.UserId}_{orderGuid}"; + } + } + catch (Exception) + { + + throw; + } + } + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + try + { + if(firstRender) + { + Console.WriteLine("HIT"); + await Js.InvokeVoidAsync("initPayPalButton"); + } + } + catch (Exception) + { + + throw; + } + } + } +} diff --git a/ShopOnline.Web/Pages/ShoppingCart.razor b/ShopOnline.Web/Pages/ShoppingCart.razor index cfaa2a8..48fcf9d 100644 --- a/ShopOnline.Web/Pages/ShoppingCart.razor +++ b/ShopOnline.Web/Pages/ShoppingCart.razor @@ -42,7 +42,7 @@ else {
Cart Summary
Total - (@TotalQuantity items)  @TotalPrice
- +   Proceed to Checkout
diff --git a/ShopOnline.Web/wwwroot/index.html b/ShopOnline.Web/wwwroot/index.html index 1914b36..354f633 100644 --- a/ShopOnline.Web/wwwroot/index.html +++ b/ShopOnline.Web/wwwroot/index.html @@ -22,6 +22,64 @@ + + + + + +