@Bean public PaymentLogService paymentLogService() { return new PaymentLogService(); } }
/** * Fetches the payment log corresponding to the given transaction id if it is in status * {@link TransactionStatus#PENDING}. If successful it also updates the payment log status to * {@link TransactionStatus#BUILDING} before returning it. * @param transactionId The transaction id for which the corresponding payment log should be * retrieved. * @return the payment log for given transaction id if it is in status * {@link TransactionStatus#PENDING}. Null otherwise. * @throws PaymentLogNotFoundException if no payment log exists for the given transaction id. */ @Transactional(propagation = Propagation.REQUIRED) public PaymentLog getPendingPaymentLogForProcessing(String transactionId) throws PaymentLogNotFoundException { try { PaymentLog paymentLog = paymentLogService.getPaymentLog(transactionId); if (paymentLog.getTransactionStatus() != TransactionStatus.PENDING) { return null; } else { paymentLog.setTransactionStatus(TransactionStatus.BUILDING); return paymentLogService.updateProcessedDateAndSave(paymentLog); } } catch (OptimisticLockingFailureException e) { // If payment log was just now updated by another monitor instance // the payment log does not need to be reprocessed. return null; } }
@Transactional(propagation = Propagation.REQUIRED) public PaymentLog createNewPaymentLog(TransactionAdapter tx, TransactionStatus transactionStatus) throws MissingTransactionInformationException { try { return paymentLogService.save(new PaymentLog( tx.getTransactionId(), tx.getCurrencyType(), transactionStatus)); } catch (DataIntegrityViolationException e) { // The payment log was probably created by another instance just now. // This is not an error because the other instance will process the transaction. return null; } }
protected void confirmTransaction(TransactionAdapter tx) { try { LOG.info("Setting status of transaction {} to confirmed.", tx.getTransactionId()); PaymentLog paymentLog = paymentLogService.getPaymentLog(tx.getTransactionId()); paymentLog.setTransactionStatus(TransactionStatus.CONFIRMED); paymentLogService.saveAndCommit(paymentLog); } catch (MissingTransactionInformationException e) { LOG.error("Couldn't set payment log status to confirmed because the transaction id " + "could not be retrieved from the {} transaction.", tx.getCurrencyType(), e); } catch (PaymentLogNotFoundException e) { try { LOG.error("No payment log existed for {} transaction {} when trying to set the " + "transaction status to CONFIRMED", tx.getCurrencyType(), tx.getTransactionId(), e); } catch (MissingTransactionInformationException ignore) { } } }
if(paymentLogService.hasInvestorInvested(investor.getId())) { StartSingleKycResponseDTO initiateResponse = initiateKyc(investor.getId(), null); if (initiateResponse.getIsSuccess()) {
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) public PaymentLog createRefundEntryForPaymentLogAndCommit( PaymentLog paymentLog, RefundReason reason) throws RefundEntryAlreadyExistsException { paymentLog = createRefundEntryForAmount(paymentLog, reason, paymentLog.getCryptocurrencyAmount(), paymentLog.getUsdAmount()); return paymentLogService.updateProcessedDateAndSave(paymentLog); }
private PaymentLog createPaymentLog(BigDecimal usdAmount, Date blockTime, Investor investor) { String txId = "txId0"; java.util.Date creationDate = new java.util.Date(); CurrencyType currency = CurrencyType.ETH; // Value doesn't matter, only the amount in usd matters. BigInteger weiAmount = BigInteger.ONE; BigInteger tomicsAmount = null; PaymentLog paymentLog = null; boolean succeeded = false; int i = 1; while (!succeeded) { try { paymentLog = paymentLogService.saveTransactionless( new PaymentLog(txId, creationDate, currency, blockTime, weiAmount, USD_FX_RATE, usdAmount, investor, tomicsAmount, TransactionStatus.BUILDING)); succeeded = true; } catch (DataIntegrityViolationException ignore) { } txId = "txId" + i++; } return paymentLog; }
private PaymentLog updateBuildingPaymentLog(TransactionAdapter tx, PaymentLog paymentLog) throws RefundEntryAlreadyExistsException { if (paymentLog == null) return null; RefundReason reason = null; try { reason = RefundReason.TRANSACTION_VALUE_MISSING; paymentLog.setCryptocurrencyAmount(tx.getTransactionValue()); BigDecimal valueInMainUnit = tx.getTransactionValueInMainUnit(); reason = RefundReason.INVESTOR_MISSING; paymentLog.setInvestor(tx.getAssociatedInvestor()); reason = RefundReason.BLOCK_TIME_MISSING; paymentLog.setBlockTime(tx.getBlockTime()); reason = RefundReason.FX_RATE_MISSING; BigDecimal fxRate = getUSDExchangeRate(tx.getBlockTime().toInstant(), tx.getCurrencyType()); paymentLog.setUsdFxRate(fxRate); paymentLog.setUsdAmount(valueInMainUnit.multiply(fxRate)); } catch (MissingTransactionInformationException e) { monitorService.createRefundEntryForPaymentLogAndCommit(paymentLog, reason); return null; } return paymentLogService.saveAndCommit(paymentLog); }
@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(); }
@Transactional(propagation = Propagation.REQUIRED) public PaymentLog sendTransactionReceivedMessageAndSavePaymentLog(PaymentLog paymentLog, BigDecimal amountInMainUnit, String transactionUrl) { messageService.send(new TransactionReceivedEmailMessage( MessageDTOHelper.build(paymentLog.getInvestor()), amountInMainUnit, paymentLog.getCurrency(), transactionUrl)); paymentLog.setTransactionReceivedMessageSent(true); return paymentLogService.updateProcessedDateAndSave(paymentLog); }
PaymentLog paymentLog = paymentLogService.getPaymentLog(transactionId); boolean confirmationMailSent = paymentLog.isTransactionReceivedMessageSent(); boolean notPending = paymentLog.getTransactionStatus() != TransactionStatus.PENDING; return paymentLogService.updateProcessedDateAndSave(paymentLog);
@Bean public PaymentLogService paymentLogService() { return new PaymentLogService(); }
@Transactional(propagation = Propagation.REQUIRED) public PaymentLog sendAllocationMessageAndSavePaymentLog(PaymentLog paymentLog, BigDecimal amountInMainUnit, String transactionUrl) { messageService.send(new TokensAllocatedEmailMessage( MessageDTOHelper.build(paymentLog.getInvestor()), amountInMainUnit, paymentLog.getCurrency(), transactionUrl, convertTomicsToTokens(paymentLog.getAllocatedTomics()))); paymentLog.setAllocationMessageSent(true); return paymentLogService.updateProcessedDateAndSave(paymentLog); }
PaymentLog paymentLog = paymentLogService.getPaymentLog(transactionId); boolean pending = paymentLog.getTransactionStatus() == TransactionStatus.PENDING; boolean allocationMailSent = paymentLog.isAllocationMessageSent(); return paymentLogService.updateProcessedDateAndSave(paymentLog);
return paymentLogService.updateProcessedDateAndSave(paymentLog); } else { throw new NoTierAtDateException();