private Investor createInvestor(String email, String randomUUID, String ipAddress) { return new Investor(new Date(), email, randomUUID, ipAddress); }
public static InvestorMessageDTO build(Investor investor) { return new InvestorMessageDTO( investor.getCreationDate(), investor.getEmail(), investor.getEmailConfirmationToken(), investor.getWalletAddress(), investor.getPayInEtherAddress(), investor.getPayInBitcoinAddress(), investor.getRefundEtherAddress(), investor.getRefundBitcoinAddress(), investor.getIpAddress() ); }
if(!alreadySentList.contains(investor.getId())) { if(paymentLogService.hasInvestorInvested(investor.getId())) { StartSingleKycResponseDTO initiateResponse = initiateKyc(investor.getId(), null); if (initiateResponse.getIsSuccess()) { kycStartedList.add(investor.getId()); } else { LOG.error("Error while initiating KYC for investor {}", investor.getId()); errorList.add(investor.getId());
private void addExistinPaymentAdresses() { List<Investor> listInvestors = investorRepository.findAllByOrderByCreationDateAsc(); listInvestors.stream().forEach((investor) -> { long timestamp = investor.getCreationDate().toInstant().getEpochSecond(); ofNullable(investor.getPayInBitcoinAddress()).ifPresent((bitcoinAddress) -> { bitcoinMonitor.addPaymentAddressesForMonitoring(bitcoinAddress, timestamp); }); ofNullable(investor.getPayInEtherAddress()).ifPresent((etherAddress) -> { ethereumMonitor.addPaymentAddressesForMonitoring(etherAddress, timestamp); }); }); }
@RequestMapping(value = "/register/{emailConfirmationToken}/validate", method = GET) public ResponseEntity<?> isConfirmationTokenValid(@Valid @Size(max = Constants.UUID_CHAR_MAX_SIZE) @PathVariable("emailConfirmationToken") String emailConfirmationToken, @Context HttpServletRequest requestContext) throws BaseException { // Get IP address from request String ipAddress = IPAddressUtil.getIPAddress(requestContext); LOG.info("/validate called from {} with token {}", ipAddress, emailConfirmationToken); Optional<Investor> oInvestor = Optional.empty(); try { oInvestor = investorRepository.findOptionalByEmailConfirmationToken(emailConfirmationToken); } catch (Exception e) { throw new UnexpectedException(); } if (!oInvestor.isPresent()) { throw new ConfirmationTokenNotFoundException(); } if (oInvestor.get().getWalletAddress() == null) { return ResponseEntity.ok().build(); } else { AddressResponse addressResponse = new AddressResponse() .setBtc(oInvestor.get().getPayInBitcoinAddress()) .setEther(oInvestor.get().getPayInEtherAddress()); return new ResponseEntity<>(addressResponse, HttpStatus.OK); } }
Optional<Investor> oInvestor = investorRepository.findOptionalByEmail(registerRequest.getEmail()); if (oInvestor.isPresent()) { emailConfirmationToken = oInvestor.get().getEmailConfirmationToken(); } else { emailConfirmationToken = generateRandomUUID(); investorRepository.saveAndFlush(investor); LOG.debug("Investor saved to the database: email=" + investor.getEmail() + "), emailConfirmationToken=" + investor.getEmailConfirmationToken()); && oInvestor.get().getWalletAddress() != null && oInvestor.get().getPayInBitcoinAddress() != null && oInvestor.get().getPayInEtherAddress() != null) { SummaryEmailMessage summaryEmailMessage = new SummaryEmailMessage(build(oInvestor.get())); messageService.send(summaryEmailMessage);
context.setVariable("tokenSymbol", this.mailServiceConfigHolder.getTokenSymbol()); context.setVariable("walletAddress", oInvestor.get().getWalletAddress()); context.setVariable("payInEtherAddress", oInvestor.get().getPayInEtherAddress()); context.setVariable("payInBitcoinAddress", oInvestor.get().getPayInBitcoinAddress()); context.setVariable("refundEtherAddress", oInvestor.get().getRefundEtherAddress()); context.setVariable("refundBitcoinAddress", oInvestor.get().getRefundBitcoinAddress()); .from(oInvestor.get().getPayInEtherAddress()) .to(ImageType.PNG) .withSize(265, 200) .from(oInvestor.get().getPayInBitcoinAddress()) .to(ImageType.PNG) .withSize(265, 200)
if (oInvestor.get().getWalletAddress() != null) { return new ResponseEntity<>(HttpStatus.CONFLICT); investor.setWalletAddress(addPrefixEtherIfNotExist(walletAddress)) .setPayInBitcoinAddress(keyPairs.getPublicBtc()) .setPayInEtherAddress(keyPairs.getPublicEth()) .setRefundBitcoinAddress(refundBitcoinAddress) .setRefundEtherAddress(addPrefixEtherIfNotExist(refundEthereumAddress)); LOG.debug("Saving wallet for the investor (" + investor.getEmail() + ") with confirmation token (" + investor.getEmailConfirmationToken() + ")."); investorRepository.save(investor); } catch (Exception e) {
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Investor investor = (Investor) o; // TODO: is it enough? return Arrays.equals(email == null ? null : email.getBytes(), investor.getEmail() == null ? null : investor.getEmail().getBytes()); }
@Test public void testFindByEmailConfirmationToken() { String randomUUID = UUID.randomUUID().toString(); Investor i = new Investor(new Date(), "test@test.com", randomUUID); investorRepository.save(i); Optional<Investor> oInvestor = investorRepository.findOptionalByEmailConfirmationToken(randomUUID); assertTrue(oInvestor.isPresent()); assertTrue(oInvestor.get().getEmailConfirmationToken().equals(randomUUID)); }
@RabbitListener( bindings = @QueueBinding(value = @Queue(value = REGISTER_CONFIRMATION_EMAIL_QUEUE, autoDelete = "false"), exchange = @Exchange( value = ICONATOR_ENTRY_EXCHANGE, type = ExchangeTypes.TOPIC, ignoreDeclarationExceptions = "true", durable = "true" ), key = REGISTER_CONFIRMATION_EMAIL_ROUTING_KEY) ) public void receiveMessage(ConfirmationEmailMessage messageObject) { try { // TODO: 05.03.18 Guil: // Add a retry mechanism (e.g., for when the SMTP server is offline) mailService.sendConfirmationEmail( new Investor().setEmail(messageObject.getInvestor().getEmail()), messageObject.getEmailLinkUri() ); } catch (Exception e) { // TODO: 05.03.18 Guil: // Instead of just output the error, send to a structured log, // e.g., logstash or, also, send an email to an admin LOG.error("Email not sent.", e); } }
@Test public void testStartKycForAll() throws Exception { List<Investor> investorList = new ArrayList<>(); List<Long> kycStartedList = new ArrayList<>(); Investor investor1 = new Investor(new Date(), "investor1@test.com", "investor1token").setId(1); Investor investor2 = new Investor(new Date(), "investor2@test.com", "investor2token").setId(2); Investor investor3 = new Investor(new Date(), "investor3@test.com", "investor3token").setId(3); Investor investor4 = new Investor(new Date(), "investor4@test.com", "investor4token").setId(4); investorList.add(investor1); investorList.add(investor2); investorList.add(investor3); investorList.add(investor4); kycStartedList.add(2L); when(mockInvestorService.getAllInvestors()).thenReturn(investorList); when(mockKycInfoService.getAllInvestorIdWhereStartKycEmailSent()).thenReturn(kycStartedList); when(mockLinkCreatorService.getKycLink(anyLong())).thenReturn(KYC_LINK); when(mockPaymentLogService.hasInvestorInvested(1)).thenReturn(true); when(mockPaymentLogService.hasInvestorInvested(3)).thenReturn(false); when(mockPaymentLogService.hasInvestorInvested(4)).thenReturn(true); MvcResult result = mockMvc.perform(MockMvcRequestBuilders.post(KYC_START_ALL) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andDo(print()) .andReturn(); StartAllKycResponseDTO responseDTO = mapper.readValue(result.getResponse().getContentAsString(), StartAllKycResponseDTO.class); assertThat(responseDTO.getKycStartedList()).containsExactly(1L, 4L); assertThat(responseDTO.getErrorList()).isEmpty(); }
@Test public void testFindByPayInEtherPublicKey() { Investor i = createInvestor(); investorRepository.save(i); Optional<Investor> oInvestor = investorRepository.findOptionalByPayInEtherAddressIgnoreCase("payInEther1"); assertTrue(oInvestor.isPresent()); assertTrue(oInvestor.filter((investor) -> investor.getPayInEtherAddress().equals("payInEther1")).isPresent()); }
@Test public void testFindByPayInBitcoinPublicKey() { Investor i = createInvestor(); investorRepository.save(i); Optional<Investor> oInvestor = investorRepository.findOptionalByPayInBitcoinAddress("payInBitcoin1"); assertTrue(oInvestor.isPresent()); assertTrue(oInvestor.filter((investor) -> investor.getPayInBitcoinAddress().equals("payInBitcoin1")).isPresent()); }
protected String getConfirmationEmailTokenByEmail(String email) throws Exception { Optional<Investor> oInvestor = investorRepository.findOptionalByEmail(email); if (oInvestor.isPresent()) { return oInvestor.get().getEmailConfirmationToken(); } else { throw new Exception("Email not found!"); } }
public void sendSummaryEmail(Investor investor) throws EmailNotSentException, EmailNotPreparedException { Optional<MimeMessage> oMessageContainer = createMessageContainer(investor.getEmail()); Optional<MimeMessageHelper> oMessage = prepareMessage(oMessageContainer, investor.getEmail(), this.mailServiceConfigHolder.getSummaryEmailSubject(), MailType.SUMMARY_EMAIL); this.mailContentBuilder.buildSummaryEmail(oMessage, Optional.ofNullable(investor)); if (this.mailServiceConfigHolder.isEnabled()) { sendMail(oMessage, MailType.SUMMARY_EMAIL); } else { LOG.info("Skip sending {} email to {}", MailType.SUMMARY_EMAIL, investor.getEmail()); } }
ethereumMonitor.addPaymentAddressesForMonitoring(investor.getPayInEtherAddress(), null); ethereumMonitor.start(); web3j, credentials, investor.getPayInEtherAddress(), fundsAmountToSendInETH, Convert.Unit.ETHER).send();
private Investor createInvestor() { String randomUUID = UUID.randomUUID().toString(); return new Investor(new Date(), "test@test.com", randomUUID, "wallet-address-12345", "payInEther1", "payInBitcoin1", "refundEther1", "refundEther2", "127.0.0.1"); }
public void sendConfirmationEmail(Investor investor, String confirmationEmaiLink) throws EmailNotSentException, EmailNotPreparedException { Optional<MimeMessage> oMessageContainer = createMessageContainer(investor.getEmail()); Optional<MimeMessageHelper> oMessage = prepareMessage(oMessageContainer, investor.getEmail(), this.mailServiceConfigHolder.getConfirmationEmailSubject(), MailType.CONFIRMATION_EMAIL); this.mailContentBuilder.buildConfirmationEmail(oMessage, confirmationEmaiLink); if (this.mailServiceConfigHolder.isEnabled()) { sendMail(oMessage, MailType.CONFIRMATION_EMAIL); } else { LOG.info("Skip sending {} email to {}, link: {}", MailType.CONFIRMATION_EMAIL, investor.getEmail(), confirmationEmaiLink); } }
@RabbitListener( bindings = @QueueBinding(value = @Queue(value = KYC_REMINDER_EMAIL_SENT_QUEUE, autoDelete = "false"), exchange = @Exchange( value = ICONATOR_ENTRY_EXCHANGE, type = ExchangeTypes.TOPIC, ignoreDeclarationExceptions = "true", durable = "true" ), key = KYC_REMINDER_EMAIL_SENT_ROUTING_KEY) ) public void receiveMessage(KycReminderEmailSentMessage message) { try { long investorId = investorService.getInvestorByEmail(message.getEmailAddress()).getId(); kycInfoService.increaseNumberOfRemindersSent(investorId); LOG.debug("Increased numberOfRemindersSent for investor with ID {} by 1", investorId); } catch (InvestorNotFoundException e) { LOG.error("Investor with address {} not found", message.getEmailAddress()); } }