DefaultWorldpayKlarnaPaymentCheckoutFacade implements WorldpayKlarnaPaymentCheckoutFacade { @Override public KlarnaRedirectAuthoriseResult checkKlarnaOrderStatus() throws WorldpayException { final CartModel cartModel = getCart(); final MerchantInfo merchantConfig = worldpayMerchantInfoService.getCurrentSiteMerchant(); final OrderInquiryServiceResponse serviceResponse = orderInquiryService.inquiryKlarnaOrder(merchantConfig, cartModel.getWorldpayOrderCode()); final AuthorisedStatus authStatus = serviceResponse.getPaymentReply().getAuthStatus(); if (AuthorisedStatus.AUTHORISED.equals(authStatus) || AuthorisedStatus.SHOPPER_REDIRECTED.equals(authStatus)) { final KlarnaRedirectAuthoriseResult klarnaRedirectAuthoriseResult = new KlarnaRedirectAuthoriseResult(); klarnaRedirectAuthoriseResult.setPending(true); klarnaRedirectAuthoriseResult.setPaymentAmount(worldpayOrderService.convertAmount(serviceResponse.getPaymentReply().getAmount())); final String decodedHtmlContent = new String(Base64.getDecoder().decode(serviceResponse.getReference().getValue()), StandardCharsets.UTF_8); klarnaRedirectAuthoriseResult.setDecodedHTMLContent(decodedHtmlContent); return klarnaRedirectAuthoriseResult; } else { throw new WorldpayException("There was a problem placing the order"); } }  @Override KlarnaRedirectAuthoriseResult checkKlarnaOrderStatus(); @Required void setCheckoutFacade(final CheckoutFacade checkoutFacade); @Required void setCartService(final CartService cartService); @Required void setWorldpayMerchantInfoService(final WorldpayMerchantInfoService worldpayMerchantInfoService); @Required void setOrderInquiryService(DefaultOrderInquiryService orderInquiryService); @Required void setWorldpayOrderService(final WorldpayOrderService worldpayOrderService);  }
@Test public void shouldInquiryKlarnaOrderStatusAuthorised() throws WorldpayException { when(worldpayMerchantInfoServiceMock.getCurrentSiteMerchant()).thenReturn(merchantInfoMock); when(orderInquiryServiceResponseMock.getReference().getValue()).thenReturn(KLARNA_CONTENT_ENCODED); when(orderInquiryServiceResponseMock.getPaymentReply().getAuthStatus()).thenReturn(AuthorisedStatus.AUTHORISED); when(orderInquiryServiceResponseMock.getPaymentReply().getAmount()).thenReturn(amountMock); final KlarnaRedirectAuthoriseResult result = testObj.checkKlarnaOrderStatus(); assertThat(result.getPending()).isTrue(); assertThat(result.getDecodedHTMLContent()).isEqualTo(KLARNA_CONTENT_DECODED); assertThat(result.getPaymentAmount()).isEqualTo(BigDecimal.valueOf(10.51D)); }
@Test public void shouldInquiryKlarnaOrderStatusShopperRedirect() throws WorldpayException { when(worldpayMerchantInfoServiceMock.getCurrentSiteMerchant()).thenReturn(merchantInfoMock); when(worldpayServiceGatewayMock.orderInquiry(klarnaOrderInquiryServiceRequestMock)).thenReturn(orderInquiryServiceResponseMock); when(orderInquiryServiceResponseMock.getReference().getValue()).thenReturn(KLARNA_CONTENT_ENCODED); when(orderInquiryServiceResponseMock.getPaymentReply().getAuthStatus()).thenReturn(AuthorisedStatus.SHOPPER_REDIRECTED); final KlarnaRedirectAuthoriseResult result = testObj.checkKlarnaOrderStatus(); assertThat(result.getDecodedHTMLContent()).isEqualTo(KLARNA_CONTENT_DECODED); }
@Test public void shouldInquiryKlarnaOrderStatusShopperNotAuthorisedOrRedirectWillFail() throws WorldpayException { expectedException.expect(WorldpayException.class); expectedException.expectMessage("There was a problem placing the order"); when(worldpayMerchantInfoServiceMock.getCurrentSiteMerchant()).thenReturn(merchantInfoMock); when(worldpayServiceGatewayMock.orderInquiry(klarnaOrderInquiryServiceRequestMock)).thenReturn(orderInquiryServiceResponseMock); when(orderInquiryServiceResponseMock.getReference().getValue()).thenReturn(KLARNA_CONTENT_ENCODED); when(orderInquiryServiceResponseMock.getPaymentReply().getAuthStatus()).thenReturn(AuthorisedStatus.ERROR); testObj.checkKlarnaOrderStatus(); }