DefaultCapturedOrderNotificationProcessorStrategy implements OrderNotificationProcessorStrategy { @Override public void processNotificationMessage(final PaymentTransactionModel paymentTransactionModel, final OrderNotificationMessage orderNotificationMessage) { final PaymentInfoModel paymentInfoModel = paymentTransactionModel.getInfo(); final String paymentTypeCode = orderNotificationMessage.getPaymentReply().getMethodCode(); if (shouldCreateCapturePaymentTransactionEntry(paymentInfoModel, paymentTypeCode)) { transactionTemplate.execute(transactionStatus -> { worldpayPaymentTransactionService.createCapturedPaymentTransactionEntry(paymentTransactionModel, orderNotificationMessage); return null; }); } else { final List<PaymentTransactionEntryModel> paymentTransactionEntries = worldpayPaymentTransactionService.getPendingPaymentTransactionEntriesForType(paymentTransactionModel, CAPTURE); transactionTemplate.execute(transactionStatus -> { updatePaymentTransactionEntry(paymentTransactionModel, paymentTransactionEntries, ACCEPTED.name()); worldpayPaymentTransactionService.updateEntriesAmount(paymentTransactionEntries, orderNotificationMessage.getPaymentReply().getAmount()); return null; }); } } DefaultCapturedOrderNotificationProcessorStrategy(final TransactionOperations transactionTemplate, final ModelService modelService, final WorldpayPaymentTransactionService worldpayPaymentTransactionService); @Override void processNotificationMessage(final PaymentTransactionModel paymentTransactionModel, final OrderNotificationMessage orderNotificationMessage);  }
@Test public void processNotificationMessage_shouldNotCreateCapturedPaymentTransactionEntryAndUpdateEntriesAmount_whenMessageIsNotAPM() { when(paymentTransactionModelMock.getInfo().getIsApm()).thenReturn(false); testObj.processNotificationMessage(paymentTransactionModelMock, orderNotificationMessageMock); verify(worldpayPaymentTransactionServiceMock, never()).createCapturedPaymentTransactionEntry(paymentTransactionModelMock, orderNotificationMessageMock); verify(worldpayPaymentTransactionServiceMock).updateEntriesStatus(pendingCaptureTransactionEntries, ACCEPTED.name()); verify(worldpayPaymentTransactionServiceMock).updateEntriesAmount(pendingCaptureTransactionEntries, orderNotificationMessageMock.getPaymentReply().getAmount()); verify(modelServiceMock).save(paymentTransactionModelMock); }
@Test public void processNotificationMessage_shouldCreateCapturedPaymentTransactionEntry_whenMessageIsAnAPMButIsNotKlarnaSSL() { when(paymentReplyMock.getMethodCode()).thenReturn(PaymentType.CASHU.getMethodCode()); when(paymentTransactionModelMock.getInfo().getIsApm()).thenReturn(true); testObj.processNotificationMessage(paymentTransactionModelMock, orderNotificationMessageMock); verify(worldpayPaymentTransactionServiceMock).createCapturedPaymentTransactionEntry(paymentTransactionModelMock, orderNotificationMessageMock); verify(worldpayPaymentTransactionServiceMock, never()).updateEntriesStatus(pendingCaptureTransactionEntries, ACCEPTED.name()); verify(worldpayPaymentTransactionServiceMock, never()).updateEntriesAmount(pendingCaptureTransactionEntries, orderNotificationMessageMock.getPaymentReply().getAmount()); verify(modelServiceMock, never()).save(paymentTransactionModelMock); }
@Test public void processNotificationMessage_shouldNotCreateCapturedPaymentTransactionEntry_whenMessageIsAnAPMAndIsKlarnaSSL() { when(paymentReplyMock.getMethodCode()).thenReturn(PaymentType.KLARNASSL.getMethodCode()); when(paymentTransactionModelMock.getInfo().getIsApm()).thenReturn(true); testObj.processNotificationMessage(paymentTransactionModelMock, orderNotificationMessageMock); verify(worldpayPaymentTransactionServiceMock, never()).createCapturedPaymentTransactionEntry(paymentTransactionModelMock, orderNotificationMessageMock); verify(worldpayPaymentTransactionServiceMock).updateEntriesStatus(pendingCaptureTransactionEntries, ACCEPTED.name()); verify(worldpayPaymentTransactionServiceMock).updateEntriesAmount(pendingCaptureTransactionEntries, orderNotificationMessageMock.getPaymentReply().getAmount()); verify(modelServiceMock).save(paymentTransactionModelMock); }