@@ -422,6 +422,10 @@ public ResponseEntity<?> checkoutBasket(@RequestBody(required = false) String js
422422 } else {
423423 logMap .put (LoggingUtils .STATUS , OK );
424424 LOGGER .infoRequest (request , "Basket checkout completed no payment required" , logMap );
425+
426+ processOrder (checkout , logMap );
427+ LOGGER .infoRequest (request , "Free order processed" , logMap );
428+
425429 return new ResponseEntity <>(checkoutData , OK );
426430 }
427431 }
@@ -582,7 +586,20 @@ private Checkout updateCheckout(final Checkout checkout, final BasketPaymentRequ
582586 */
583587 private void processSuccessfulPayment (final String requestId ,
584588 final Checkout checkout ) {
585- Map <String , Object > logMap = LoggingUtils .createLogMapWithRequestId (requestId );
589+ final Map <String , Object > logMap = LoggingUtils .createLogMapWithRequestId (requestId );
590+ processOrder (checkout , logMap );
591+ LOGGER .info ("Process successful payment, order created and basket cleared" , logMap );
592+ }
593+
594+ /**
595+ * Performs the actions required to process an order. This order must be "good to go" - i.e.,
596+ * successfully paid for, or free.
597+ *
598+ * @param checkout the checkout required to process the payment
599+ * @param logMap log map for logging by client method
600+ */
601+ private void processOrder (final Checkout checkout ,
602+ final Map <String , Object > logMap ) {
586603 LoggingUtils .logIfNotNull (logMap , LoggingUtils .USER_ID , checkout .getId ());
587604 orderService .createOrder (checkout );
588605 basketService .clearBasket (checkout .getUserId ());
0 commit comments