DefaultWorldpayHostedOrderFacade implements WorldpayHostedOrderFacade { @Override public RedirectAuthoriseResult inquiryPaymentStatus() throws WorldpayException { final String worldpayOrderCode = cartService.getSessionCart().getWorldpayOrderCode(); final MerchantInfo merchantInfo = worldpayMerchantInfoService.getCurrentSiteMerchant(); final OrderInquiryServiceResponse inquiryResponse = orderInquiryService.inquireOrder(merchantInfo, worldpayOrderCode); final PaymentReply paymentReply = inquiryResponse.getPaymentReply(); final RedirectAuthoriseResult redirectAuthoriseResult = new RedirectAuthoriseResult(); redirectAuthoriseResult.setPaymentStatus(paymentReply.getAuthStatus()); final BigDecimal paymentAmount = worldpayOrderService.convertAmount(paymentReply.getAmount()); redirectAuthoriseResult.setPaymentAmount(paymentAmount); redirectAuthoriseResult.setPending(apmConfigurationLookupService.getAPMConfigurationForCode(paymentReply.getMethodCode()) != null); return redirectAuthoriseResult; } DefaultWorldpayHostedOrderFacade(final SessionService sessionService, final WorldpayRedirectOrderService worldpayRedirectOrderService,
                                            final WorldpayMerchantInfoService worldpayMerchantInfoService, final CartService cartService,
                                            final WorldpayOrderInfoStrategy worldpayOrderInfoStrategy,
                                            final WorldpayMerchantConfigDataFacade worldpayMerchantConfigDataFacade,
                                            final OrderInquiryService orderInquiryService,
                                            final APMConfigurationLookupService apmConfigurationLookupService,
                                            final WorldpayOrderService worldpayOrderService); @Override PaymentData redirectAuthorise(final AdditionalAuthInfo additionalAuthInfo); @Override void completeRedirectAuthorise(final RedirectAuthoriseResult result); @Override boolean validateRedirectResponse(final Map<String, String> worldpayResponse); @Override RedirectAuthoriseResult inquiryPaymentStatus();  }
@Test public void shouldInquiryPaymentStatusRetrievingOrderCodeFromCartForAPM() throws WorldpayException { when(worldpayMerchantInfoServiceMock.getCurrentSiteMerchant()).thenReturn(merchantInfoMock); when(cartModelMock.getWorldpayOrderCode()).thenReturn(WORLDPAY_ORDER_CODE); when(orderInquiryServiceMock.inquireOrder(merchantInfoMock, WORLDPAY_ORDER_CODE)).thenReturn(orderInquiryServiceResponseMock); when(paymentReplyMock.getAuthStatus()).thenReturn(AuthorisedStatus.AUTHORISED); when(worldpayOrderServiceMock.convertAmount(paymentReplyMock.getAmount())).thenReturn(BigDecimal.valueOf(123.45)); when(paymentReplyMock.getMethodCode()).thenReturn(PAYMENT_TYPE_CODE); when(apmConfigurationLookupService.getAPMConfigurationForCode(PAYMENT_TYPE_CODE)).thenReturn(worldpayAPMConfigurationModel); final RedirectAuthoriseResult result = testObj.inquiryPaymentStatus(); assertEquals(AuthorisedStatus.AUTHORISED, result.getPaymentStatus()); assertEquals(BigDecimal.valueOf(123.45D), result.getPaymentAmount()); assertTrue(result.getPending()); }
@Test public void shouldInquiryPaymentStatusRetrievingOrderCodeFromCartForNotAPM() throws WorldpayException { when(worldpayMerchantInfoServiceMock.getCurrentSiteMerchant()).thenReturn(merchantInfoMock); when(cartModelMock.getWorldpayOrderCode()).thenReturn(WORLDPAY_ORDER_CODE); when(orderInquiryServiceMock.inquireOrder(merchantInfoMock, WORLDPAY_ORDER_CODE)).thenReturn(orderInquiryServiceResponseMock); when(paymentReplyMock.getAuthStatus()).thenReturn(AuthorisedStatus.AUTHORISED); when(worldpayOrderServiceMock.convertAmount(paymentReplyMock.getAmount())).thenReturn(BigDecimal.valueOf(123.45)); when(paymentReplyMock.getMethodCode()).thenReturn(PAYMENT_TYPE_CODE); when(apmConfigurationLookupService.getAPMConfigurationForCode(PAYMENT_TYPE_CODE)).thenReturn(null); final RedirectAuthoriseResult result = testObj.inquiryPaymentStatus(); assertEquals(AuthorisedStatus.AUTHORISED, result.getPaymentStatus()); assertEquals(BigDecimal.valueOf(123.45D), result.getPaymentAmount()); assertFalse(result.getPending()); }