public void sendPayment(Author author, BigDecimal amount, String url) throws TransferFailedException { try { String note = "Commit payment:\n__" + author.getUsername() + "__ " + url; Transaction transaction = new Transaction(); transaction.setTo(author.getEmail()); transaction.setAmount(Money.of(CurrencyUnit.of("BTC"), amount, RoundingMode.DOWN)); transaction.setNotes(note); Transaction response = coinbase.sendMoney(transaction); if (response.getStatus() != Transaction.Status.COMPLETE) { throw new TransferFailedException(); } } catch (CoinbaseException | IOException e) { throw new TransferFailedException(e); } }
@Override protected Money fromConvertedColumns(Object[] convertedColumns) { CurrencyUnit currencyUnitPart = (CurrencyUnit) convertedColumns[0]; BigDecimal amountPart = (BigDecimal) convertedColumns[1]; Money money = Money.of(currencyUnitPart, amountPart); return money; }
/** * Converts this money to an instance of {@code Money}. * * @param roundingMode the rounding mode to use, not null * @return the money instance, never null * @throws ArithmeticException if the rounding fails */ public Money toMoney(RoundingMode roundingMode) { return Money.of(this, roundingMode); }
@Override protected Money fromConvertedColumns(Object[] convertedColumns) { CurrencyUnit currencyUnitPart = (CurrencyUnit) convertedColumns[0]; BigDecimal amountPart = (BigDecimal) convertedColumns[1]; Money money = Money.of(currencyUnitPart, amountPart); return money; }
/** * Converts this money to an instance of {@code Money} without rounding. * If the scale of this money exceeds the currency scale an exception will be thrown. * * @return the money instance, never null * @throws ArithmeticException if the rounding fails */ public Money toMoney() { return Money.of(this); }
public static long toMinorUnits(final String currencyIsoCode, final BigDecimal amountBD, final RoundingMode roundingMode) { // The payment amount specified in minor units, without the decimal separator final CurrencyUnit currencyUnit = CurrencyUnit.of(currencyIsoCode); return Money.of(currencyUnit, amountBD, roundingMode).getAmountMinorLong(); } }
private Objective readObjectvieFrom(ResultSet resultSet) throws SQLException { Objective objective = new Objective( resultSet.getString("NAME"), new Percentage(resultSet.getBigDecimal("ALLOCATION")), Money.of(EUR, resultSet.getBigDecimal("SAVINGS")) ); objective.setId(resultSet.getLong("ID")); return objective; }
private Objective readObjectvieFrom(ResultSet resultSet) throws SQLException { Objective objective = new Objective( resultSet.getString("NAME"), new Percentage(resultSet.getBigDecimal("ALLOCATION")), Money.of(EUR, resultSet.getBigDecimal("SAVINGS")) ); objective.setId(resultSet.getLong("ID")); return objective; }
@Override public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { BigDecimal amount = BigDecimalType.INSTANCE.nullSafeGet(rs, names[0], session); String currencyCode = StringType.INSTANCE.nullSafeGet(rs, names[1], session); return amount == null && currencyCode == null ? null : Money.of(CurrencyUnit.getInstance(currencyCode), amount); }
public CurrencyRepresentation(Currency currency, Locale locale) { this.symbol = CURRENCY_FORMATTER.withLocale(locale).print( Money.of(CurrencyUnit.of(currency), BigDecimal.TEN, RoundingMode.HALF_EVEN)); this.localSymbol = MoneyUtil.getLocalSymbol(currency); }
@Test public void shouldCalculatePaybackIfEligible() { when(paybackPolicy.isEligible(account, purchase)).thenReturn(TRUE); Money payback = merchant.calculatePaybackFor(account, purchase); assertThat(payback).isEqualTo(Money.of(EUR, 6)); }
@Test public void shouldThrowWhenAccountNotFound() { Purchase purchase = new Purchase(Money.of(EUR, 100L), "4321432143214321", merchantNumber, now()); catchException(bookKeeper, EmptyResultDataAccessException.class).registerPaybackFor(purchase); assertThat(caughtException()).isNotNull(); }
@Test public void shouldThrowWhenMerchantNotFound() { Purchase purchase = new Purchase(Money.of(EUR, 100L), creditCardNumber, "1111111111", now()); catchException(bookKeeper, EmptyResultDataAccessException.class).registerPaybackFor(purchase); assertThat(caughtException()).isNotNull(); }
@Test public void shouldThrowWhenMerchantNotFound() { purchase = new Purchase(Money.of(EUR, 100L), creditCardNumber, "1111111111", now()); catchException(bookKeeper, EmptyResultDataAccessException.class).registerPaybackFor(purchase); assertThat(caughtException()).isNotNull(); }
@Test public void shouldThrowWhenAccountNotFound() { purchase = new Purchase(Money.of(EUR, 100L), "4321432143214321", merchantNumber, now()); catchException(bookKeeper, EmptyResultDataAccessException.class).registerPaybackFor(purchase); assertThat(caughtException()).isNotNull(); }
@Test public void shouldThrowWhenAccountNotFound() { purchase = new Purchase(Money.of(EUR, 100L), "4321432143214321", merchantNumber, now()); catchException(bookKeeper, EmptyResultDataAccessException.class).registerPaybackFor(purchase); assertThat(caughtException()).isNotNull(); }
@Test public void shouldRegisterPayback() { PaybackConfirmation confirmation = bookKeeper.registerPaybackFor(purchase); assertThat(confirmation.getNumber()).isNotNull(); assertThat(confirmation.getIncome().getAmount()).isEqualTo(Money.of(EUR, 6L)); assertThat(confirmation.getIncome().getDistributions()).hasSize(2); assertThat(confirmation.getIncome().getDistribution("Glock").getAmount()).isEqualTo(Money.of(EUR, 3L)); assertThat(confirmation.getIncome().getDistribution("M60").getAmount()).isEqualTo(Money.of(EUR, 3L)); } }
@Test public void shouldRegisterPayback() { PaybackConfirmation confirmation = bookKeeper.registerPaybackFor(purchase); assertThat(confirmation.getNumber()).isNotNull(); assertThat(confirmation.getIncome().getAmount()).isEqualTo(Money.of(EUR, 6L)); assertThat(confirmation.getIncome().getDistributions()).hasSize(2); assertThat(confirmation.getIncome().getDistribution("Glock").getAmount()).isEqualTo(Money.of(EUR, 3L)); assertThat(confirmation.getIncome().getDistribution("M60").getAmount()).isEqualTo(Money.of(EUR, 3L)); } }
@Test public void shouldRegisterPayback() { PaybackConfirmation confirmation = bookKeeper.registerPaybackFor(purchase); assertThat(confirmation.getNumber()).isNotNull(); assertThat(confirmation.getIncome().getAmount()).isEqualTo(Money.of(EUR, 6L)); assertThat(confirmation.getIncome().getDistributions()).hasSize(2); assertThat(confirmation.getIncome().getDistribution("Glock").getAmount()).isEqualTo(Money.of(EUR, 3L)); assertThat(confirmation.getIncome().getDistribution("M60").getAmount()).isEqualTo(Money.of(EUR, 3L)); } }
@Test public void shouldRegisterPayback() { PaybackConfirmation confirmation = bookKeeper.registerPaybackFor(purchase()); assertThat(confirmation.getNumber()).isNotNull(); assertThat(confirmation.getIncome().getAmount()).isEqualTo(Money.of(EUR, 6L)); assertThat(confirmation.getIncome().getDistributions()).hasSize(2); assertThat(confirmation.getIncome().getDistribution("Glock").getAmount()).isEqualTo(Money.of(EUR, 3L)); assertThat(confirmation.getIncome().getDistribution("M60").getAmount()).isEqualTo(Money.of(EUR, 3L)); } }