Browse Source

Updated payment

pull/53/head
Galip Tolga Erdem 4 years ago
parent
commit
7d6734dedb
  1. 1
      apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbp.PublicWeb.csproj
  2. 7
      apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicAutoMapperProfile.cs
  3. 2
      apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs
  4. 29
      apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Payment.cshtml.cs
  5. 5
      services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs
  6. 1
      services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderItemCreateDto.cs
  7. 10
      services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs

1
apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbp.PublicWeb.csproj

@ -28,6 +28,7 @@
<ProjectReference Include="..\..\..\..\services\catalog\src\EShopOnAbp.CatalogService.HttpApi.Client\EShopOnAbp.CatalogService.HttpApi.Client.csproj" />
<ProjectReference Include="..\..\..\..\services\basket\src\EShopOnAbp.BasketService.HttpApi.Client\EShopOnAbp.BasketService.HttpApi.Client.csproj" />
<ProjectReference Include="..\..\..\..\services\payment\src\EShopOnAbp.PaymentService.HttpApi.Client\EShopOnAbp.PaymentService.HttpApi.Client.csproj" />
<ProjectReference Include="..\..\..\..\services\ordering\src\EShopOnAbp.OrderingService.HttpApi.Client\EShopOnAbp.OrderingService.HttpApi.Client.csproj" />
<!-- <ProjectReference Include="..\..\..\..\services\product\src\MyCompanyName.MyProjectName.ProductService.HttpApi.Client\MyCompanyName.MyProjectName.ProductService.HttpApi.Client.csproj" />-->
</ItemGroup>

7
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<BasketItemDto, OrderItemCreateDto>()
.ForMember(p => p.Units, opts => opts.MapFrom(q => q.Count))
.ForMember(p => p.PictureUrl, opts => opts.MapFrom(q => q.ImageName))
.Ignore(q => q.Discount);
}
}
}

2
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)

29
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<EShopOnAbpPublicWebPaymentOptions> 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<BasketItemDto>, List<OrderItemCreateDto>>(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; }

5
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(),

1
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; }

10
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<OrderItemCreateDto> 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;

Loading…
Cancel
Save