@Test public void executePaymentRefundOperationSuccessTest() throws WirecardPaymenException { when(returnRequestModel.getOrder()).thenReturn(orderModel); when(wirecardTransactionService.lookForAcceptedTransactions(orderModel, PaymentTransactionType.CAPTURE)) .thenReturn(true); when(orderModel.getPaymentTransactions()).thenReturn(Collections.singletonList(transaction2)); when(orderModel.getPaymentMode()).thenReturn(paymentModeModel); when(paymentModeModel.getCode()).thenReturn(provider2); when(paymentOperationStrategy.getOperation(returnRequestModel.getOrder().getPaymentMode(), PaymentTransactionType.REFUND_FOLLOW_ON.name())) .thenReturn(paymentOperation); try { when(paymentOperation.doOperation(returnRequestModel, null)) .thenReturn(returnSuccess); } catch (WirecardPaymenException e) { e.printStackTrace(); } when(wirecardPaymentService.getReturnStatus(returnSuccess)).thenReturn(ReturnStatus.PAYMENT_REVERSED); ReturnStatus returnStatus = wirecardPaymentOperationExecutionService.executePaymentRefundOperation(returnRequestModel, null); assertEquals("ReturnStatus does not match", ReturnStatus.PAYMENT_REVERSED, returnStatus); }
@Override public ReturnStatus executePaymentRefundOperation(ReturnRequestModel returnRequestModel, PaymentOperationData data) { Payment response = null; try { if (wirecardTransactionService.lookForAcceptedTransactions(returnRequestModel.getOrder(), PaymentTransactionType.CAPTURE)) { response = getPaymentOperationStrategy().getOperation(returnRequestModel.getOrder().getPaymentMode(), WirecardPaymentTransactionConstants.REFUND_FOLLOW_ON) .doOperation(returnRequestModel, data); } else if (wirecardTransactionService.lookForAcceptedTransactions(returnRequestModel.getOrder(), PaymentTransactionType.DEBIT)) { WirecardPaymentConfigurationModel paymentConfigurationModel = wirecardPaymentConfigurationService.getConfiguration(returnRequestModel.getOrder().getStore(), returnRequestModel.getOrder().getPaymentMode()); data = new PaymentOperationData(); data.setWirecardFallbackAuthenticationModel(paymentConfigurationModel.getFallbackAuthentication()); response = getPaymentOperationStrategy().getOperation(returnRequestModel.getOrder().getPaymentMode(), WirecardPaymentTransactionConstants.REFUND_FOLLOW_ON) .doOperation(returnRequestModel, data); } } catch (WirecardPaymenException e) { LOGGER.error(e.getMessage(), e); } ReturnStatus returnStatus = wirecardPaymentService.getReturnStatus(response); wirecardPaymentService.setReturnRequestStatus(returnRequestModel, returnStatus); return returnStatus; }
DefaultWirecardPOExecutionService implements WirecardPOExecutionService { @Override public ReturnStatus executePaymentRefundOperation(ReturnRequestModel returnRequestModel, PaymentOperationData data) { Payment response = null; try { if (wirecardTransactionService.lookForAcceptedTransactions(returnRequestModel.getOrder(), PaymentTransactionType.CAPTURE)) { response = getPaymentOperationStrategy().getOperation(returnRequestModel.getOrder().getPaymentMode(), WirecardPaymentTransactionConstants.REFUND_FOLLOW_ON) .doOperation(returnRequestModel, data); } else if (wirecardTransactionService.lookForAcceptedTransactions(returnRequestModel.getOrder(), PaymentTransactionType.DEBIT)) { WirecardPaymentConfigurationModel paymentConfigurationModel = wirecardPaymentConfigurationService.getConfiguration(returnRequestModel.getOrder().getStore(), returnRequestModel.getOrder().getPaymentMode()); data = new PaymentOperationData(); data.setWirecardFallbackAuthenticationModel(paymentConfigurationModel.getFallbackAuthentication()); response = getPaymentOperationStrategy().getOperation(returnRequestModel.getOrder().getPaymentMode(), WirecardPaymentTransactionConstants.REFUND_FOLLOW_ON) .doOperation(returnRequestModel, data); } } catch (WirecardPaymenException e) { LOGGER.error(e.getMessage(), e); } ReturnStatus returnStatus = wirecardPaymentService.getReturnStatus(response); wirecardPaymentService.setReturnRequestStatus(returnRequestModel, returnStatus); return returnStatus; } }
DefaultWirecardPOExecutionService implements WirecardPOExecutionService { @Override public ReturnStatus executePaymentRefundOperation(ReturnRequestModel returnRequestModel, PaymentOperationData data) { Payment response = null; try { if (wirecardTransactionService.lookForAcceptedTransactions(returnRequestModel.getOrder(), PaymentTransactionType.CAPTURE)) { response = getPaymentOperationStrategy().getOperation(returnRequestModel.getOrder().getPaymentMode(), WirecardPaymentTransactionConstants.REFUND_FOLLOW_ON) .doOperation(returnRequestModel, data); } else if (wirecardTransactionService.lookForAcceptedTransactions(returnRequestModel.getOrder(), PaymentTransactionType.DEBIT)) { WirecardPaymentConfigurationModel paymentConfigurationModel = wirecardPaymentConfigurationService.getConfiguration(returnRequestModel.getOrder().getStore(), returnRequestModel.getOrder().getPaymentMode()); data = new PaymentOperationData(); data.setWirecardFallbackAuthenticationModel(paymentConfigurationModel.getFallbackAuthentication()); response = getPaymentOperationStrategy().getOperation(returnRequestModel.getOrder().getPaymentMode(), WirecardPaymentTransactionConstants.REFUND_FOLLOW_ON) .doOperation(returnRequestModel, data); } } catch (WirecardPaymenException e) { LOGGER.error(e.getMessage(), e); } ReturnStatus returnStatus = wirecardPaymentService.getReturnStatus(response); wirecardPaymentService.setReturnRequestStatus(returnRequestModel, returnStatus); return returnStatus; }  }
DefaultWirecardPOExecutionService implements WirecardPOExecutionService { @Override public ReturnStatus executePaymentRefundOperation(ReturnRequestModel returnRequestModel, PaymentOperationData data) { Payment response = null; try { if (wirecardTransactionService.lookForAcceptedTransactions(returnRequestModel.getOrder(), PaymentTransactionType.CAPTURE)) { response = getPaymentOperationStrategy().getOperation(returnRequestModel.getOrder().getPaymentMode(), WirecardPaymentTransactionConstants.REFUND_FOLLOW_ON) .doOperation(returnRequestModel, data); } else if (wirecardTransactionService.lookForAcceptedTransactions(returnRequestModel.getOrder(), PaymentTransactionType.DEBIT)) { WirecardPaymentConfigurationModel paymentConfigurationModel = wirecardPaymentConfigurationService.getConfiguration(returnRequestModel.getOrder().getStore(), returnRequestModel.getOrder().getPaymentMode()); data = new PaymentOperationData(); data.setWirecardFallbackAuthenticationModel(paymentConfigurationModel.getFallbackAuthentication()); response = getPaymentOperationStrategy().getOperation(returnRequestModel.getOrder().getPaymentMode(), WirecardPaymentTransactionConstants.REFUND_FOLLOW_ON) .doOperation(returnRequestModel, data); } } catch (WirecardPaymenException e) { LOGGER.error(e.getMessage(), e); } ReturnStatus returnStatus = wirecardPaymentService.getReturnStatus(response); wirecardPaymentService.setReturnRequestStatus(returnRequestModel, returnStatus); return returnStatus; }  @Override OrderStatus executePaymentCaptureOperation(AbstractOrderModel abstractOrderModel, PaymentOperationData data); @Override ReturnStatus executePaymentRefundOperation(ReturnRequestModel returnRequestModel, PaymentOperationData data); @Override OrderStatus executeAuthorizationCancelOperation(AbstractOrderModel abstractOrderModel); @Required void setWirecardTransactionService(WirecardTransactionService wirecardTransactionService); @Required void setWirecardPaymentModeService(WirecardPaymentModeService wirecardPaymentModeService); @Required void setWirecardPaymentService(WirecardPaymentService wirecardPaymentService); @Required void setWirecardPaymentConfigurationService(WirecardPaymentConfigurationService wirecardPaymentConfigurationService); @Required void setPaymentOperationStrategy(PaymentOperationStrategy paymentOperationStrategy); }
DefaultWirecardPOExecutionService implements WirecardPOExecutionService { @Override public ReturnStatus executePaymentRefundOperation(ReturnRequestModel returnRequestModel, PaymentOperationData data) { Payment response = null; try { if (wirecardTransactionService.lookForAcceptedTransactions(returnRequestModel.getOrder(), PaymentTransactionType.CAPTURE)) { response = getPaymentOperationStrategy().getOperation(returnRequestModel.getOrder().getPaymentMode(), WirecardPaymentTransactionConstants.REFUND_FOLLOW_ON) .doOperation(returnRequestModel, data); } else if (wirecardTransactionService.lookForAcceptedTransactions(returnRequestModel.getOrder(), PaymentTransactionType.DEBIT)) { WirecardPaymentConfigurationModel paymentConfigurationModel = wirecardPaymentConfigurationService.getConfiguration(returnRequestModel.getOrder().getStore(), returnRequestModel.getOrder().getPaymentMode()); data = new PaymentOperationData(); data.setWirecardFallbackAuthenticationModel(paymentConfigurationModel.getFallbackAuthentication()); response = getPaymentOperationStrategy().getOperation(returnRequestModel.getOrder().getPaymentMode(), WirecardPaymentTransactionConstants.REFUND_FOLLOW_ON) .doOperation(returnRequestModel, data); } } catch (WirecardPaymenException e) { LOGGER.error(e.getMessage(), e); } ReturnStatus returnStatus = wirecardPaymentService.getReturnStatus(response); wirecardPaymentService.setReturnRequestStatus(returnRequestModel, returnStatus); return returnStatus; }  @Override OrderStatus executePaymentCaptureOperation(AbstractOrderModel abstractOrderModel, PaymentOperationData data); @Override ReturnStatus executePaymentRefundOperation(ReturnRequestModel returnRequestModel, PaymentOperationData data); @Override OrderStatus executeAuthorizationCancelOperation(AbstractOrderModel abstractOrderModel); @Required void setWirecardTransactionService(WirecardTransactionService wirecardTransactionService); @Required void setWirecardPaymentModeService(WirecardPaymentModeService wirecardPaymentModeService); @Required void setWirecardPaymentService(WirecardPaymentService wirecardPaymentService); @Required void setWirecardPaymentConfigurationService(WirecardPaymentConfigurationService wirecardPaymentConfigurationService); @Required void setPaymentOperationStrategy(PaymentOperationStrategy paymentOperationStrategy);  }