@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); }
PaymentLog allocateTokensWithRetries(PaymentLog paymentLog) throws Throwable { if (paymentLog.getUsdAmount() == null) { throw new IllegalArgumentException("PaymentLog's amount in USD must not be null."); } if (paymentLog.getBlockTime() == null) { throw new IllegalArgumentException("PaymentLog's block time must not be null."); } LOG.debug("Calling token allocation with {} USD for {} transaction {}.", paymentLog.getUsdAmount().toPlainString(), paymentLog.getCurrency(), paymentLog.getTransactionId()); try { // Retry as long as there are database locking exceptions. PaymentLog updatedPaymentLog = retryer.call( () -> monitorService.allocateTokens(paymentLog)); LOG.debug("Allocated {} tomics for {} transaction {}.", updatedPaymentLog.getAllocatedTomics(), updatedPaymentLog.getCurrency(), updatedPaymentLog.getTransactionId()); return updatedPaymentLog; } catch (Throwable e) { LOG.error("Failed to distribute payment to tiers for {} transaction {}.", paymentLog.getCurrency().name(), paymentLog.getTransactionId(), e.getCause()); RefundReason reason = RefundReason.TOKEN_ALLOCATION_FAILED; monitorService.createRefundEntryForPaymentLogAndCommit(paymentLog, reason); throw e; } }
BigDecimal usd = paymentLog.getUsdAmount(); Optional<SaleTier> oTier = saleTierService.getTierAtDate(blockTime); if (oTier.isPresent()) {
if (paymentLog == null) return; // no processing required. if (isAmountInsufficient(paymentLog.getUsdAmount())) { monitorService.createRefundEntryForPaymentLogAndCommit(paymentLog, RefundReason.INSUFFICIENT_PAYMENT_AMOUNT); paymentLog, tx.getTransactionValueInMainUnit(), tx.getTransactionUrl()); LOG.info("Transaction processed: {} {} / {} USD / {} FX / investor id {} / Time: {} / Tomics Amount {}", tx.getTransactionValueInMainUnit(), tx.getCurrencyType().name(), paymentLog.getUsdAmount(), paymentLog.getUsdFxRate(), tx.getAssociatedInvestor(), paymentLog.getCreateDate(), paymentLog.getAllocatedTomics());