DefaultWorldpayPaymentTransactionService implements WorldpayPaymentTransactionService { @Override public PaymentTransactionEntryModel createNotPendingCancelOrderTransactionEntry(final PaymentTransactionModel paymentTransactionModel) { final PaymentTransactionEntryModel paymentTransactionEntryModel = modelService.create(PaymentTransactionEntryModel.class); final AbstractOrderModel orderModel = paymentTransactionModel.getOrder(); paymentTransactionEntryModel.setCode(entryCodeStrategy.generateCode(paymentTransactionModel)); paymentTransactionEntryModel.setType(CANCEL); paymentTransactionEntryModel.setPaymentTransaction(paymentTransactionModel); paymentTransactionEntryModel.setTime(Date.from(Instant.now())); paymentTransactionEntryModel.setRequestId(orderModel.getWorldpayOrderCode()); paymentTransactionEntryModel.setAmount(BigDecimal.valueOf(orderModel.getTotalPrice())); paymentTransactionEntryModel.setRequestToken(paymentTransactionModel.getRequestToken()); paymentTransactionEntryModel.setTransactionStatus(TransactionStatus.REJECTED.name()); paymentTransactionEntryModel.setTransactionStatusDetails(TransactionStatusDetails.PROCESSOR_DECLINE.name()); paymentTransactionEntryModel.setCurrency(orderModel.getCurrency()); paymentTransactionEntryModel.setPending(false); modelService.save(paymentTransactionEntryModel); return paymentTransactionEntryModel; }  @Override boolean areAllPaymentTransactionsAcceptedForType(final OrderModel order, final PaymentTransactionType paymentTransactionType); @Override boolean isAnyPaymentTransactionApmOpenForOrder(final OrderModel order); @Override boolean isPaymentTransactionPending(final PaymentTransactionModel paymentTransaction, final PaymentTransactionType paymentTransactionType); @Override List<PaymentTransactionEntryModel> filterPaymentTransactionEntriesOfType(final PaymentTransactionModel paymentTransaction,
                                                                                    final PaymentTransactionType paymentTransactionType); @Override List<PaymentTransactionEntryModel> getPendingPaymentTransactionEntriesForType(final PaymentTransactionModel paymentTransactionModel,
                                                                                         final PaymentTransactionType paymentTransactionType); @Override List<PaymentTransactionEntryModel> getNotPendingPaymentTransactionEntriesForType(final PaymentTransactionModel paymentTransactionModel,
                                                                                            final PaymentTransactionType paymentTransactionType); @Override boolean isPreviousTransactionCompleted(final String worldpayOrderCode, final PaymentTransactionType paymentTransactionType, final OrderModel orderModel); @Override PaymentTransactionEntryModel createCapturedPaymentTransactionEntry(final PaymentTransactionModel paymentTransaction, final OrderNotificationMessage orderNotificationMessage); @Override PaymentTransactionEntryModel createPendingAuthorisePaymentTransactionEntry(final PaymentTransactionModel paymentTransaction,
                                                                                      final String merchantCode,
                                                                                      final CartModel cartModel,
                                                                                      final BigDecimal authorisedAmount); @Override PaymentTransactionEntryModel createNonPendingAuthorisePaymentTransactionEntry(final PaymentTransactionModel paymentTransaction,
                                                                                         final String merchantCode,
                                                                                         final AbstractOrderModel abstractOrderModel,
                                                                                         final BigDecimal authorisedAmount); @Override PaymentTransactionModel createPaymentTransaction(final boolean apmOpen, final String merchantCode, final CommerceCheckoutParameter commerceCheckoutParameter); @Override PaymentTransactionModel getPaymentTransactionFromCode(final String transactionCode); @Override void updateEntriesStatus(final List<PaymentTransactionEntryModel> paymentTransactionEntries, final String transactionStatus); @Override void addRiskScore(final PaymentTransactionModel paymentTransactionModel, final PaymentReply paymentReply); @Override void addAavFields(final PaymentTransactionEntryModel paymentTransactionEntryModel, final PaymentReply paymentReply); @Override void updateEntriesAmount(final List<PaymentTransactionEntryModel> transactionEntries, final Amount amount); @Override boolean isAuthorisedAmountCorrect(final OrderModel order); @Override PaymentTransactionEntryModel createNotPendingCancelOrderTransactionEntry(final PaymentTransactionModel paymentTransactionModel); @Override PaymentTransactionEntryModel createNotPendingSettledPaymentTransactionEntry(final PaymentTransactionModel paymentTransactionModel, final OrderNotificationMessage orderNotificationMessage); @Required void setPaymentTransactionDependency(final Map<PaymentTransactionType, PaymentTransactionType> paymentTransactionDependency); @Required void setCommonI18NService(final CommonI18NService commonI18NService); @Required void setModelService(final ModelService modelService); @Required void setEntryCodeStrategy(final EntryCodeStrategy entryCodeStrategy); @Required void setWorldpayPaymentTransactionDao(final WorldpayPaymentTransactionDao worldpayPaymentTransactionDao); @Required void setWorldpayRiskScoreConverter(final Converter<RiskScore, WorldpayRiskScoreModel> worldpayRiskScoreConverter); @Required void setWorldpayAavResponsePopulator(final Populator<PaymentReply, WorldpayAavResponseModel> worldpayAavResponsePopulator); @Required void setConfigurationService(final ConfigurationService configurationService); @Required void setWorldpayOrderService(final WorldpayOrderService worldpayOrderService); @Required void setWorldpayBankConfigurationService(final WorldpayBankConfigurationLookupService worldpayBankConfigurationService);  }
@Test public void createNotPendingCancelOrderTransactionEntry_ShouldCreateCancelTransactionEntryWithPendingSetToFalse() { when(paymentTransactionModelMock.getOrder()).thenReturn(abstractOrderMock); when(abstractOrderMock.getWorldpayOrderCode()).thenReturn(WORLDPAY_ORDER_CODE); when(abstractOrderMock.getCurrency()).thenReturn(currencyModelMock); when(abstractOrderMock.getTotalPrice()).thenReturn(BigDecimal.TEN.doubleValue()); when(paymentTransactionModelMock.getRequestToken()).thenReturn(REQUEST_TOKEN); when(modelServiceMock.create(PaymentTransactionEntryModel.class)).thenReturn(new PaymentTransactionEntryModel()); final PaymentTransactionEntryModel result = testObj.createNotPendingCancelOrderTransactionEntry(paymentTransactionModelMock); assertThat(result.getCode()).isEqualTo(TRANSACTION_ENTRY_CODE); assertThat(result.getPaymentTransaction()).isEqualTo(paymentTransactionModelMock); assertThat(result.getTime()).isNotNull(); assertThat(result.getRequestId()).isEqualTo(WORLDPAY_ORDER_CODE); assertThat(result.getAmount().doubleValue()).isEqualTo(BigDecimal.TEN.doubleValue()); assertThat(result.getRequestToken()).isEqualTo(REQUEST_TOKEN); assertThat(result.getTransactionStatus()).isEqualTo(REJECTED.name()); assertThat(result.getTransactionStatusDetails()).isEqualTo(PROCESSOR_DECLINE.name()); assertThat(result.getCurrency()).isEqualTo(currencyModelMock); assertThat(result.getPending()).isFalse(); assertThat(result.getType()).isEqualTo(CANCEL); verify(modelServiceMock).save(result); }