@@ -47,6 +47,8 @@ public class PlaceOrderCommandHandler : IRequestHandler<PlaceOrderCommand, Place
4747 private readonly ILanguageService _languageService ;
4848 private readonly ILogger < PlaceOrderCommandHandler > _logger ;
4949 private readonly IMediator _mediator ;
50+ private readonly IOrderApprovalService _orderApprovalService ;
51+ private readonly ITranslationService _translationService ;
5052 private readonly ICatalogMessageProviderService _catalogMessageProviderService ;
5153 private readonly IOrderService _orderService ;
5254 private readonly OrderSettings _orderSettings ;
@@ -100,6 +102,8 @@ public PlaceOrderCommandHandler(
100102 IAuctionService auctionService ,
101103 ICountryService countryService ,
102104 IShoppingCartValidator shoppingCartValidator ,
105+ IOrderApprovalService orderApprovalService ,
106+ ITranslationService translationService ,
103107 ShippingSettings shippingSettings ,
104108 ShoppingCartSettings shoppingCartSettings ,
105109 PaymentSettings paymentSettings ,
@@ -136,6 +140,8 @@ public PlaceOrderCommandHandler(
136140 _auctionService = auctionService ;
137141 _countryService = countryService ;
138142 _shoppingCartValidator = shoppingCartValidator ;
143+ _orderApprovalService = orderApprovalService ;
144+ _translationService = translationService ;
139145 _shippingSettings = shippingSettings ;
140146 _shoppingCartSettings = shoppingCartSettings ;
141147 _paymentSettings = paymentSettings ;
@@ -163,6 +169,16 @@ public async Task<PlaceOrderResult> Handle(PlaceOrderCommand command, Cancellati
163169 if ( result . Errors . Any ( ) )
164170 return result ;
165171
172+ //an order over the customer's limit is placed awaiting an approval, with an allowed payment method only
173+ var approval = await _orderApprovalService . RequiresApproval ( details . Cart , details . Context ) ;
174+ details . ApprovalRequired = approval . Required ;
175+ if ( details . ApprovalRequired && ! _orderApprovalService . IsPaymentMethodAllowed ( details . PaymentMethodSystemName ) )
176+ {
177+ result . AddError ( _translationService . GetResource ( "Checkout.OrderApproval.PaymentMethodNotAllowed" ,
178+ command . Language . Id ) ) ;
179+ return result ;
180+ }
181+
166182 #region Payment workflow
167183
168184 var processPayment = await PrepareProcessPayment ( details ) ;
@@ -194,7 +210,8 @@ await _mediator.Send(new OrderNotificationCommand {
194210 Order = result . PlacedOrder ,
195211 Customer = details . Customer ,
196212 OriginalCustomerIfImpersonated = command . OriginalCustomerIfImpersonated ,
197- Host = command . Host
213+ Host = command . Host ,
214+ NotifyStoreOwnerAndVendors = ! details . ApprovalRequired
198215 } , cancellationToken ) ;
199216
200217 //check order status
@@ -203,7 +220,8 @@ await _mediator.Send(new OrderNotificationCommand {
203220 //raise event
204221 await _mediator . Publish ( new OrderPlacedEvent ( result . PlacedOrder ) , cancellationToken ) ;
205222
206- if ( result . PlacedOrder . PaymentStatusId == PaymentStatus . Paid )
223+ //an order awaiting approval is processed as paid once it is approved (store owner and vendors hear of it then)
224+ if ( ! details . ApprovalRequired && result . PlacedOrder . PaymentStatusId == PaymentStatus . Paid )
207225 await _mediator . Send ( new ProcessOrderPaidCommand { Order = result . PlacedOrder } , cancellationToken ) ;
208226
209227 #endregion
@@ -929,7 +947,9 @@ protected virtual Order PrepareOrderHeader(PaymentTransaction paymentTransaction
929947 CurrencyRate = details . CurrencyRate ,
930948 Rate = details . Currency . Rate ,
931949 AffiliateId = details . AffiliateId ,
932- OrderStatusId = ( int ) OrderStatusSystem . Pending ,
950+ OrderStatusId = details . ApprovalRequired
951+ ? ( int ) OrderStatusSystem . AwaitingApproval
952+ : ( int ) OrderStatusSystem . Pending ,
933953 PaymentMethodSystemName = paymentTransaction . PaymentMethodSystemName ,
934954 PaymentOptionAttribute =
935955 details . Customer . GetUserFieldFromEntity < string > ( SystemCustomerFieldNames . PaymentOptionAttribute ,
0 commit comments