@Override public String getProcessedPaymentRate() { final Currency currency = getProcessedCurrency(); if (currency == null) { return null; } // If there were multiple payments (and refunds) we pick chose the last one DateTime latestPaymentDate = null; final Iterator<InvoicePayment> paymentIterator = invoice.getPayments().iterator(); while (paymentIterator.hasNext()) { final InvoicePayment cur = paymentIterator.next(); latestPaymentDate = latestPaymentDate != null && latestPaymentDate.isAfter(cur.getPaymentDate()) ? latestPaymentDate : cur.getPaymentDate(); } try { final CurrencyConversion conversion = currencyConversionApi.getCurrencyConversion(currency, latestPaymentDate); for (final Rate rate : conversion.getRates()) { if (rate.getCurrency() == getCurrency()) { return rate.getValue().toString(); } } } catch (final CurrencyConversionException e) { logger.warn("Failed to retrieve currency conversion rates for currency='{}', dateConversion='{}'", currency, latestPaymentDate, e); return null; } logger.warn("Failed to retrieve currency conversion rates for currency='{}', dateConversion='{}'", currency, latestPaymentDate); return null; }
public static InvoicePayment createAndPersistPayment(final InvoiceInternalApi invoicePaymentApi, final Clock clock, final UUID invoiceId, final BigDecimal amount, final Currency currency, final InternalCallContext callContext) throws InvoiceApiException { final InvoicePayment payment = Mockito.mock(InvoicePayment.class); Mockito.when(payment.getId()).thenReturn(UUID.randomUUID()); Mockito.when(payment.getType()).thenReturn(InvoicePaymentType.ATTEMPT); Mockito.when(payment.getInvoiceId()).thenReturn(invoiceId); Mockito.when(payment.getPaymentId()).thenReturn(UUID.randomUUID()); Mockito.when(payment.getPaymentCookieId()).thenReturn(UUID.randomUUID().toString()); final DateTime utcNow = clock.getUTCNow(); Mockito.when(payment.getPaymentDate()).thenReturn(utcNow); Mockito.when(payment.getAmount()).thenReturn(amount); Mockito.when(payment.getCurrency()).thenReturn(currency); Mockito.when(payment.getProcessedCurrency()).thenReturn(currency); Mockito.when(payment.isSuccess()).thenReturn(true); invoicePaymentApi.recordPaymentAttemptCompletion(payment.getInvoiceId(), payment.getAmount(), payment.getCurrency(), payment.getProcessedCurrency(), payment.getPaymentId(), payment.getPaymentCookieId(), payment.getPaymentDate(), payment.isSuccess(), callContext); return payment; } }
public InvoicePaymentModelDao(final InvoicePayment invoicePayment) { this(invoicePayment.getId(), invoicePayment.getCreatedDate(), invoicePayment.getType(), invoicePayment.getInvoiceId(), invoicePayment.getPaymentId(), invoicePayment.getPaymentDate(), invoicePayment.getAmount(), invoicePayment.getCurrency(), invoicePayment.getProcessedCurrency(), invoicePayment.getPaymentCookieId(), invoicePayment.getLinkedInvoicePaymentId(), invoicePayment.isSuccess()); }