DefaultOrderInquiryService implements OrderInquiryService { @Override public void processOrderInquiryServiceResponse(final PaymentTransactionModel paymentTransactionModel, final OrderInquiryServiceResponse orderInquiryServiceResponse) throws WorldpayConfigurationException { if (!orderInquiryServiceResponse.isError()) { final String methodCode = orderInquiryServiceResponse.getPaymentReply().getMethodCode(); worldpayPaymentInfoService.savePaymentType(paymentTransactionModel, methodCode); if (paymentTransactionModel.getInfo().getIsApm()) { worldpayPaymentInfoService.createWorldpayApmPaymentInfo(paymentTransactionModel); LOG.info(format("Converting PaymentInfo to WorldpayAPMPaymentInfo and setting timeout-date for PaymentTransaction with code [{0}] on order with code [{1}]", paymentTransactionModel.getCode(), paymentTransactionModel.getOrder().getCode())); } } else { LOG.error(format("Order inquiry service returned error [{0}]", orderInquiryServiceResponse.getErrorDetail().getMessage())); } }  @Override OrderInquiryServiceResponse inquirePaymentTransaction(final MerchantInfo merchantConfig, final PaymentTransactionModel paymentTransactionModel); @Override void processOrderInquiryServiceResponse(final PaymentTransactionModel paymentTransactionModel, final OrderInquiryServiceResponse orderInquiryServiceResponse); @Override OrderInquiryServiceResponse inquireOrder(final MerchantInfo merchantInfo, final String worldpayOrderCode); @Override OrderInquiryServiceResponse inquiryKlarnaOrder(final MerchantInfo merchantInfo, final String worldpayOrderCode); @Required void setWorldpayPaymentInfoService(final WorldpayPaymentInfoService worldpayPaymentInfoService); @Required void setWorldpayServiceGateway(final WorldpayServiceGateway worldpayServiceGateway); @Required void setConfigurationService(final ConfigurationService configurationService);  }
@Test public void processOrderInquiryServiceResponseShouldCreateAPMPaymentInfo() throws WorldpayConfigurationException { when(paymentTransactionPaymentInfoModelMock.getIsApm()).thenReturn(true); testObj.processOrderInquiryServiceResponse(paymentTransactionModelMock, orderInquiryServiceResponseMock); verify(worldpayPaymentInfoServiceMock).savePaymentType(paymentTransactionModelMock, PAYMENT_METHOD_CODE); verify(worldpayPaymentInfoServiceMock).createWorldpayApmPaymentInfo(paymentTransactionModelMock); }
@Test public void processOrderInquiryServiceResponseShouldNotCreateAPMPaymentInfoWhenNotAPM() throws WorldpayConfigurationException { when(paymentTransactionPaymentInfoModelMock.getIsApm()).thenReturn(false); testObj.processOrderInquiryServiceResponse(paymentTransactionModelMock, orderInquiryServiceResponseMock); verify(worldpayPaymentInfoServiceMock).savePaymentType(paymentTransactionModelMock, PAYMENT_METHOD_CODE); verify(worldpayPaymentInfoServiceMock, never()).createWorldpayApmPaymentInfo(paymentTransactionModelMock); }
@Test public void processOrderInquiryServiceResponseShouldDoNothingWhenInquiryResponseHasErrors() throws WorldpayConfigurationException { when(orderInquiryServiceResponseMock.isError()).thenReturn(true); when(orderInquiryServiceResponseMock.getErrorDetail().getMessage()).thenReturn(ERROR_MESSAGE); testObj.processOrderInquiryServiceResponse(paymentTransactionModelMock, orderInquiryServiceResponseMock); verify(worldpayPaymentInfoServiceMock, never()).savePaymentType(paymentTransactionModelMock, PAYMENT_METHOD_CODE); verify(worldpayPaymentInfoServiceMock, never()).createWorldpayApmPaymentInfo(paymentTransactionModelMock); }