From 7f2b0c96f5a1d116747a93101c5bd45c4632ecea Mon Sep 17 00:00:00 2001 From: enisn Date: Tue, 18 Jan 2022 11:49:24 +0300 Subject: [PATCH] Remove PaymentType from Order Service --- .../Components/Payment/Default.cshtml | 16 +- .../Payment/PaymentWidgetViewComponent.cs | 15 +- .../EShopOnAbpPaymentConsts.cs | 2 +- .../EShopOnAbpPublicWebModule.cs | 21 +- .../Pages/OrderReceived.cshtml | 5 +- .../Pages/Payment.cshtml.cs | 7 +- .../Pages/PaymentCompleted.cshtml.cs | 8 +- .../src/EShopOnAbp.PublicWeb/Pages/payment.js | 4 +- .../PaymentMethods/PaymentMethodUiOptions.cs | 17 ++ .../ServiceProviders/PaymentMethodProvider.cs | 43 ++++ .../ServiceProviders/PaymentTypeProvider.cs | 24 -- .../components/payment/payment-widget.css | 17 +- .../components/payment/payment-widget.js | 8 +- .../Orders/OrderCreateDto.cs | 2 +- .../Orders/OrderDto.cs | 3 +- .../Orders/OrderAppService.cs | 5 +- .../OrderingServiceErrorCodes.cs | 1 - .../Orders/OrderConstants.cs | 2 +- .../Orders/Order.cs | 7 +- .../Orders/OrderManager.cs | 4 +- .../Orders/PaymentType.cs | 46 ---- .../OrderServiceDataSeedContributor.cs | 10 - .../OrderingServiceDbContext.cs | 148 ++++++------- ...0118084223_Removed_PaymentType.Designer.cs | 206 ++++++++++++++++++ .../20220118084223_Removed_PaymentType.cs | 72 ++++++ .../OrderingServiceDbContextModelSnapshot.cs | 33 +-- .../Orders/EfCoreOrderQueryableExtensions.cs | 1 - .../Orders/EfCoreOrderRepository.cs | 1 - .../Orders/OrderEfCoreQueryableExtensions.cs | 1 - .../Orders/OrderApplication_Tests.cs | 2 +- .../Orders/OrderManager_Tests.cs | 5 +- .../PaymentMethodClientProxy.Generated.cs | 23 ++ .../ClientProxies/PaymentMethodClientProxy.cs | 7 + .../PaymentRequestClientProxy.Generated.cs | 12 +- .../ClientProxies/payment-generate-proxy.json | 63 ++++-- .../Controllers/PaymentMethodController.cs | 1 + 36 files changed, 560 insertions(+), 282 deletions(-) create mode 100644 apps/public-web/src/EShopOnAbp.PublicWeb/PaymentMethods/PaymentMethodUiOptions.cs create mode 100644 apps/public-web/src/EShopOnAbp.PublicWeb/ServiceProviders/PaymentMethodProvider.cs delete mode 100644 apps/public-web/src/EShopOnAbp.PublicWeb/ServiceProviders/PaymentTypeProvider.cs delete mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/PaymentType.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220118084223_Removed_PaymentType.Designer.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220118084223_Removed_PaymentType.cs create mode 100644 services/payment/src/EShopOnAbp.PaymentService.HttpApi.Client/ClientProxies/PaymentMethodClientProxy.Generated.cs create mode 100644 services/payment/src/EShopOnAbp.PaymentService.HttpApi.Client/ClientProxies/PaymentMethodClientProxy.cs diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/Components/Payment/Default.cshtml b/apps/public-web/src/EShopOnAbp.PublicWeb/Components/Payment/Default.cshtml index 34740bc5..6aa6359b 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/Components/Payment/Default.cshtml +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/Components/Payment/Default.cshtml @@ -14,7 +14,7 @@ { string isSelectedAddressClass = address.IsDefault ? "is-selected" : string.Empty; -
+

@address.Type

@@ -31,17 +31,17 @@
@L["Payment:SelectPaymentMethod"]
- @foreach (var paymentType in Model.PaymentTypes) + @foreach (var paymentMethod in Model.PaymentMethods) { - string isSelectedClass = paymentType.IsDefault ? "is-selected" : ""; + string isSelectedClass = paymentMethod.IsDefault ? "is-selected" : ""; - + -

- @paymentType.Name +

+ @paymentMethod.Name

-

- +

+

diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/Components/Payment/PaymentWidgetViewComponent.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/Components/Payment/PaymentWidgetViewComponent.cs index 0e458afa..85020fde 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/Components/Payment/PaymentWidgetViewComponent.cs +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/Components/Payment/PaymentWidgetViewComponent.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using EShopOnAbp.BasketService; +using EShopOnAbp.PaymentService.PaymentMethods; using EShopOnAbp.PublicWeb.ServiceProviders; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc; @@ -11,23 +12,23 @@ namespace EShopOnAbp.PublicWeb.Components.Payment; [Widget( AutoInitialize = true, RefreshUrl = "/Widgets/Payment", - StyleTypes = new[] {typeof(PaymentWidgetStyleContributor)}, - ScriptTypes = new[] {typeof(PaymentWidgetScriptContributor)} + StyleTypes = new[] { typeof(PaymentWidgetStyleContributor) }, + ScriptTypes = new[] { typeof(PaymentWidgetScriptContributor) } )] public class PaymentWidgetViewComponent : AbpViewComponent { private readonly UserBasketProvider _userBasketProvider; private readonly UserAddressProvider _userAddressProvider; - private readonly PaymentTypeProvider _paymentTypeProvider; + private readonly PaymentMethodProvider _paymentMethodProvider; public PaymentWidgetViewComponent( UserBasketProvider userBasketProvider, UserAddressProvider userAddressProvider, - PaymentTypeProvider paymentTypeProvider) + PaymentMethodProvider paymentMethodProvider) { _userBasketProvider = userBasketProvider; _userAddressProvider = userAddressProvider; - _paymentTypeProvider = paymentTypeProvider; + _paymentMethodProvider = paymentMethodProvider; } public async Task InvokeAsync() @@ -36,7 +37,7 @@ public class PaymentWidgetViewComponent : AbpViewComponent { Basket = await _userBasketProvider.GetBasketAsync(), Address = _userAddressProvider.GetDemoAddresses(), - PaymentTypes = _paymentTypeProvider.GetPaymentTypes() + PaymentMethods = await _paymentMethodProvider.GetPaymentMethodsAsync() }; return View("~/Components/Payment/Default.cshtml", viewModel); } @@ -46,5 +47,5 @@ public class PaymentViewModel { public BasketDto Basket { get; set; } public List Address { get; set; } - public List PaymentTypes { get; set; } + public List PaymentMethods { get; set; } } \ No newline at end of file diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPaymentConsts.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPaymentConsts.cs index ac1619f4..02ae5dd4 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPaymentConsts.cs +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPaymentConsts.cs @@ -3,7 +3,7 @@ public static class EShopOnAbpPaymentConsts { public const string Currency = "USD"; - public const string PaymentTypeCookie = "selected_payment_type"; // Setted in payment-widget.js + public const string PaymentMethodCookie = "selected_payment_method"; // Setted in payment-widget.js public static class DemoAddressTypes { diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs index 482a3bde..912783e2 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs @@ -36,6 +36,9 @@ using Yarp.ReverseProxy.Transforms; using Volo.Abp.AspNetCore.Mvc.UI.Bundling; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Bundling; using EShopOnAbp.PublicWeb.Components.Toolbar.Cart; +using EShopOnAbp.PublicWeb.PaymentMethods; +using EShopOnAbp.PaymentService.PaymentMethods; +using Microsoft.Extensions.Configuration; namespace EShopOnAbp.PublicWeb { @@ -107,10 +110,7 @@ namespace EShopOnAbp.PublicWeb options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"]; }); - Configure(options => - { - options.PaymentSuccessfulCallbackUrl = configuration["App:SelfUrl"].EnsureEndsWith('/') + "PaymentCompleted"; - }); + ConfigurePayment(configuration); context.Services.AddAuthentication(options => { @@ -176,6 +176,19 @@ namespace EShopOnAbp.PublicWeb }); } + private void ConfigurePayment(IConfiguration configuration) + { + Configure(options => + { + options.PaymentSuccessfulCallbackUrl = configuration["App:SelfUrl"].EnsureEndsWith('/') + "PaymentCompleted"; + }); + + Configure(options => + { + options.ConfigureIcon(PaymentMethodNames.PayPal, "fa-cc-paypal paypal"); + }); + } + public override void OnApplicationInitialization(ApplicationInitializationContext context) { var app = context.GetApplicationBuilder(); diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/OrderReceived.cshtml b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/OrderReceived.cshtml index f7adfe3a..a8bb5960 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/OrderReceived.cshtml +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/OrderReceived.cshtml @@ -1,9 +1,12 @@ @page "{orderNo:int}" @using System.Globalization @using EShopOnAbp.Localization +@using EShopOnAbp.PublicWeb.PaymentMethods @using Microsoft.Extensions.Localization +@using Microsoft.Extensions.Options @model EShopOnAbp.PublicWeb.Pages.OrderReceivedModel @inject IStringLocalizer L +@inject IOptions PaymentMethodUiOptions @{ decimal orderTotal = Model.ReceivedOrder.Items.Sum(q => q.UnitPrice * q.Units); string orderTotalString = orderTotal.ToString("C", new CultureInfo("en-US")); // We work with USD any ways @@ -15,7 +18,7 @@ } @{ - var paymentIcon = Model.ReceivedOrder.PaymentType == "paypal" ? "fa-cc-paypal" : "fa-credit-card"; + var paymentIcon = PaymentMethodUiOptions.Value.Icons.GetValueOrDefault(Model.ReceivedOrder.PaymentMethod, PaymentMethodUiOptions.Value.DefaultIcon); } 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 39f08826..2d9aec56 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Payment.cshtml.cs +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Payment.cshtml.cs @@ -46,7 +46,7 @@ public class PaymentModel : AbpPageModel { Logger.LogInformation("Payment Proceeded..."); Logger.LogInformation($"AddressId: {model.SelectedAddressId}"); - Logger.LogInformation($"PaymentType: {model.SelectedPaymentType}"); + Logger.LogInformation($"PaymentMethod: {model.SelectedPaymentMethod}"); Logger.LogInformation($"Total Discount: {model.TotalDiscountPercentage}"); var basket = await _userBasketProvider.GetBasketAsync(); @@ -59,6 +59,7 @@ public class PaymentModel : AbpPageModel var placedOrder = await _orderAppService.CreateAsync(new OrderCreateDto() { + PaymentMethod = model.SelectedPaymentMethod, Address = GetUserAddress(model.SelectedAddressId), Products = productItems }); @@ -73,7 +74,7 @@ public class PaymentModel : AbpPageModel }); var response = await _paymentRequestAppService.StartAsync( - model.SelectedPaymentType, + model.SelectedPaymentMethod, new PaymentRequestStartDto { PaymentRequestId = paymentRequest.Id, @@ -87,7 +88,7 @@ public class PaymentModel : AbpPageModel public class PaymentPageViewModel { public int SelectedAddressId { get; set; } - public string SelectedPaymentType { get; set; } + public string SelectedPaymentMethod { get; set; } public decimal TotalDiscountPercentage { get; set; } } diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/PaymentCompleted.cshtml.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/PaymentCompleted.cshtml.cs index 84c37136..d761f2b4 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/PaymentCompleted.cshtml.cs +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/PaymentCompleted.cshtml.cs @@ -25,15 +25,15 @@ public class PaymentCompletedModel : AbpPageModel public async Task OnGetAsync() { - if (!HttpContext.Request.Cookies.TryGetValue(EShopOnAbpPaymentConsts.PaymentTypeCookie, - out var selectedPaymentType)) + if (!HttpContext.Request.Cookies.TryGetValue(EShopOnAbpPaymentConsts.PaymentMethodCookie, + out var selectedPaymentMethod)) { throw new InvalidOperationException("A payment type must be selected!"); } PaymentRequest = await _paymentRequestAppService.CompleteAsync( // TODO: Use string name - selectedPaymentType, + selectedPaymentMethod, new PaymentRequestCompleteInputDto() { Token = Token }); IsSuccessful = PaymentRequest.State == PaymentRequestState.Completed; @@ -41,7 +41,7 @@ public class PaymentCompletedModel : AbpPageModel if (IsSuccessful) { // Remove cookie so that can be set again when default payment type is set - HttpContext.Response.Cookies.Delete(EShopOnAbpPaymentConsts.PaymentTypeCookie); + HttpContext.Response.Cookies.Delete(EShopOnAbpPaymentConsts.PaymentMethodCookie); return RedirectToPage("OrderReceived", new { orderNo = PaymentRequest.OrderNo }); } diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/payment.js b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/payment.js index e6ea6a3e..50c25f9a 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/payment.js +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/payment.js @@ -9,8 +9,8 @@ form.appendChild(addressInput); let paymentInput = document.createElement('input'); - paymentInput.setAttribute('name', "model.SelectedPaymentType"); - paymentInput.setAttribute('value', document.querySelector(".payment-list .card.is-selected").getAttribute("data-payment-type")); + paymentInput.setAttribute('name', "model.SelectedPaymentMethod"); + paymentInput.setAttribute('value', document.querySelector(".payment-list .card.is-selected").getAttribute("data-payment-method")); paymentInput.setAttribute('type', "hidden"); form.appendChild(paymentInput); }; diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/PaymentMethods/PaymentMethodUiOptions.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/PaymentMethods/PaymentMethodUiOptions.cs new file mode 100644 index 00000000..5cd06d96 --- /dev/null +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/PaymentMethods/PaymentMethodUiOptions.cs @@ -0,0 +1,17 @@ +using JetBrains.Annotations; +using System.Collections.Generic; + +namespace EShopOnAbp.PublicWeb.PaymentMethods; + +public class PaymentMethodUiOptions +{ + [NotNull] + public Dictionary Icons { get; } = new(); + + public string DefaultIcon { get; set; } = "fa-credit-card demo"; + + public void ConfigureIcon(string paymentMethod, string iconCss) + { + Icons[paymentMethod] = iconCss; + } +} diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/ServiceProviders/PaymentMethodProvider.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/ServiceProviders/PaymentMethodProvider.cs new file mode 100644 index 00000000..0c6f8f7a --- /dev/null +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/ServiceProviders/PaymentMethodProvider.cs @@ -0,0 +1,43 @@ +using EShopOnAbp.PaymentService.PaymentMethods; +using EShopOnAbp.PublicWeb.PaymentMethods; +using Microsoft.Extensions.Options; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; + +namespace EShopOnAbp.PublicWeb.ServiceProviders; + +public class PaymentMethodProvider : ITransientDependency +{ + protected IPaymentMethodAppService PaymentMethodAppService { get; } + + private readonly PaymentMethodUiOptions _options; + + public PaymentMethodProvider( + IPaymentMethodAppService paymentMethodAppService, + IOptions options) + { + PaymentMethodAppService = paymentMethodAppService; + _options = options.Value; + } + + public async Task> GetPaymentMethodsAsync() + { + var paymentMethods = await PaymentMethodAppService.GetListAsync(); + + return paymentMethods.Select((pm, i) => new PaymentMethodViewModel + { + Name = pm.Name, + IsDefault = i == 0, + IconCss = _options.Icons.GetOrDefault(pm.Name)?? _options.DefaultIcon + }).ToList(); + } +} + +public class PaymentMethodViewModel +{ + public string Name { get; set; } + public string IconCss { get; set; } + public bool IsDefault { get; set; } +} \ No newline at end of file diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/ServiceProviders/PaymentTypeProvider.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/ServiceProviders/PaymentTypeProvider.cs deleted file mode 100644 index 20f61887..00000000 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/ServiceProviders/PaymentTypeProvider.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Generic; -using Volo.Abp.DependencyInjection; - -namespace EShopOnAbp.PublicWeb.ServiceProviders; - -public class PaymentTypeProvider : ITransientDependency -{ - public List GetPaymentTypes() - { - return new List - { - new() { Type = "demo", Name = "Demo", IconCss = "fa-credit-card demo", IsDefault = true}, - new() { Type = "paypal", Name = "Paypal", IconCss = "fa-cc-paypal paypal"} - }; - } -} - -public class PaymentType -{ - public string Type { get; set; } - public string Name { get; set; } - public string IconCss { get; set; } - public bool IsDefault { get; set; } = false; -} \ No newline at end of file diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/components/payment/payment-widget.css b/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/components/payment/payment-widget.css index 90e9a095..0653b7f9 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/components/payment/payment-widget.css +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/components/payment/payment-widget.css @@ -15,18 +15,19 @@ padding: 2px 16px; } -.is-selected { - border: solid #bfbfe3; +.payment-method-icon { + opacity:0.8; } -.payment-type-header { - font-weight: 500; +.selectable { + cursor: pointer; } -.paypal { - color: #6c84fa; +.is-selected { + border: solid #bfbfe3; + color: #6c84fa !important; } -.demo { - color: darkgray; +.payment-method-header { + font-weight: 500; } \ No newline at end of file diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/components/payment/payment-widget.js b/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/components/payment/payment-widget.js index d02eccb3..04a11e3a 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/components/payment/payment-widget.js +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/components/payment/payment-widget.js @@ -1,7 +1,7 @@ (function () { // Write selected payment type to cookie anyways - const paymentType = $(".payment-list").find(".is-selected").attr('data-payment-type'); - abp.utils.setCookieValue("selected_payment_type", paymentType); + const paymentMethod = $(".payment-list").find(".is-selected").attr('data-payment-method'); + abp.utils.setCookieValue("selected_payment_method", paymentMethod); abp.widgets.PaymentWidget = function ($wrapper) { var widgetManager = $wrapper.data('abp-widget-manager'); @@ -19,8 +19,8 @@ .find('.payment-list .card') .click(el => { const $this = $(el.currentTarget); - const paymentTypeId = $this.attr('data-payment-type'); - abp.utils.setCookieValue("selected_payment_type", paymentTypeId); + const paymentMethod = $this.attr('data-payment-method'); + abp.utils.setCookieValue("selected_payment_method", paymentMethod); $this.parents(".payment-list").find('.card').removeClass("is-selected"); $this.addClass("is-selected"); }); diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderCreateDto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderCreateDto.cs index 8c1149d7..7ef58ed5 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderCreateDto.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderCreateDto.cs @@ -4,7 +4,7 @@ namespace EShopOnAbp.OrderingService.Orders; public class OrderCreateDto { - public int PaymentTypeId { get; set; } + public string PaymentMethod { get; set; } public OrderAddressDto Address { get; set; } = new(); public List Products { get; set; } = new(); } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderDto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderDto.cs index 237484b9..29ca1943 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderDto.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderDto.cs @@ -10,8 +10,7 @@ public class OrderDto : EntityDto public int OrderNo {get;set;} public int OrderStatusId { get; set; } public string OrderStatus { get; set; } - public int PaymentTypeId { get; set; } - public string PaymentType { get; set; } + public string PaymentMethod { get; set; } public BuyerDto Buyer { get; set; } public OrderAddressDto Address { get; set; } = new(); public List Items { get; set; } = new(); diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs index 7530e593..19c0701a 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs @@ -53,7 +53,7 @@ public class OrderAppService : ApplicationService, IOrderAppService var placedOrder = await _orderManager.CreateOrderAsync ( - paymentTypeId: input.PaymentTypeId, + paymentMethod: input.PaymentMethod, buyerId: CurrentUser.GetId(), buyerName: CurrentUser.Name, buyerEmail: CurrentUser.Email, @@ -108,8 +108,7 @@ public class OrderAppService : ApplicationService, IOrderAppService OrderDate = order.OrderDate, OrderStatus = order.OrderStatus.Name, OrderStatusId = order.OrderStatus.Id, - PaymentType = order.PaymentType.Name, - PaymentTypeId = order.PaymentType.Id + PaymentMethod = order.PaymentMethod }; } } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs index 00310165..be008249 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs @@ -3,7 +3,6 @@ public static class OrderingServiceErrorCodes { public const string OrderingStatusNotFound = "Ordering:00001"; - public const string PaymentTypeNotFound = "Ordering:00011"; public const string InvalidUnits = "Ordering:00002"; public const string InvalidDiscount = "Ordering:00003"; public const string InvalidTotalForDiscount = "Ordering:00004"; diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderConstants.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderConstants.cs index 2409e42b..8bb2cb50 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderConstants.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderConstants.cs @@ -2,7 +2,7 @@ public static class OrderConstants { - public const int OrderPaymentTypeNameMaxLength = 128; + public const int OrderPaymentMethodNameMaxLength = 128; public const int OrderStatusNameMaxLength = 256; public const int PaymentStatusMaxLength = 256; diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs index f7d44dcd..9a899c46 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs @@ -8,10 +8,9 @@ namespace EShopOnAbp.OrderingService.Orders; public class Order : AggregateRoot { private int _orderStatusId; - private int _paymentTypeId; public DateTime OrderDate { get; private set; } public int OrderNo { get; private set; } - public PaymentType PaymentType { get; private set; } + public string PaymentMethod { get; private set; } public Guid? PaymentRequestId { get; private set; } public string PaymentStatus { get; private set; } public Buyer Buyer { get; private set; } @@ -23,16 +22,16 @@ public class Order : AggregateRoot { } - internal Order(Guid id, Buyer buyer, Address address, PaymentType paymentType, + internal Order(Guid id, Buyer buyer, Address address, string paymentMethod, Guid? paymentRequestId = null) : base(id) { _orderStatusId = OrderStatus.Placed.Id; - _paymentTypeId = paymentType.Id; OrderDate = DateTime.UtcNow; OrderNo = GenerateOrderNo(id); Buyer = buyer; Address = address; PaymentRequestId = paymentRequestId; + PaymentMethod = paymentMethod; PaymentStatus = "Waiting"; // TODO: magic string OrderItems = new List(); } diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs index 5a0c5ee1..60e2c41d 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs @@ -21,7 +21,7 @@ public class OrderManager : DomainService } public async Task CreateOrderAsync( - int paymentTypeId, + string paymentMethod, Guid buyerId, string buyerName, string buyerEmail, @@ -44,7 +44,7 @@ public class OrderManager : DomainService country: addressCountry, zipcode: addressZipCode, description: addressDescription), - paymentType: PaymentType.From(paymentTypeId) + paymentMethod: paymentMethod ); // Add new order items diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/PaymentType.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/PaymentType.cs deleted file mode 100644 index ec3a0e35..00000000 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/PaymentType.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Volo.Abp; - -namespace EShopOnAbp.OrderingService.Orders; - -public class PaymentType : Enumeration -{ - public static PaymentType Demo = new PaymentType(0, nameof(Demo).ToLowerInvariant()); - public static PaymentType Paypal = new PaymentType(1, nameof(Paypal).ToLowerInvariant()); - - public PaymentType(int id, string name) : base(id, name) - { - } - - public static IEnumerable List() => - new[] {Demo, Paypal}; - - public static PaymentType FromName(string name) - { - var state = List() - .SingleOrDefault(s => String.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase)); - - if (state == null) - { - throw new BusinessException(OrderingServiceErrorCodes.PaymentTypeNotFound) - .WithData("PaymentType", String.Join(",", List().Select(s => s.Name))); - } - - return state; - } - - public static PaymentType From(int id) - { - var state = List().SingleOrDefault(s => s.Id == id); - - if (state == null) - { - throw new BusinessException(OrderingServiceErrorCodes.PaymentTypeNotFound) - .WithData("PaymentType", String.Join(",", List().Select(s => s.Name))); - } - - return state; - } -} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderServiceDataSeedContributor.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderServiceDataSeedContributor.cs index b1d2355a..2ebd3abd 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderServiceDataSeedContributor.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderServiceDataSeedContributor.cs @@ -24,16 +24,6 @@ public class OrderServiceDataSeedContributor : IDataSeedContributor, ITransientD public async Task SeedAsync(DataSeedContext context) { await SeedOrderStatusAsync(); - await SeedPaymentTypesAsync(); - } - - private async Task SeedPaymentTypesAsync() - { - if (!await _dbContext.Set().AnyAsync()) - { - await _dbContext.Set().AddRangeAsync(PaymentType.List()); - await _dbContext.SaveChangesAsync(); - } } private async Task SeedOrderStatusAsync() diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs index 3351c858..cd25eda5 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs @@ -5,103 +5,79 @@ using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.Modeling; -namespace EShopOnAbp.OrderingService.EntityFrameworkCore +namespace EShopOnAbp.OrderingService.EntityFrameworkCore; + +[ConnectionStringName(OrderingServiceDbProperties.ConnectionStringName)] +public class OrderingServiceDbContext : AbpDbContext, IOrderingServiceDbContext { - [ConnectionStringName(OrderingServiceDbProperties.ConnectionStringName)] - public class OrderingServiceDbContext : AbpDbContext, IOrderingServiceDbContext + public virtual DbSet Orders { get; set; } + + public OrderingServiceDbContext(DbContextOptions options) + : base(options) { - public virtual DbSet Orders { get; set; } + } - public OrderingServiceDbContext(DbContextOptions options) - : base(options) - { - } + protected override void OnModelCreating(ModelBuilder builder) + { + base.OnModelCreating(builder); - protected override void OnModelCreating(ModelBuilder builder) - { - base.OnModelCreating(builder); + /* Include modules to your migration db context */ + + builder.ConfigureOrderingService(); + /* Configure your own tables/entities inside here */ - /* Include modules to your migration db context */ - builder.ConfigureOrderingService(); - /* Configure your own tables/entities inside here */ - + builder.Entity(b => + { + b.ToTable(OrderingServiceDbProperties.DbTablePrefix + "Orders", OrderingServiceDbProperties.DbSchema); + b.ConfigureByConvention(); //auto configure for the base class props - builder.Entity(b => - { - b.ToTable(OrderingServiceDbProperties.DbTablePrefix + "Orders", OrderingServiceDbProperties.DbSchema); - b.ConfigureByConvention(); //auto configure for the base class props - b.Property(q => q.PaymentStatus).HasMaxLength(OrderConstants.PaymentStatusMaxLength); - - b.OwnsOne(o => o.Address, a => { a.WithOwner(); }); - b.OwnsOne(o => o.Buyer, a => { a.WithOwner(); }); - - b.Property("_orderStatusId").UsePropertyAccessMode(PropertyAccessMode.Field) - .HasColumnName("OrderStatusId") - .IsRequired(); - - b.Property("_paymentTypeId").UsePropertyAccessMode(PropertyAccessMode.Field) - .HasColumnName("PaymentTypeId") - .IsRequired(); - - b.HasOne(q => q.OrderStatus).WithMany().HasForeignKey("_orderStatusId"); - b.HasOne(q => q.PaymentType).WithMany().HasForeignKey("_paymentTypeId"); - - b.Navigation(q => q.OrderItems).UsePropertyAccessMode(PropertyAccessMode.Property); - }); - - builder.Entity(b => - { - b.ToTable(OrderingServiceDbProperties.DbTablePrefix + "OrderItems", - OrderingServiceDbProperties.DbSchema); - b.ConfigureByConvention(); //auto configure for the base class props + + b.OwnsOne(o => o.Address, a => { a.WithOwner(); }); + b.OwnsOne(o => o.Buyer, a => { a.WithOwner(); }); + + b.Property("_orderStatusId").UsePropertyAccessMode(PropertyAccessMode.Field) + .HasColumnName("OrderStatusId") + .IsRequired(); + + b.HasOne(q => q.OrderStatus).WithMany().HasForeignKey("_orderStatusId"); + + b.Navigation(q => q.OrderItems).UsePropertyAccessMode(PropertyAccessMode.Property); + }); + + builder.Entity(b => + { + b.ToTable(OrderingServiceDbProperties.DbTablePrefix + "OrderItems", + OrderingServiceDbProperties.DbSchema); + b.ConfigureByConvention(); //auto configure for the base class props b.Property("OrderId").IsRequired(); - b.Property(q => q.ProductId).IsRequired(); - b.Property(q => q.ProductCode).IsRequired(); - b.Property(q => q.ProductName).IsRequired(); - b.Property(q => q.Discount).IsRequired(); - b.Property(q => q.UnitPrice).IsRequired(); - b.Property(q => q.Units).IsRequired(); - b.Property(q => q.PictureUrl).IsRequired(false); - }); - - builder.Entity(b => - { - b.ToTable(OrderingServiceDbProperties.DbTablePrefix + "OrderStatus", - OrderingServiceDbProperties.DbSchema); - b.ConfigureByConvention(); //auto configure for the base class props + b.Property(q => q.ProductId).IsRequired(); + b.Property(q => q.ProductCode).IsRequired(); + b.Property(q => q.ProductName).IsRequired(); + b.Property(q => q.Discount).IsRequired(); + b.Property(q => q.UnitPrice).IsRequired(); + b.Property(q => q.Units).IsRequired(); + b.Property(q => q.PictureUrl).IsRequired(false); + }); - b.HasKey(q => q.Id); - - b.Property(q => q.Id) - .HasDefaultValue(1) - .ValueGeneratedNever() - .IsRequired(); - - b.Property(o => o.Name) - .HasMaxLength(OrderConstants.OrderStatusNameMaxLength) - .IsRequired(); - }); - - builder.Entity(b => - { - b.ToTable(OrderingServiceDbProperties.DbTablePrefix + "PaymentTypes", - OrderingServiceDbProperties.DbSchema); - b.ConfigureByConvention(); //auto configure for the base class props + builder.Entity(b => + { + b.ToTable(OrderingServiceDbProperties.DbTablePrefix + "OrderStatus", + OrderingServiceDbProperties.DbSchema); + b.ConfigureByConvention(); //auto configure for the base class props b.HasKey(q => q.Id); - - b.Property(q => q.Id) - .HasDefaultValue(1) - .ValueGeneratedNever() - .IsRequired(); - - b.Property(o => o.Name) - .HasMaxLength(OrderConstants.OrderPaymentTypeNameMaxLength) - .IsRequired(); - }); - } + + b.Property(q => q.Id) + .HasDefaultValue(1) + .ValueGeneratedNever() + .IsRequired(); + + b.Property(o => o.Name) + .HasMaxLength(OrderConstants.OrderStatusNameMaxLength) + .IsRequired(); + }); } -} \ No newline at end of file +} diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220118084223_Removed_PaymentType.Designer.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220118084223_Removed_PaymentType.Designer.cs new file mode 100644 index 00000000..70bd4795 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220118084223_Removed_PaymentType.Designer.cs @@ -0,0 +1,206 @@ +// +using System; +using EShopOnAbp.OrderingService.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using Volo.Abp.EntityFrameworkCore; + +#nullable disable + +namespace EShopOnAbp.OrderingService.Migrations +{ + [DbContext(typeof(OrderingServiceDbContext))] + [Migration("20220118084223_Removed_PaymentType")] + partial class Removed_PaymentType + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.PostgreSql) + .HasAnnotation("ProductVersion", "6.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.Order", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasMaxLength(40) + .HasColumnType("character varying(40)") + .HasColumnName("ConcurrencyStamp"); + + b.Property("ExtraProperties") + .HasColumnType("text") + .HasColumnName("ExtraProperties"); + + b.Property("OrderDate") + .HasColumnType("timestamp with time zone"); + + b.Property("OrderNo") + .HasColumnType("integer"); + + b.Property("PaymentMethod") + .HasColumnType("text"); + + b.Property("PaymentRequestId") + .HasColumnType("uuid"); + + b.Property("PaymentStatus") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("_orderStatusId") + .HasColumnType("integer") + .HasColumnName("OrderStatusId"); + + b.HasKey("Id"); + + b.HasIndex("_orderStatusId"); + + b.ToTable("Orders", (string)null); + }); + + modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.OrderItem", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("Discount") + .HasColumnType("numeric"); + + b.Property("OrderId") + .HasColumnType("uuid"); + + b.Property("PictureUrl") + .HasColumnType("text"); + + b.Property("ProductCode") + .IsRequired() + .HasColumnType("text"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("ProductName") + .IsRequired() + .HasColumnType("text"); + + b.Property("UnitPrice") + .HasColumnType("numeric"); + + b.Property("Units") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.ToTable("OrderItems", (string)null); + }); + + modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.OrderStatus", b => + { + b.Property("Id") + .HasColumnType("integer") + .HasDefaultValue(1); + + b.Property("Name") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.ToTable("OrderStatus", (string)null); + }); + + modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.Order", b => + { + b.HasOne("EShopOnAbp.OrderingService.Orders.OrderStatus", "OrderStatus") + .WithMany() + .HasForeignKey("_orderStatusId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsOne("EShopOnAbp.OrderingService.Orders.Address", "Address", b1 => + { + b1.Property("OrderId") + .HasColumnType("uuid"); + + b1.Property("City") + .HasColumnType("text"); + + b1.Property("Country") + .HasColumnType("text"); + + b1.Property("Description") + .HasColumnType("text"); + + b1.Property("Street") + .HasColumnType("text"); + + b1.Property("ZipCode") + .HasColumnType("text"); + + b1.HasKey("OrderId"); + + b1.ToTable("Orders"); + + b1.WithOwner() + .HasForeignKey("OrderId"); + }); + + b.OwnsOne("EShopOnAbp.OrderingService.Orders.Buyer", "Buyer", b1 => + { + b1.Property("OrderId") + .HasColumnType("uuid"); + + b1.Property("Email") + .HasColumnType("text"); + + b1.Property("Id") + .HasColumnType("uuid"); + + b1.Property("Name") + .HasColumnType("text"); + + b1.HasKey("OrderId"); + + b1.ToTable("Orders"); + + b1.WithOwner() + .HasForeignKey("OrderId"); + }); + + b.Navigation("Address"); + + b.Navigation("Buyer"); + + b.Navigation("OrderStatus"); + }); + + modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.OrderItem", b => + { + b.HasOne("EShopOnAbp.OrderingService.Orders.Order", null) + .WithMany("OrderItems") + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.Order", b => + { + b.Navigation("OrderItems"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220118084223_Removed_PaymentType.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220118084223_Removed_PaymentType.cs new file mode 100644 index 00000000..88ed3390 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220118084223_Removed_PaymentType.cs @@ -0,0 +1,72 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EShopOnAbp.OrderingService.Migrations +{ + public partial class Removed_PaymentType : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_PaymentTypes_PaymentTypeId", + table: "Orders"); + + migrationBuilder.DropTable( + name: "PaymentTypes"); + + migrationBuilder.DropIndex( + name: "IX_Orders_PaymentTypeId", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "PaymentTypeId", + table: "Orders"); + + migrationBuilder.AddColumn( + name: "PaymentMethod", + table: "Orders", + type: "text", + nullable: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "PaymentMethod", + table: "Orders"); + + migrationBuilder.AddColumn( + name: "PaymentTypeId", + table: "Orders", + type: "integer", + nullable: false, + defaultValue: 0); + + migrationBuilder.CreateTable( + name: "PaymentTypes", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false, defaultValue: 1), + Name = table.Column(type: "character varying(128)", maxLength: 128, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PaymentTypes", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_PaymentTypeId", + table: "Orders", + column: "PaymentTypeId"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_PaymentTypes_PaymentTypeId", + table: "Orders", + column: "PaymentTypeId", + principalTable: "PaymentTypes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs index 550b95bc..151f2ee8 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs @@ -24,22 +24,6 @@ namespace EShopOnAbp.OrderingService.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - modelBuilder.Entity("EShopOnAbp.OrderingService.Buyers.PaymentType", b => - { - b.Property("Id") - .HasColumnType("integer") - .HasDefaultValue(1); - - b.Property("Name") - .IsRequired() - .HasMaxLength(128) - .HasColumnType("character varying(128)"); - - b.HasKey("Id"); - - b.ToTable("PaymentTypes", (string)null); - }); - modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.Order", b => { b.Property("Id") @@ -61,6 +45,9 @@ namespace EShopOnAbp.OrderingService.Migrations b.Property("OrderNo") .HasColumnType("integer"); + b.Property("PaymentMethod") + .HasColumnType("text"); + b.Property("PaymentRequestId") .HasColumnType("uuid"); @@ -72,16 +59,10 @@ namespace EShopOnAbp.OrderingService.Migrations .HasColumnType("integer") .HasColumnName("OrderStatusId"); - b.Property("_paymentTypeId") - .HasColumnType("integer") - .HasColumnName("PaymentTypeId"); - b.HasKey("Id"); b.HasIndex("_orderStatusId"); - b.HasIndex("_paymentTypeId"); - b.ToTable("Orders", (string)null); }); @@ -147,12 +128,6 @@ namespace EShopOnAbp.OrderingService.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("EShopOnAbp.OrderingService.Buyers.PaymentType", "PaymentType") - .WithMany() - .HasForeignKey("_paymentTypeId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - b.OwnsOne("EShopOnAbp.OrderingService.Orders.Address", "Address", b1 => { b1.Property("OrderId") @@ -208,8 +183,6 @@ namespace EShopOnAbp.OrderingService.Migrations b.Navigation("Buyer"); b.Navigation("OrderStatus"); - - b.Navigation("PaymentType"); }); modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.OrderItem", b => diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderQueryableExtensions.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderQueryableExtensions.cs index da4c615d..493554d1 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderQueryableExtensions.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderQueryableExtensions.cs @@ -10,7 +10,6 @@ public static class EfCoreOrderQueryableExtensions ? queryable : queryable .Include(q => q.OrderStatus) - .Include(q => q.PaymentType) .Include(q => q.Address) .Include(q => q.Buyer) .Include(q => q.OrderItems); diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs index 32414453..45ef6948 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs @@ -25,7 +25,6 @@ public class EfCoreOrderRepository : EfCoreRepository o.OrderStatus, GetCancellationToken(cancellationToken)); - await EnsurePropertyLoadedAsync(newEntity, o => o.PaymentType, GetCancellationToken(cancellationToken)); return newEntity; } diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/OrderEfCoreQueryableExtensions.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/OrderEfCoreQueryableExtensions.cs index 7b194839..cecca583 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/OrderEfCoreQueryableExtensions.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/OrderEfCoreQueryableExtensions.cs @@ -16,7 +16,6 @@ public static class OrderEfCoreQueryableExtensions .Include(x => x.Address) .Include(x => x.Buyer) .Include(x => x.OrderItems) - .Include(x => x.PaymentType) .Include(x => x.OrderStatus); } } \ No newline at end of file diff --git a/services/ordering/test/EShopOnAbp.OrderingService.Application.Tests/Orders/OrderApplication_Tests.cs b/services/ordering/test/EShopOnAbp.OrderingService.Application.Tests/Orders/OrderApplication_Tests.cs index 64d10435..79d35857 100644 --- a/services/ordering/test/EShopOnAbp.OrderingService.Application.Tests/Orders/OrderApplication_Tests.cs +++ b/services/ordering/test/EShopOnAbp.OrderingService.Application.Tests/Orders/OrderApplication_Tests.cs @@ -45,7 +45,7 @@ public class OrderApplication_Tests:OrderingServiceApplicationTestBase var placedOrder = await _orderAppService.CreateAsync(new OrderCreateDto() { - PaymentTypeId = 1, + PaymentMethod = 1, Address = new OrderAddressDto() { City = "Test City", Country = "Test Country", Description = "No Description", Street = "Test Street", diff --git a/services/ordering/test/EShopOnAbp.OrderingService.Domain.Tests/Orders/OrderManager_Tests.cs b/services/ordering/test/EShopOnAbp.OrderingService.Domain.Tests/Orders/OrderManager_Tests.cs index 7a37be0e..23d95f28 100644 --- a/services/ordering/test/EShopOnAbp.OrderingService.Domain.Tests/Orders/OrderManager_Tests.cs +++ b/services/ordering/test/EShopOnAbp.OrderingService.Domain.Tests/Orders/OrderManager_Tests.cs @@ -18,13 +18,14 @@ public class OrderManagerUnitTests : OrderingServiceDomainTestBase [Fact] public async Task Should_CreateOrderAsync() { + var paymentMethod = "Cash on Delivery"; var orderItems = new List<(Guid productId, string productName, string productCode, decimal unitPrice, decimal discount, string pictureUrl, int units)>(); orderItems.Add((Guid.NewGuid(), "Test product", "Code:001", 15, 0, "", 1)); var createdOrder = await _orderManager.CreateOrderAsync( - 1, + paymentMethod, Guid.Parse("11CA0F6D-208E-441A-9F9B-3611C96E4383"), "gterdem", "gterdem@volosoft.com", @@ -36,6 +37,6 @@ public class OrderManagerUnitTests : OrderingServiceDomainTestBase createdOrder.ShouldNotBeNull(); createdOrder.OrderStatus.ShouldBe(OrderStatus.Placed); - createdOrder.PaymentType.ShouldBe(PaymentType.Paypal); + createdOrder.PaymentMethod.ShouldBe(paymentMethod); } } \ No newline at end of file diff --git a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Client/ClientProxies/PaymentMethodClientProxy.Generated.cs b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Client/ClientProxies/PaymentMethodClientProxy.Generated.cs new file mode 100644 index 00000000..10fb88a0 --- /dev/null +++ b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Client/ClientProxies/PaymentMethodClientProxy.Generated.cs @@ -0,0 +1,23 @@ +// This file is automatically generated by ABP framework to use MVC Controllers from CSharp +using System; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Http.Client; +using Volo.Abp.Http.Modeling; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Http.Client.ClientProxying; +using EShopOnAbp.PaymentService.PaymentMethods; +using System.Collections.Generic; + +// ReSharper disable once CheckNamespace +namespace EShopOnAbp.PaymentService.Controllers.ClientProxies; + +[Dependency(ReplaceServices = true)] +[ExposeServices(typeof(IPaymentMethodAppService), typeof(PaymentMethodClientProxy))] +public partial class PaymentMethodClientProxy : ClientProxyBase, IPaymentMethodAppService +{ + public virtual async Task> GetListAsync() + { + return await RequestAsync>(nameof(GetListAsync)); + } +} diff --git a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Client/ClientProxies/PaymentMethodClientProxy.cs b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Client/ClientProxies/PaymentMethodClientProxy.cs new file mode 100644 index 00000000..fe71a7b9 --- /dev/null +++ b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Client/ClientProxies/PaymentMethodClientProxy.cs @@ -0,0 +1,7 @@ +// This file is part of PaymentMethodClientProxy, you can customize it here +// ReSharper disable once CheckNamespace +namespace EShopOnAbp.PaymentService.Controllers.ClientProxies; + +public partial class PaymentMethodClientProxy +{ +} diff --git a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Client/ClientProxies/PaymentRequestClientProxy.Generated.cs b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Client/ClientProxies/PaymentRequestClientProxy.Generated.cs index fd8725af..24e7edc2 100644 --- a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Client/ClientProxies/PaymentRequestClientProxy.Generated.cs +++ b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Client/ClientProxies/PaymentRequestClientProxy.Generated.cs @@ -15,11 +15,11 @@ namespace EShopOnAbp.PaymentService.Controllers.ClientProxies; [ExposeServices(typeof(IPaymentRequestAppService), typeof(PaymentRequestClientProxy))] public partial class PaymentRequestClientProxy : ClientProxyBase, IPaymentRequestAppService { - public virtual async Task CompleteAsync(string paymentType, PaymentRequestCompleteInputDto input) + public virtual async Task CompleteAsync(string paymentMethod, PaymentRequestCompleteInputDto input) { return await RequestAsync(nameof(CompleteAsync), new ClientProxyRequestTypeValue { - { typeof(string), paymentType }, + { typeof(string), paymentMethod }, { typeof(PaymentRequestCompleteInputDto), input } }); } @@ -32,20 +32,20 @@ public partial class PaymentRequestClientProxy : ClientProxyBase HandleWebhookAsync(string paymentType, string payload) + public virtual async Task HandleWebhookAsync(string paymentMethod, string payload) { return await RequestAsync(nameof(HandleWebhookAsync), new ClientProxyRequestTypeValue { - { typeof(string), paymentType }, + { typeof(string), paymentMethod }, { typeof(string), payload } }); } - public virtual async Task StartAsync(string paymentType, PaymentRequestStartDto input) + public virtual async Task StartAsync(string paymentMethod, PaymentRequestStartDto input) { return await RequestAsync(nameof(StartAsync), new ClientProxyRequestTypeValue { - { typeof(string), paymentType }, + { typeof(string), paymentMethod }, { typeof(PaymentRequestStartDto), input } }); } diff --git a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Client/ClientProxies/payment-generate-proxy.json b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Client/ClientProxies/payment-generate-proxy.json index 43db9ece..70f348f7 100644 --- a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Client/ClientProxies/payment-generate-proxy.json +++ b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Client/ClientProxies/payment-generate-proxy.json @@ -4,6 +4,33 @@ "rootPath": "payment", "remoteServiceName": "PaymentService", "controllers": { + "EShopOnAbp.PaymentService.Controllers.PaymentMethodController": { + "controllerName": "PaymentMethod", + "controllerGroupName": "PaymentMethod", + "type": "EShopOnAbp.PaymentService.Controllers.PaymentMethodController", + "interfaces": [ + { + "type": "EShopOnAbp.PaymentService.PaymentMethods.IPaymentMethodAppService" + } + ], + "actions": { + "GetListAsync": { + "uniqueName": "GetListAsync", + "name": "GetListAsync", + "httpMethod": "GET", + "url": "api/payment/methods", + "supportedVersions": [], + "parametersOnMethod": [], + "parameters": [], + "returnValue": { + "type": "System.Collections.Generic.List", + "typeSimple": "[EShopOnAbp.PaymentService.PaymentMethods.PaymentMethodDto]" + }, + "allowAnonymous": null, + "implementFrom": "EShopOnAbp.PaymentService.PaymentMethods.IPaymentMethodAppService" + } + } + }, "EShopOnAbp.PaymentService.Controllers.PaymentRequestController": { "controllerName": "PaymentRequest", "controllerGroupName": "PaymentRequest", @@ -14,15 +41,15 @@ } ], "actions": { - "CompleteAsyncByPaymentTypeAndInput": { - "uniqueName": "CompleteAsyncByPaymentTypeAndInput", + "CompleteAsyncByPaymentMethodAndInput": { + "uniqueName": "CompleteAsyncByPaymentMethodAndInput", "name": "CompleteAsync", "httpMethod": "POST", - "url": "api/payment/requests/{paymentType}/complete", + "url": "api/payment/requests/{paymentMethod}/complete", "supportedVersions": [], "parametersOnMethod": [ { - "name": "paymentType", + "name": "paymentMethod", "typeAsString": "System.String, System.Private.CoreLib", "type": "System.String", "typeSimple": "string", @@ -40,8 +67,8 @@ ], "parameters": [ { - "nameOnMethod": "paymentType", - "name": "paymentType", + "nameOnMethod": "paymentMethod", + "name": "paymentMethod", "jsonName": null, "type": "System.String", "typeSimple": "string", @@ -108,15 +135,15 @@ "allowAnonymous": null, "implementFrom": "EShopOnAbp.PaymentService.PaymentRequests.IPaymentRequestAppService" }, - "HandleWebhookAsyncByPaymentTypeAndPayload": { - "uniqueName": "HandleWebhookAsyncByPaymentTypeAndPayload", + "HandleWebhookAsyncByPaymentMethodAndPayload": { + "uniqueName": "HandleWebhookAsyncByPaymentMethodAndPayload", "name": "HandleWebhookAsync", "httpMethod": "POST", - "url": "api/payment/requests/{paymentType}/webhook", + "url": "api/payment/requests/{paymentMethod}/webhook", "supportedVersions": [], "parametersOnMethod": [ { - "name": "paymentType", + "name": "paymentMethod", "typeAsString": "System.String, System.Private.CoreLib", "type": "System.String", "typeSimple": "string", @@ -134,8 +161,8 @@ ], "parameters": [ { - "nameOnMethod": "paymentType", - "name": "paymentType", + "nameOnMethod": "paymentMethod", + "name": "paymentMethod", "jsonName": null, "type": "System.String", "typeSimple": "string", @@ -165,15 +192,15 @@ "allowAnonymous": null, "implementFrom": "EShopOnAbp.PaymentService.PaymentRequests.IPaymentRequestAppService" }, - "StartAsyncByPaymentTypeAndInput": { - "uniqueName": "StartAsyncByPaymentTypeAndInput", + "StartAsyncByPaymentMethodAndInput": { + "uniqueName": "StartAsyncByPaymentMethodAndInput", "name": "StartAsync", "httpMethod": "POST", - "url": "api/payment/requests/{paymentType}/start", + "url": "api/payment/requests/{paymentMethod}/start", "supportedVersions": [], "parametersOnMethod": [ { - "name": "paymentType", + "name": "paymentMethod", "typeAsString": "System.String, System.Private.CoreLib", "type": "System.String", "typeSimple": "string", @@ -191,8 +218,8 @@ ], "parameters": [ { - "nameOnMethod": "paymentType", - "name": "paymentType", + "nameOnMethod": "paymentMethod", + "name": "paymentMethod", "jsonName": null, "type": "System.String", "typeSimple": "string", diff --git a/services/payment/src/EShopOnAbp.PaymentService.HttpApi/Controllers/PaymentMethodController.cs b/services/payment/src/EShopOnAbp.PaymentService.HttpApi/Controllers/PaymentMethodController.cs index 9a805315..c95f9f50 100644 --- a/services/payment/src/EShopOnAbp.PaymentService.HttpApi/Controllers/PaymentMethodController.cs +++ b/services/payment/src/EShopOnAbp.PaymentService.HttpApi/Controllers/PaymentMethodController.cs @@ -18,6 +18,7 @@ public class PaymentMethodController : PaymentServiceController, IPaymentMethodA PaymentMethodAppService = paymentMethodAppService; } + [HttpGet] public Task> GetListAsync() { return PaymentMethodAppService.GetListAsync();