DefaultWorldpayPaymentInfoService implements WorldpayPaymentInfoService { @Override public void setPaymentInfoModel(final PaymentTransactionModel paymentTransactionModel, final AbstractOrderModel orderModel, final OrderNotificationMessage orderNotificationMessage) throws WorldpayConfigurationException { final PaymentInfoModel paymentInfo = getPaymentInfoModel(paymentTransactionModel, orderNotificationMessage); attachPaymentInfoModel(paymentTransactionModel, orderModel, paymentInfo); updateStoredCredentialsOnPaymentInfo(paymentInfo,orderNotificationMessage); removePaymentInfoWhenCreatingNewOneFromNotification(orderModel); } DefaultWorldpayPaymentInfoService(final ModelService modelService, final EnumerationService enumerationService, final APMConfigurationLookupService apmConfigurationLookupService, final ConfigurationService configurationService, final WorldpayMerchantInfoService worldpayMerchantInfoService); @Override void savePaymentType(final PaymentTransactionModel transactionModel, final String methodCode); @Override void setPaymentInfoModel(final PaymentTransactionModel paymentTransactionModel, final AbstractOrderModel orderModel, final OrderNotificationMessage orderNotificationMessage); @Override void updateAndAttachPaymentInfoModel(final PaymentTransactionModel paymentTransactionModel, final AbstractOrderModel orderModel, final PaymentInfoModel paymentInfoModel); @Override WorldpayAPMPaymentInfoModel createWorldpayApmPaymentInfo(final PaymentTransactionModel paymentTransactionModel); @Override PaymentInfoModel createPaymentInfo(final CartModel cartModel); @Override PaymentInfoModel createPaymentInfoGooglePay(final CartModel cartModel, final GooglePayAdditionalAuthInfo googleAuthInfo); @Override PaymentInfoModel createPaymentInfoApplePay(final CartModel cartModel, final ApplePayAdditionalAuthInfo applePayAdditionalAuthInfo); @Override CreditCardPaymentInfoModel createCreditCardPaymentInfo(final AbstractOrderModel abstractOrderModel, final TokenReply tokenReply, final boolean saveCard, final String merchantId); @Override void setCreditCardType(final CreditCardPaymentInfoModel creditCardPaymentInfoModel, final PaymentReply paymentReply); @Override Optional<CreditCardPaymentInfoModel> updateCreditCardPaymentInfo(final CartModel cartModel, final UpdateTokenServiceRequest updateTokenServiceRequest); @Override void setTransactionIdentifierOnPaymentInfo(final PaymentInfoModel paymentInfoModel, final String transactionIdentifier);  }
@Test public void shouldUseExistingCreditCardForTokenInformationAndSaveItToPaymentTransactionAndOrderWhenEventIsMatch() throws WorldpayConfigurationException { when(tokenReplyMock.getTokenDetails().getTokenEvent()).thenReturn(MATCH); testObj.setPaymentInfoModel(paymentTransactionModelMock, orderModelMock, orderNotificationMessageMock); verifyCardNotCreated(); }
@Test public void shouldUseExistingCreditCardForTokenInformationAndSaveItToPaymentTransactionAndOrderWhenEventIsConflict() throws WorldpayConfigurationException { when(tokenReplyMock.getTokenDetails().getTokenEvent()).thenReturn(CONFLICT); testObj.setPaymentInfoModel(paymentTransactionModelMock, orderModelMock, orderNotificationMessageMock); verifyCardNotCreated(); }
@Test public void shouldNotCreateCreditCardPaymentInfoModelWhenPaymentTransactionHasACreditCardPaymentInfoThatHasASubscriptionId() throws WorldpayConfigurationException { when(paymentTransactionPaymentInfoModelMock.getIsApm()).thenReturn(false); when(paymentTransactionModelMock.getRequestId()).thenReturn(WORLDPAY_ORDER_CODE); when(orderNotificationMessageMock.getTokenReply()).thenReturn(null); when(paymentTransactionModelMock.getInfo()).thenReturn(creditCardPaymentInfoModelMock); when(creditCardPaymentInfoModelMock.getSubscriptionId()).thenReturn(PAYMENT_TOKEN_ID); testObj.setPaymentInfoModel(paymentTransactionModelMock, orderModelMock, orderNotificationMessageMock); verify(modelServiceMock, never()).save(any(CreditCardPaymentInfoModel.class)); verify(orderModelMock).setPaymentInfo(creditCardPaymentInfoModelMock); verify(paymentTransactionModelMock).setInfo(creditCardPaymentInfoModelMock); verify(modelServiceMock).saveAll(orderModelMock, paymentTransactionModelMock); }
@Test public void shouldNotCreateCreditCardPaymentInfoModelWhenPaymentTransactionHasACreditCardPaymentInfoThatDoesNotHaveSubscriptionId() throws WorldpayConfigurationException { when(paymentTransactionPaymentInfoModelMock.getIsApm()).thenReturn(false); when(paymentTransactionModelMock.getRequestId()).thenReturn(WORLDPAY_ORDER_CODE); when(orderNotificationMessageMock.getTokenReply()).thenReturn(null); when(paymentTransactionModelMock.getInfo()).thenReturn(creditCardPaymentInfoModelMock); when(creditCardPaymentInfoModelMock.getSubscriptionId()).thenReturn(null); when(modelServiceMock.clone(paymentTransactionPaymentInfoModelMock, WorldpayAPMPaymentInfoModel.class)).thenReturn(worldpayAPMPaymentInfoModelMock); testObj.setPaymentInfoModel(paymentTransactionModelMock, orderModelMock, orderNotificationMessageMock); verify(modelServiceMock).clone(any(CreditCardPaymentInfoModel.class),eq(CreditCardPaymentInfoModel.class)); verify(orderModelMock).setPaymentInfo(creditCardPaymentInfoModelMock); verify(paymentTransactionModelMock).setInfo(creditCardPaymentInfoModelMock); verify(modelServiceMock).saveAll(orderModelMock, paymentTransactionModelMock); }