@Override public Currency getProcessedCurrency() { final Currency processedCurrency = ((DefaultInvoice) invoice).getProcessedCurrency(); // If the processed currency is different we return it; otherwise we return null so that template does not print anything special return (processedCurrency != getCurrency()) ? processedCurrency : null; }
@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 = ((DefaultInvoice) 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 (Rate rate : conversion.getRates()) { if (rate.getCurrency() == getCurrency()) { return rate.getValue().toString(); } } } catch (CurrencyConversionException e) { logger.warn("Failed to retrieve currency conversion rates for currency = " + currency + " and date = " + latestPaymentDate, e); return null; } logger.warn("Failed to retrieve currency conversion rates for currency = " + currency + " and date = " + latestPaymentDate); return null; }