From 9ad705384c877658303044d8eae6b31421f53580 Mon Sep 17 00:00:00 2001 From: support Date: Wed, 18 Nov 2026 17:25:25 +0100 Subject: [PATCH 1/2] Hide abandoned checkouts in the payment transaction list --- .../GetPaymentTransactionQueryHandler.cs | 3 ++ .../Payments/PaymentTransactionService.cs | 7 ++- .../Payments/IPaymentTransactionService.cs | 4 +- .../Orders/GetPaymentTransactionQuery.cs | 3 ++ .../GetPaymentTransactionQueryHandlerTests.cs | 44 ++++++++++++++++++ .../BasePaymentTransactionControllerTests.cs | 19 +++++++- .../BasePaymentTransactionController.cs | 3 +- .../Orders/PaymentTransactionListModel.cs | 3 ++ .../PaymentTransaction/List.cshtml | 4 +- .../App_Data/Resources/DefaultLanguage.xml | Bin 1808490 -> 1809246 bytes .../App_Data/Resources/Upgrade/en_250.xml | 6 +++ 11 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 src/Tests/Grand.Business.Checkout.Tests/Queries/Handlers/Orders/GetPaymentTransactionQueryHandlerTests.cs diff --git a/src/Business/Grand.Business.Checkout/Queries/Handlers/Orders/GetPaymentTransactionQueryHandler.cs b/src/Business/Grand.Business.Checkout/Queries/Handlers/Orders/GetPaymentTransactionQueryHandler.cs index 4753a7632..16ea065e1 100644 --- a/src/Business/Grand.Business.Checkout/Queries/Handlers/Orders/GetPaymentTransactionQueryHandler.cs +++ b/src/Business/Grand.Business.Checkout/Queries/Handlers/Orders/GetPaymentTransactionQueryHandler.cs @@ -40,6 +40,9 @@ public async Task> Handle(GetPaymentTransactionQu if (request.CreatedToUtc.HasValue) query = query.Where(rr => request.CreatedToUtc.Value >= rr.CreatedOnUtc); + if (!request.IncludeTemp) + query = query.Where(rr => !rr.Temp); + query = query.OrderByDescending(rr => rr.CreatedOnUtc); return await _paymentTransactionRepository.PagedAsync(query, request.PageIndex, request.PageSize, cancellationToken); diff --git a/src/Business/Grand.Business.Checkout/Services/Payments/PaymentTransactionService.cs b/src/Business/Grand.Business.Checkout/Services/Payments/PaymentTransactionService.cs index eefc3b8b8..b2746dc6e 100644 --- a/src/Business/Grand.Business.Checkout/Services/Payments/PaymentTransactionService.cs +++ b/src/Business/Grand.Business.Checkout/Services/Payments/PaymentTransactionService.cs @@ -127,6 +127,7 @@ public virtual async Task> GetByAuthorizationTransacti /// Page size /// Created date from (UTC); null to load all records /// Created date to (UTC); null to load all records + /// False leaves out transactions of a checkout that never became an order /// Page list payment transaction public virtual async Task> SearchPaymentTransactions( Guid? orderGuid = null, @@ -135,7 +136,8 @@ public virtual async Task> SearchPaymentTransacti TransactionStatus? ts = null, int pageIndex = 0, int pageSize = int.MaxValue, DateTime? createdFromUtc = null, - DateTime? createdToUtc = null) + DateTime? createdToUtc = null, + bool includeTemp = true) { var model = new GetPaymentTransactionQuery { CreatedFromUtc = createdFromUtc, @@ -145,7 +147,8 @@ public virtual async Task> SearchPaymentTransacti OrderGuid = orderGuid, CustomerEmail = customerEmail, StoreId = storeId, - Ts = ts + Ts = ts, + IncludeTemp = includeTemp }; return await _mediator.Send(model); diff --git a/src/Business/Grand.Business.Core/Interfaces/Checkout/Payments/IPaymentTransactionService.cs b/src/Business/Grand.Business.Core/Interfaces/Checkout/Payments/IPaymentTransactionService.cs index 79aaa3f83..d96ef3d1b 100644 --- a/src/Business/Grand.Business.Core/Interfaces/Checkout/Payments/IPaymentTransactionService.cs +++ b/src/Business/Grand.Business.Core/Interfaces/Checkout/Payments/IPaymentTransactionService.cs @@ -64,6 +64,7 @@ Task> GetByAuthorizationTransactionIdAndPaymentMethod( /// Page size /// Created date from (UTC); null to load all records /// Created date to (UTC); null to load all records + /// False leaves out transactions of a checkout that never became an order /// Page list payment transaction Task> SearchPaymentTransactions( Guid? orderGuid = null, @@ -72,7 +73,8 @@ Task> SearchPaymentTransactions( TransactionStatus? ts = null, int pageIndex = 0, int pageSize = int.MaxValue, DateTime? createdFromUtc = null, - DateTime? createdToUtc = null); + DateTime? createdToUtc = null, + bool includeTemp = true); /// /// Set payment error for transaction diff --git a/src/Business/Grand.Business.Core/Queries/Checkout/Orders/GetPaymentTransactionQuery.cs b/src/Business/Grand.Business.Core/Queries/Checkout/Orders/GetPaymentTransactionQuery.cs index adeab78f8..562e0fd50 100644 --- a/src/Business/Grand.Business.Core/Queries/Checkout/Orders/GetPaymentTransactionQuery.cs +++ b/src/Business/Grand.Business.Core/Queries/Checkout/Orders/GetPaymentTransactionQuery.cs @@ -14,4 +14,7 @@ public class GetPaymentTransactionQuery : IRequestFalse leaves out transactions of a checkout that never became an order. + public bool IncludeTemp { get; set; } = true; } \ No newline at end of file diff --git a/src/Tests/Grand.Business.Checkout.Tests/Queries/Handlers/Orders/GetPaymentTransactionQueryHandlerTests.cs b/src/Tests/Grand.Business.Checkout.Tests/Queries/Handlers/Orders/GetPaymentTransactionQueryHandlerTests.cs new file mode 100644 index 000000000..bb7cd494b --- /dev/null +++ b/src/Tests/Grand.Business.Checkout.Tests/Queries/Handlers/Orders/GetPaymentTransactionQueryHandlerTests.cs @@ -0,0 +1,44 @@ +using Grand.Business.Checkout.Queries.Handlers.Orders; +using Grand.Business.Core.Queries.Checkout.Orders; +using Grand.Data.Tests.MongoDb; +using Grand.Domain.Payments; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Grand.Business.Checkout.Tests.Queries.Handlers.Orders; + +[TestClass] +public class GetPaymentTransactionQueryHandlerTests +{ + private GetPaymentTransactionQueryHandler _handler; + private MongoDBRepositoryTest _repository; + + [TestInitialize] + public void Init() + { + _repository = new MongoDBRepositoryTest(); + _handler = new GetPaymentTransactionQueryHandler(_repository); + } + + [TestMethod] + public async Task Handle_WithoutTemp_LeavesOutAbandonedCheckouts() + { + await _repository.Collection.InsertOneAsync(new PaymentTransaction { OrderCode = "ORDER", Temp = false }); + await _repository.Collection.InsertOneAsync(new PaymentTransaction { OrderCode = "ABANDONED", Temp = true }); + + var result = await _handler.Handle(new GetPaymentTransactionQuery { IncludeTemp = false }, CancellationToken.None); + + Assert.AreEqual(1, result.Count); + Assert.AreEqual("ORDER", result[0].OrderCode); + } + + [TestMethod] + public async Task Handle_ByDefault_IncludesAbandonedCheckouts() + { + await _repository.Collection.InsertOneAsync(new PaymentTransaction { OrderCode = "ORDER", Temp = false }); + await _repository.Collection.InsertOneAsync(new PaymentTransaction { OrderCode = "ABANDONED", Temp = true }); + + var result = await _handler.Handle(new GetPaymentTransactionQuery(), CancellationToken.None); + + Assert.AreEqual(2, result.Count); + } +} diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/BasePaymentTransactionControllerTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/BasePaymentTransactionControllerTests.cs index f717e6c20..77e7e9b34 100644 --- a/src/Tests/Grand.Web.Admin.Tests/Controllers/BasePaymentTransactionControllerTests.cs +++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/BasePaymentTransactionControllerTests.cs @@ -103,7 +103,7 @@ public async Task List_Post_AdminScope_DoesNotForceStoreId() { _scopeMock.Setup(s => s.DefaultStoreId).Returns((string)null); _paymentTransactionServiceMock - .Setup(s => s.SearchPaymentTransactions(null, null, null, null, 0, int.MaxValue, null, null)) + .Setup(s => s.SearchPaymentTransactions(null, null, null, null, 0, int.MaxValue, null, null, false)) .ReturnsAsync(new PagedList(new List(), 0, 10)); var model = new PaymentTransactionListModel(); @@ -112,12 +112,27 @@ public async Task List_Post_AdminScope_DoesNotForceStoreId() Assert.IsNull(model.StoreId); } + [TestMethod] + public async Task List_Post_LeavesOutAbandonedUnlessAsked() + { + _paymentTransactionServiceMock + .Setup(s => s.SearchPaymentTransactions(null, null, null, null, 0, int.MaxValue, null, null, It.IsAny())) + .ReturnsAsync(new PagedList(new List(), 0, 10)); + var command = new DataSourceRequest { Page = 1, PageSize = int.MaxValue }; + + await _controller.List(command, new PaymentTransactionListModel()); + await _controller.List(command, new PaymentTransactionListModel { ShowAbandoned = true }); + + _paymentTransactionServiceMock.Verify(s => s.SearchPaymentTransactions(null, null, null, null, 0, int.MaxValue, null, null, false), Times.Once); + _paymentTransactionServiceMock.Verify(s => s.SearchPaymentTransactions(null, null, null, null, 0, int.MaxValue, null, null, true), Times.Once); + } + [TestMethod] public async Task List_Post_StoreScope_ForcesStoreId() { _scopeMock.Setup(s => s.DefaultStoreId).Returns("store-1"); _paymentTransactionServiceMock - .Setup(s => s.SearchPaymentTransactions(null, "store-1", It.IsAny(), null, 0, int.MaxValue, null, null)) + .Setup(s => s.SearchPaymentTransactions(null, "store-1", It.IsAny(), null, 0, int.MaxValue, null, null, false)) .ReturnsAsync(new PagedList(new List(), 0, 10)); var model = new PaymentTransactionListModel { StoreId = "some-other-store" }; diff --git a/src/Web/Grand.Web.AdminShared/Controllers/BasePaymentTransactionController.cs b/src/Web/Grand.Web.AdminShared/Controllers/BasePaymentTransactionController.cs index c82b2bb8e..9da48ab75 100644 --- a/src/Web/Grand.Web.AdminShared/Controllers/BasePaymentTransactionController.cs +++ b/src/Web/Grand.Web.AdminShared/Controllers/BasePaymentTransactionController.cs @@ -111,7 +111,8 @@ public async Task List(DataSourceRequest command, PaymentTransact storeId: model.StoreId, orderGuid: orderGuid, pageIndex: command.Page - 1, - pageSize: command.PageSize); + pageSize: command.PageSize, + includeTemp: model.ShowAbandoned); var dataModel = new List(); diff --git a/src/Web/Grand.Web.AdminShared/Models/Orders/PaymentTransactionListModel.cs b/src/Web/Grand.Web.AdminShared/Models/Orders/PaymentTransactionListModel.cs index 3d27a0e9a..d82584bc3 100644 --- a/src/Web/Grand.Web.AdminShared/Models/Orders/PaymentTransactionListModel.cs +++ b/src/Web/Grand.Web.AdminShared/Models/Orders/PaymentTransactionListModel.cs @@ -24,6 +24,9 @@ public class PaymentTransactionListModel : BaseModel [UIHint("DateNullable")] public DateTime? EndDate { get; set; } + [GrandResourceDisplayName("Admin.Orders.PaymentTransaction.List.ShowAbandoned")] + public bool ShowAbandoned { get; set; } + public string StoreId { get; set; } public IList PaymentTransactionStatus { get; set; } = new List(); diff --git a/src/Web/Grand.Web.AdminShared/Views/AdminShared/PaymentTransaction/List.cshtml b/src/Web/Grand.Web.AdminShared/Views/AdminShared/PaymentTransaction/List.cshtml index c3e0e2947..32686f78c 100644 --- a/src/Web/Grand.Web.AdminShared/Views/AdminShared/PaymentTransaction/List.cshtml +++ b/src/Web/Grand.Web.AdminShared/Views/AdminShared/PaymentTransaction/List.cshtml @@ -28,6 +28,7 @@ + @@ -77,7 +78,8 @@ SearchCustomerEmail: $('#@Html.IdFor(model => model.SearchCustomerEmail)').val(), OrderNumber: $('#@Html.IdFor(model => model.OrderNumber)').val(), StartDate: $('#@Html.IdFor(model => model.StartDate)').val(), - EndDate: $('#@Html.IdFor(model => model.EndDate)').val() + EndDate: $('#@Html.IdFor(model => model.EndDate)').val(), + ShowAbandoned: $('#@Html.IdFor(model => model.ShowAbandoned)').is(':checked') }; addAntiForgeryToken(data); return data; diff --git a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml index d1a18ed187984b934c8387dc52570e243bde61fc..acbe8a5debab71b21590dc2939bee33e328c2bd4 100644 GIT binary patch delta 350 zcmZ`!xlY4S5L|+f7(b3+oRFlz6{0|h0tq3mf)5~{fP-T|f)|mqrI;Skur81gSDymW z@)>kd(o*pWtSu-gC|3Jsc6Mgp=RgnN^c5zM!z2utuwWw(2UBpNFpU|^Vh#n&!@~l6 z6j8z=%BZ|nYsu}SyThY9wak0ZN_nT$q&|gIm(mmo(mdYI@AKd(XB7VM)S!rOt{sni zrgg+$_iE#RkN3E^#G@^Dg@+F%%WhK^#N!uL=JiAwc9UWXC`=9ggN}?t>Ik7Fr6<*r zcU}6i@E6iWDziZDYsr=Ad{t0`*62hkHM;CO{^qYuEb=ot7eVy16lC9Q3rg8I3+swy PEIQ4HALcICl4|7}r&?R$ delta 68 zcmcb&E$`KayoMIW7N!>F7M2#)7Pc1l7LFFq7OocV7M>Q~7QPn#7J(MQ7NHj57LgXw Y7O@ub7Ks+g7O5@L0W+q%%$Ak{07D}dv;Y7A diff --git a/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_250.xml b/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_250.xml index cd041cda6..9a8054188 100644 --- a/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_250.xml +++ b/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_250.xml @@ -2496,4 +2496,10 @@ Manage stock integration + + Show abandoned checkouts + + + Also show transactions of a checkout that never became an order, e.g. a payment that failed or was left unfinished. + From f793dddf6bf2a9e378c0aa83a53adea81f3655f6 Mon Sep 17 00:00:00 2001 From: support Date: Wed, 18 Nov 2026 19:04:50 +0100 Subject: [PATCH 2/2] Record the payment before the order is written A transaction stayed Temp when saving the order or a handler of its inserted event failed after the gateway took the payment, so the list hid it as an abandoned checkout. The payment is now recorded right after the gateway answers. Deleting waits an hour after any change, not only on Temp ones, and searching by order number shows the transaction whatever state it is in. The list sends GetPaymentTransactionQuery itself, leaving IPaymentTransactionService unchanged. --- .../Orders/PlaceOrderCommandHandler.cs | 10 ++--- ...CanDeletePaymentTransactionQueryHandler.cs | 3 +- .../Payments/PaymentTransactionService.cs | 7 +--- .../Payments/IPaymentTransactionService.cs | 4 +- .../Orders/GetPaymentTransactionQuery.cs | 3 +- .../Orders/PlaceOrderCommandHandlerTests.cs | 15 ++++++- ...letePaymentTransactionQueryHandlerTests.cs | 11 +++++ .../BasePaymentTransactionControllerTests.cs | 39 +++++++++++++----- .../BasePaymentTransactionController.cs | 22 +++++----- .../App_Data/Resources/DefaultLanguage.xml | Bin 1809952 -> 1809940 bytes .../App_Data/Resources/Upgrade/en_250.xml | 2 +- 11 files changed, 77 insertions(+), 39 deletions(-) diff --git a/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PlaceOrderCommandHandler.cs b/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PlaceOrderCommandHandler.cs index 02505eb55..eb946ce69 100644 --- a/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PlaceOrderCommandHandler.cs +++ b/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PlaceOrderCommandHandler.cs @@ -242,6 +242,10 @@ public async Task Handle(PlaceOrderCommand command, Cancellati var orderHeader = PrepareOrderHeader(paymentTransaction, paymentResult, details); + //the payment is recorded before the order is written: if saving the order fails, the transaction + //still shows what the gateway did and is no longer taken for an abandoned checkout + await UpdatePaymentTransaction(paymentTransaction, orderHeader, paymentResult); + result.PlacedOrder = await SaveOrderDetails(details, orderHeader, orderItems); //from here on what was claimed belongs to the order orderInserted = true; @@ -250,12 +254,6 @@ public async Task Handle(PlaceOrderCommand command, Cancellati #endregion - #region Payment transaction - - await UpdatePaymentTransaction(paymentTransaction, result.PlacedOrder, paymentResult); - - #endregion - #region Events & notes await _mediator.Send(new OrderNotificationCommand { diff --git a/src/Business/Grand.Business.Checkout/Queries/Handlers/Orders/CanDeletePaymentTransactionQueryHandler.cs b/src/Business/Grand.Business.Checkout/Queries/Handlers/Orders/CanDeletePaymentTransactionQueryHandler.cs index b30181bd3..9ef4650f0 100644 --- a/src/Business/Grand.Business.Checkout/Queries/Handlers/Orders/CanDeletePaymentTransactionQueryHandler.cs +++ b/src/Business/Grand.Business.Checkout/Queries/Handlers/Orders/CanDeletePaymentTransactionQueryHandler.cs @@ -29,7 +29,8 @@ public async Task Handle(CanDeletePaymentTransactionQuery request, Cancell return false; var lastChangedUtc = paymentTransaction.UpdatedOnUtc ?? paymentTransaction.CreatedOnUtc; - if (paymentTransaction.Temp && lastChangedUtc > DateTime.UtcNow - CheckoutInProgress) + //the payment is recorded just before the order is written, so a recent change may still be getting one + if (lastChangedUtc > DateTime.UtcNow - CheckoutInProgress) return false; //a deleted order is gone from the panel, and the placeholders reserving order numbers are deleted ones diff --git a/src/Business/Grand.Business.Checkout/Services/Payments/PaymentTransactionService.cs b/src/Business/Grand.Business.Checkout/Services/Payments/PaymentTransactionService.cs index d45d377c4..6dbd80f95 100644 --- a/src/Business/Grand.Business.Checkout/Services/Payments/PaymentTransactionService.cs +++ b/src/Business/Grand.Business.Checkout/Services/Payments/PaymentTransactionService.cs @@ -132,7 +132,6 @@ public virtual async Task> GetByAuthorizationTransacti /// Page size /// Created date from (UTC); null to load all records /// Created date to (UTC); null to load all records - /// False leaves out transactions of a checkout that never became an order /// Page list payment transaction public virtual async Task> SearchPaymentTransactions( Guid? orderGuid = null, @@ -141,8 +140,7 @@ public virtual async Task> SearchPaymentTransacti TransactionStatus? ts = null, int pageIndex = 0, int pageSize = int.MaxValue, DateTime? createdFromUtc = null, - DateTime? createdToUtc = null, - bool includeTemp = true) + DateTime? createdToUtc = null) { var model = new GetPaymentTransactionQuery { CreatedFromUtc = createdFromUtc, @@ -152,8 +150,7 @@ public virtual async Task> SearchPaymentTransacti OrderGuid = orderGuid, CustomerEmail = customerEmail, StoreId = storeId, - Ts = ts, - IncludeTemp = includeTemp + Ts = ts }; return await _mediator.Send(model); diff --git a/src/Business/Grand.Business.Core/Interfaces/Checkout/Payments/IPaymentTransactionService.cs b/src/Business/Grand.Business.Core/Interfaces/Checkout/Payments/IPaymentTransactionService.cs index 977410701..d35d63a52 100644 --- a/src/Business/Grand.Business.Core/Interfaces/Checkout/Payments/IPaymentTransactionService.cs +++ b/src/Business/Grand.Business.Core/Interfaces/Checkout/Payments/IPaymentTransactionService.cs @@ -65,7 +65,6 @@ Task> GetByAuthorizationTransactionIdAndPaymentMethod( /// Page size /// Created date from (UTC); null to load all records /// Created date to (UTC); null to load all records - /// False leaves out transactions of a checkout that never became an order /// Page list payment transaction Task> SearchPaymentTransactions( Guid? orderGuid = null, @@ -74,8 +73,7 @@ Task> SearchPaymentTransactions( TransactionStatus? ts = null, int pageIndex = 0, int pageSize = int.MaxValue, DateTime? createdFromUtc = null, - DateTime? createdToUtc = null, - bool includeTemp = true); + DateTime? createdToUtc = null); /// /// Set payment error for transaction diff --git a/src/Business/Grand.Business.Core/Queries/Checkout/Orders/GetPaymentTransactionQuery.cs b/src/Business/Grand.Business.Core/Queries/Checkout/Orders/GetPaymentTransactionQuery.cs index 562e0fd50..3ff313f7b 100644 --- a/src/Business/Grand.Business.Core/Queries/Checkout/Orders/GetPaymentTransactionQuery.cs +++ b/src/Business/Grand.Business.Core/Queries/Checkout/Orders/GetPaymentTransactionQuery.cs @@ -15,6 +15,7 @@ public class GetPaymentTransactionQuery : IRequestFalse leaves out transactions of a checkout that never became an order. + /// False leaves out transactions of a checkout that never got a payment through: still in progress, + /// failed or abandoned. public bool IncludeTemp { get; set; } = true; } \ No newline at end of file diff --git a/src/Tests/Grand.Business.Checkout.Tests/Commands/Handlers/Orders/PlaceOrderCommandHandlerTests.cs b/src/Tests/Grand.Business.Checkout.Tests/Commands/Handlers/Orders/PlaceOrderCommandHandlerTests.cs index a3e621818..0f1d70d9f 100644 --- a/src/Tests/Grand.Business.Checkout.Tests/Commands/Handlers/Orders/PlaceOrderCommandHandlerTests.cs +++ b/src/Tests/Grand.Business.Checkout.Tests/Commands/Handlers/Orders/PlaceOrderCommandHandlerTests.cs @@ -276,6 +276,19 @@ public async Task Handle_ExceptionBeforeOrderInsert_ReleasesClaim() claims.Verify(x => x.Release(It.IsAny()), Times.Once); } + [TestMethod] + public async Task Handle_ExceptionBeforeOrderInsert_PaymentAlreadyRecorded() + { + var (handler, _, orders, _, _, _, details, _) = ClaimSetup(); + orders.Setup(x => x.InsertOrder(It.IsAny())).ThrowsAsync(new Exception("database down")); + + await handler.Handle(ClaimCommand(details), CancellationToken.None); + + //what the gateway did stays visible, and the transaction is not taken for an abandoned checkout + _paymentTransactions.Verify(x => x.UpdatePaymentTransaction(It.Is(t => + t.Id == "tx" && !t.Temp && t.TransactionAmount == details.OrderTotal)), Times.Once); + } + [TestMethod] public async Task Handle_ExceptionAfterOrderInsert_KeepsClaim() { @@ -367,7 +380,7 @@ protected override Task PreparePaymentTransaction(PlaceOrder { return Task.FromResult(new PaymentTransaction { Id = "tx", StoreId = "store", OrderCode = "CODE1", - PaymentMethodSystemName = details.PaymentMethodSystemName + PaymentMethodSystemName = details.PaymentMethodSystemName, Temp = true }); } diff --git a/src/Tests/Grand.Business.Checkout.Tests/Queries/Handlers/Orders/CanDeletePaymentTransactionQueryHandlerTests.cs b/src/Tests/Grand.Business.Checkout.Tests/Queries/Handlers/Orders/CanDeletePaymentTransactionQueryHandlerTests.cs index 4aba6b141..25ac1a27b 100644 --- a/src/Tests/Grand.Business.Checkout.Tests/Queries/Handlers/Orders/CanDeletePaymentTransactionQueryHandlerTests.cs +++ b/src/Tests/Grand.Business.Checkout.Tests/Queries/Handlers/Orders/CanDeletePaymentTransactionQueryHandlerTests.cs @@ -117,6 +117,17 @@ public async Task CheckoutStillInProgress_CannotDelete() Assert.IsFalse(await Handle(retried)); } + [TestMethod] + public async Task PaymentJustRecorded_CannotDelete() + { + //the payment is recorded just before the order is written + var recorded = Abandoned(); + recorded.Temp = false; + recorded.UpdatedOnUtc = DateTime.UtcNow.AddSeconds(-1); + + Assert.IsFalse(await Handle(recorded)); + } + [TestMethod] public async Task NullTransaction_Throws() { diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/BasePaymentTransactionControllerTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/BasePaymentTransactionControllerTests.cs index 0d64ee02a..34f70caa5 100644 --- a/src/Tests/Grand.Web.Admin.Tests/Controllers/BasePaymentTransactionControllerTests.cs +++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/BasePaymentTransactionControllerTests.cs @@ -104,9 +104,7 @@ public void List_ReturnsViewWithPreparedModel() public async Task List_Post_AdminScope_DoesNotForceStoreId() { _scopeMock.Setup(s => s.DefaultStoreId).Returns((string)null); - _paymentTransactionServiceMock - .Setup(s => s.SearchPaymentTransactions(null, null, null, null, 0, int.MaxValue, null, null, false)) - .ReturnsAsync(new PagedList(new List(), 0, 10)); + SetupSearch(); var model = new PaymentTransactionListModel(); await _controller.List(new DataSourceRequest { Page = 1, PageSize = int.MaxValue }, model); @@ -114,33 +112,52 @@ public async Task List_Post_AdminScope_DoesNotForceStoreId() Assert.IsNull(model.StoreId); } + private void SetupSearch() + { + _mediatorMock + .Setup(m => m.Send(It.IsAny(), It.IsAny())) + .ReturnsAsync(new PagedList(new List(), 0, 10)); + } + [TestMethod] public async Task List_Post_LeavesOutAbandonedUnlessAsked() { - _paymentTransactionServiceMock - .Setup(s => s.SearchPaymentTransactions(null, null, null, null, 0, int.MaxValue, null, null, It.IsAny())) - .ReturnsAsync(new PagedList(new List(), 0, 10)); + SetupSearch(); var command = new DataSourceRequest { Page = 1, PageSize = int.MaxValue }; await _controller.List(command, new PaymentTransactionListModel()); await _controller.List(command, new PaymentTransactionListModel { ShowAbandoned = true }); - _paymentTransactionServiceMock.Verify(s => s.SearchPaymentTransactions(null, null, null, null, 0, int.MaxValue, null, null, false), Times.Once); - _paymentTransactionServiceMock.Verify(s => s.SearchPaymentTransactions(null, null, null, null, 0, int.MaxValue, null, null, true), Times.Once); + _mediatorMock.Verify(m => m.Send(It.Is(q => !q.IncludeTemp), It.IsAny()), Times.Once); + _mediatorMock.Verify(m => m.Send(It.Is(q => q.IncludeTemp), It.IsAny()), Times.Once); + } + + [TestMethod] + public async Task List_Post_ByOrderNumber_IncludesAbandoned() + { + SetupSearch(); + var orderGuid = Guid.NewGuid(); + _orderServiceMock.Setup(s => s.GetOrderByNumber(1001)).ReturnsAsync(new Order { OrderGuid = orderGuid }); + + await _controller.List(new DataSourceRequest { Page = 1, PageSize = int.MaxValue }, + new PaymentTransactionListModel { OrderNumber = "1001" }); + + _mediatorMock.Verify(m => m.Send(It.Is(q => q.OrderGuid == orderGuid && q.IncludeTemp), + It.IsAny()), Times.Once); } [TestMethod] public async Task List_Post_StoreScope_ForcesStoreId() { _scopeMock.Setup(s => s.DefaultStoreId).Returns("store-1"); - _paymentTransactionServiceMock - .Setup(s => s.SearchPaymentTransactions(null, "store-1", It.IsAny(), null, 0, int.MaxValue, null, null, false)) - .ReturnsAsync(new PagedList(new List(), 0, 10)); + SetupSearch(); var model = new PaymentTransactionListModel { StoreId = "some-other-store" }; await _controller.List(new DataSourceRequest { Page = 1, PageSize = int.MaxValue }, model); Assert.AreEqual("store-1", model.StoreId); + _mediatorMock.Verify(m => m.Send(It.Is(q => q.StoreId == "store-1"), + It.IsAny()), Times.Once); } [TestMethod] diff --git a/src/Web/Grand.Web.AdminShared/Controllers/BasePaymentTransactionController.cs b/src/Web/Grand.Web.AdminShared/Controllers/BasePaymentTransactionController.cs index 76fb91c99..d345a2ab6 100644 --- a/src/Web/Grand.Web.AdminShared/Controllers/BasePaymentTransactionController.cs +++ b/src/Web/Grand.Web.AdminShared/Controllers/BasePaymentTransactionController.cs @@ -103,16 +103,18 @@ public async Task List(DataSourceRequest command, PaymentTransact orderGuid = order.OrderGuid; } - var paymentTransactions = await paymentTransactionService.SearchPaymentTransactions( - customerEmail: model.SearchCustomerEmail, - ts: model.SearchTransactionStatus >= 0 ? (TransactionStatus)model.SearchTransactionStatus : null, - createdFromUtc: startDateValue, - createdToUtc: endDateValue, - storeId: model.StoreId, - orderGuid: orderGuid, - pageIndex: command.Page - 1, - pageSize: command.PageSize, - includeTemp: model.ShowAbandoned); + var paymentTransactions = await mediator.Send(new GetPaymentTransactionQuery { + CustomerEmail = model.SearchCustomerEmail, + Ts = model.SearchTransactionStatus >= 0 ? (TransactionStatus)model.SearchTransactionStatus : null, + CreatedFromUtc = startDateValue, + CreatedToUtc = endDateValue, + StoreId = model.StoreId, + OrderGuid = orderGuid, + PageIndex = command.Page - 1, + PageSize = command.PageSize, + //the payment of an order searched for by its number is shown whatever state its checkout left it in + IncludeTemp = model.ShowAbandoned || orderGuid.HasValue + }); var dataModel = new List(); diff --git a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml index fd0c348309246c4eca45a297a1f767cf2b5cee56..d80a4943603419d608fa9422ec5b40abab276572 100644 GIT binary patch delta 125 zcmZ3mCvVE0yoMIW7N!>F7M2#)7Pc1l7LFFq7OocV7M>Q~7QPn#7J(MQ7NHj57LgXw z7O@ub7Ks+g7O5@LR&%F^xbnyt=P{%*lmT%Og91Z2kj`T$0kTRMGJqoa45bX|K$Z?r TB$YuA$kqe0GN(_SE8PtMJDDMj delta 145 zcmbQTCvU-?yoMIW7N!>F7M2#)7Pc1l7LFFq7OocV7M>Q~7QPn#7J(MQ7NHj57LgXw z7O@ub7Ks+g7O5@LR&$+87%~_V8A=!w81fiW8OngT2*^$X(#b&aTp+Cgr1OAeK2RnF eEUyFPr84L-qysTfc6wnsrzkVfnCYE!rMm&Y6(th@ diff --git a/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_250.xml b/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_250.xml index f52bccc1d..b80b5b135 100644 --- a/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_250.xml +++ b/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_250.xml @@ -2503,6 +2503,6 @@ Show abandoned checkouts - Also show transactions of a checkout that never became an order, e.g. a payment that failed or was left unfinished. + Also show transactions of a checkout whose payment never went through, e.g. it failed or was left unfinished.