diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbp.PublicWeb.csproj b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbp.PublicWeb.csproj index 7f718696..e96e613c 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbp.PublicWeb.csproj +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbp.PublicWeb.csproj @@ -28,6 +28,7 @@ + diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicAutoMapperProfile.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicAutoMapperProfile.cs index 561a3ab2..b4bebecc 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicAutoMapperProfile.cs +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicAutoMapperProfile.cs @@ -1,6 +1,8 @@ using AutoMapper; using EShopOnAbp.BasketService; +using EShopOnAbp.OrderingService.Orders; using EShopOnAbp.PaymentService.PaymentRequests; +using Volo.Abp.AutoMapper; namespace EShopOnAbp.PublicWeb { @@ -13,6 +15,11 @@ namespace EShopOnAbp.PublicWeb .ForMember(p => p.Name, opts => opts.MapFrom(p => p.ProductName)) .ForMember(p => p.UnitPrice, opts => opts.MapFrom(p => p.TotalPrice / p.Count)) .ForMember(p => p.Quantity, opts => opts.MapFrom(p => p.Count)); + + CreateMap() + .ForMember(p => p.Units, opts => opts.MapFrom(q => q.Count)) + .ForMember(p => p.PictureUrl, opts => opts.MapFrom(q => q.ImageName)) + .Ignore(q => q.Discount); } } } diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs index 146189d6..4d36f2a3 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs @@ -13,6 +13,7 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect; using StackExchange.Redis; using System; using System.Net.Http.Headers; +using EShopOnAbp.OrderingService; using Volo.Abp; using Volo.Abp.Account; using Volo.Abp.AspNetCore.Authentication.OpenIdConnect; @@ -48,6 +49,7 @@ namespace EShopOnAbp.PublicWeb typeof(EShopOnAbpSharedLocalizationModule), typeof(CatalogServiceHttpApiClientModule), typeof(BasketServiceHttpApiClientModule), + typeof(OrderingServiceHttpApiClientModule), typeof(AbpAspNetCoreSignalRModule), typeof(PaymentServiceHttpApiClientModule), typeof(AbpAutoMapperModule) diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Payment.cshtml.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Payment.cshtml.cs index 2ecf2245..dca6651b 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Payment.cshtml.cs +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Payment.cshtml.cs @@ -6,7 +6,9 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; +using EShopOnAbp.OrderingService.Orders; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Abp.Users; @@ -16,16 +18,22 @@ namespace EShopOnAbp.PublicWeb.Pages; public class PaymentModel : AbpPageModel { private readonly IPaymentRequestAppService _paymentRequestAppService; + private readonly IOrderAppService _orderAppService; private readonly UserBasketProvider _userBasketProvider; + private readonly UserAddressProvider _userAddressProvider; private readonly EShopOnAbpPublicWebPaymentOptions _publicWebPaymentOptions; public PaymentModel( IPaymentRequestAppService paymentRequestAppService, + IOrderAppService orderAppService, UserBasketProvider userBasketProvider, + UserAddressProvider userAddressProvider, IOptions publicWebPaymentOptions) { _paymentRequestAppService = paymentRequestAppService; _userBasketProvider = userBasketProvider; + _userAddressProvider = userAddressProvider; + _orderAppService = orderAppService; _publicWebPaymentOptions = publicWebPaymentOptions.Value; } @@ -40,6 +48,14 @@ public class PaymentModel : AbpPageModel Logger.LogInformation($"PaymentId: {model.SelectedPaymentId}"); var basket = await _userBasketProvider.GetBasketAsync(); + var placedOrder = await _orderAppService.CreateAsync(new OrderCreateDto() + { + PaymentTypeId = 1, // Paypal + Address = GetUserAddress(model.SelectedAddressId), + Products = ObjectMapper.Map, List>(basket.Items) + }); + + var paymentRequest = await _paymentRequestAppService.CreateAsync(new PaymentRequestCreationDto { @@ -58,6 +74,19 @@ public class PaymentModel : AbpPageModel return Redirect(response.CheckoutLink); } + private OrderAddressDto GetUserAddress(int selectedAddressId) + { + var address = _userAddressProvider.GetDemoAddresses().First(q => q.Id == selectedAddressId); + return new OrderAddressDto + { + City = address.City, + Country = address.Country, + Description = address.Description, + Street = address.Street, + ZipCode = address.ZipCode + }; + } + public class PaymentPageViewModel { public int SelectedAddressId { get; set; } diff --git a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs index 3ddf3ba4..933110c5 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs @@ -217,9 +217,10 @@ namespace EShopOnAbp.IdentityService.DbMigrations scopes: commonScopes.Union(new[] { "AdministrationService", - "CatalogService", // Consider removing this service + "CatalogService", "BasketService", - "PaymentService" + "PaymentService", + "OrderingService" }), grantTypes: new[] { "hybrid" }, secret: "1q2w3e*".Sha256(), diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderItemCreateDto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderItemCreateDto.cs index 5bb57765..ff554fcd 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderItemCreateDto.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderItemCreateDto.cs @@ -5,6 +5,7 @@ namespace EShopOnAbp.OrderingService.Orders; public class OrderItemCreateDto { public Guid ProductId { get; set; } + public string ProductCode { get; set; } public string ProductName { get; set; } public string PictureUrl { get; set; } public decimal UnitPrice { get; set; } diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs index ceb76211..029c5c91 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs @@ -50,16 +50,18 @@ public class OrderAppService : ApplicationService, IOrderAppService return await CreateOrderDtoMappingAsync(placedOrder); } - private List<(Guid productId, string productName, decimal unitPrice, decimal discount, string pictureUrl, int units + private List<(Guid productId, string productName, string productCode, decimal unitPrice, decimal discount, string + pictureUrl, int units )> GetProductListTuple(List products) { var orderItems = - new List<(Guid productId, string productName, decimal unitPrice, decimal discount, string pictureUrl, int + new List<(Guid productId, string productName, string productCode, decimal unitPrice, decimal discount, + string pictureUrl, int units)>(); foreach (var product in products) { - orderItems.Add((product.ProductId, product.ProductName, product.UnitPrice, product.Discount, - product.PictureUrl, product.Units)); + orderItems.Add((product.ProductId, product.ProductName, product.ProductCode, product.UnitPrice, + product.Discount, product.PictureUrl, product.Units)); } return orderItems;