WorldpaySubscriptionAuthoriseResultPopulator implements Populator<DirectAuthoriseServiceResponse, WorldpaySubscriptionAuthorizeResult> { @Override public void populate(final DirectAuthoriseServiceResponse source, final WorldpaySubscriptionAuthorizeResult target) throws ConversionException { final String orderCode = source.getOrderCode(); final PaymentReply paymentReply = source.getPaymentReply(); if (paymentReply == null) { if (source.getRedirectReference() != null) { worldpayAuthorisationResultService.setAuthorizeResultForAPM(source, target); } else { LOG.warn("No PaymentReply in response from worldpay"); final ErrorDetail errorDetail = source.getErrorDetail(); if (errorDetail != null) { LOG.error("Error message from Worldpay: " + errorDetail.getMessage()); } worldpayAuthorisationResultService.setAuthoriseResultAsError(target); } } else { final AuthorisedStatus status = paymentReply.getAuthStatus(); worldpayAuthorisationResultService.setAuthoriseResultByTransactionStatus(target, status, orderCode); } }  @Override void populate(final DirectAuthoriseServiceResponse source, final WorldpaySubscriptionAuthorizeResult target); @Required void setWorldpayAuthorisationResultService(final WorldpayAuthorisationResultService worldpayAuthorisationResultService);  }
@Test public void populateShouldSetAcceptedAndSuccessfulWhenDirectAuthoriseServiceResponseAuthorised() { when(paymentReplyMock.getAuthStatus()).thenReturn(AUTHORISED); final WorldpaySubscriptionAuthorizeResult result = new WorldpaySubscriptionAuthorizeResult(); testObj.populate(directAuthoriseServiceResponseMock, result); verify(worldpayAuthorisationResultServiceMock).setAuthoriseResultByTransactionStatus(result, AUTHORISED, ORDER_CODE); }
@Test public void populateShouldSetRejectedAndUnknownCodeWhenDirectAuthoriseServiceResponseNotAuthorised() { when(paymentReplyMock.getAuthStatus()).thenReturn(REFUSED); final WorldpaySubscriptionAuthorizeResult result = new WorldpaySubscriptionAuthorizeResult(); testObj.populate(directAuthoriseServiceResponseMock, result); verify(worldpayAuthorisationResultServiceMock).setAuthoriseResultByTransactionStatus(result, REFUSED, ORDER_CODE); }
@Test public void populateShouldSetErrorAndGeneralSystemErrorWhenDirectAuthoriseServiceResponseError() { when(paymentReplyMock.getAuthStatus()).thenReturn(ERROR); final WorldpaySubscriptionAuthorizeResult result = new WorldpaySubscriptionAuthorizeResult(); testObj.populate(directAuthoriseServiceResponseMock, result); verify(worldpayAuthorisationResultServiceMock).setAuthoriseResultByTransactionStatus(result, ERROR, ORDER_CODE); }
@Test public void populateShouldSetErrorAndGeneralSystemErrorWhenDirectAuthoriseServiceResponseHasNoPaymentReplyAndIsNotAPM() { when(directAuthoriseServiceResponseMock.getPaymentReply()).thenReturn(null); when(directAuthoriseServiceResponseMock.getErrorDetail()).thenReturn(errorDetailMock); when(errorDetailMock.getMessage()).thenReturn(ERROR_MESSAGE); final WorldpaySubscriptionAuthorizeResult result = new WorldpaySubscriptionAuthorizeResult(); testObj.populate(directAuthoriseServiceResponseMock, result); verify(directAuthoriseServiceResponseMock).getErrorDetail(); verify(worldpayAuthorisationResultServiceMock).setAuthoriseResultAsError(result); }
@Test public void populateShouldSetRejectedAndReviewNeededWhenDirectAuthoriseServiceResponseHasNoPaymentReplyAndIsAPM() { when(directAuthoriseServiceResponseMock.getPaymentReply()).thenReturn(null); when(directAuthoriseServiceResponseMock.getRedirectReference()).thenReturn(redirectReferenceMock); when(redirectReferenceMock.getValue()).thenReturn(REFERENCE_URL); final WorldpaySubscriptionAuthorizeResult result = new WorldpaySubscriptionAuthorizeResult(); testObj.populate(directAuthoriseServiceResponseMock, result); verify(worldpayAuthorisationResultServiceMock).setAuthorizeResultForAPM(directAuthoriseServiceResponseMock, result); }