DefaultWorldpayPaymentTransactionService implements WorldpayPaymentTransactionService { @Override public PaymentTransactionModel createPaymentTransaction(final boolean apmOpen, final String merchantCode, final CommerceCheckoutParameter commerceCheckoutParameter) { final PaymentTransactionModel paymentTransactionModel = modelService.create(PaymentTransactionModel.class); final AbstractOrderModel abstractOrderModel = commerceCheckoutParameter.getCart() == null ? commerceCheckoutParameter.getOrder() : commerceCheckoutParameter.getCart(); final String worldpayOrderCode = abstractOrderModel.getWorldpayOrderCode(); paymentTransactionModel.setCode(worldpayOrderCode); paymentTransactionModel.setRequestId(worldpayOrderCode); paymentTransactionModel.setRequestToken(merchantCode); paymentTransactionModel.setPaymentProvider(commerceCheckoutParameter.getPaymentProvider()); paymentTransactionModel.setOrder(abstractOrderModel); paymentTransactionModel.setCurrency(abstractOrderModel.getCurrency()); paymentTransactionModel.setInfo(commerceCheckoutParameter.getPaymentInfo()); paymentTransactionModel.setApmOpen(apmOpen); paymentTransactionModel.setPlannedAmount(commerceCheckoutParameter.getAuthorizationAmount()); if (abstractOrderModel instanceof CartModel) { final String shopperBankCode = ((CartModel) abstractOrderModel).getShopperBankCode(); final WorldpayBankConfigurationModel activeBankConfigurationsForCode = worldpayBankConfigurationService.getBankConfigurationForBankCode(shopperBankCode); paymentTransactionModel.setWorldpayBank(activeBankConfigurationsForCode); } modelService.save(paymentTransactionModel); return paymentTransactionModel; }  @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 shouldCreatePaymentTransaction() { testObj.createPaymentTransaction(true, MERCHANT_CODE, commerceCheckoutParameterMock); verify(paymentTransactionModelMock).setCode(WORLDPAY_ORDER_CODE); verify(paymentTransactionModelMock).setRequestId(WORLDPAY_ORDER_CODE); verify(paymentTransactionModelMock).setRequestToken(MERCHANT_CODE); verify(paymentTransactionModelMock).setPaymentProvider(PAYMENT_PROVIDER); verify(paymentTransactionModelMock).setOrder(cartModelMock); verify(paymentTransactionModelMock).setCurrency(currencyModelMock); verify(paymentTransactionModelMock).setInfo(paymentInfoModelMock); verify(paymentTransactionModelMock).setApmOpen(true); verify(paymentTransactionModelMock).setPlannedAmount(BigDecimal.TEN); verify(paymentTransactionModelMock).setWorldpayBank(worldpayBankConfigurationMock); verify(modelServiceMock).save(paymentTransactionModelMock); }
@Test public void shouldNotSetWorldpayBankIfNotACart() { when(commerceCheckoutParameterMock.getCart()).thenReturn(null); when(commerceCheckoutParameterMock.getOrder()).thenReturn(abstractOrderMock); testObj.createPaymentTransaction(true, MERCHANT_CODE, commerceCheckoutParameterMock); verify(paymentTransactionModelMock, never()).setWorldpayBank(any(WorldpayBankConfigurationModel.class)); }
@Test public void shouldCreateTransactionWillNullBankCodeIfMissing() { when(worldpayBankConfigurationServiceMock.getBankConfigurationForBankCode(null)).thenReturn(null); testObj.createPaymentTransaction(true, MERCHANT_CODE, commerceCheckoutParameterMock); verify(paymentTransactionModelMock).setWorldpayBank(worldpayBankConfigurationMock); verify(modelServiceMock).save(paymentTransactionModelMock); }