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; } }
private PaymentLog createRefundEntryForAmount( PaymentLog paymentLog, RefundReason reason, BigInteger cryptocurrencyAmount, BigDecimal usdAmount) throws RefundEntryAlreadyExistsException { EligibleForRefund refund = eligibleForRefundService.save( new EligibleForRefund(reason, cryptocurrencyAmount, usdAmount, paymentLog.getCurrency(), paymentLog.getInvestor(), paymentLog.getTransactionId())); paymentLog.setEligibleForRefund(refund); return paymentLog; }
LOG.info("{} transaction {} generated a overflow of {} USD", paymentLog.getCurrency().name(), paymentLog.getTransactionId(), result.getOverflow()); try { paymentLog = createRefundEntryForOverflow(paymentLog, result.getOverflow()); } catch (RefundEntryAlreadyExistsException e) { LOG.error("Couldn't save overflow USD {} as refund beacause a refund entry for " + "transaction {} already existed", result.getOverflow(), paymentLog.getTransactionId());
"for that transaction.", paymentLog.getTransactionId(), e); } catch (Throwable t) { LOG.error("Error processing transaction.", t);