@Override public boolean apply(final InvoicePayment input) { return input.getType() == InvoicePaymentType.ATTEMPT && !input.isSuccess(); } }).orNull();
public static BigDecimal computeInvoiceAmountPaid(final Currency currency, @Nullable final Iterable<InvoicePayment> invoicePayments) { BigDecimal amountPaid = BigDecimal.ZERO; if (invoicePayments == null || !invoicePayments.iterator().hasNext()) { return KillBillMoney.of(amountPaid, currency); } for (final InvoicePayment invoicePayment : invoicePayments) { if (!invoicePayment.isSuccess()) { continue; } if (InvoicePaymentType.ATTEMPT.equals(invoicePayment.getType())) { amountPaid = amountPaid.add(invoicePayment.getAmount()); } } return KillBillMoney.of(amountPaid, currency); }
public static BigDecimal computeInvoiceAmountRefunded(final Currency currency, @Nullable final Iterable<InvoicePayment> invoicePayments) { BigDecimal amountRefunded = BigDecimal.ZERO; if (invoicePayments == null || !invoicePayments.iterator().hasNext()) { return KillBillMoney.of(amountRefunded, currency); } for (final InvoicePayment invoicePayment : invoicePayments) { if (invoicePayment.isSuccess() == null || !invoicePayment.isSuccess()) { continue; } if (InvoicePaymentType.REFUND.equals(invoicePayment.getType()) || InvoicePaymentType.CHARGED_BACK.equals(invoicePayment.getType())) { amountRefunded = amountRefunded.add(invoicePayment.getAmount()); } } return KillBillMoney.of(amountRefunded, currency); } }
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; } }
assertEquals(invoice1.getPayments().get(0).getAmount().compareTo(BigDecimal.ZERO), 0); assertEquals(invoice1.getPayments().get(0).getCurrency(), Currency.USD); assertFalse(invoice1.getPayments().get(0).isSuccess()); assertNotNull(invoice1.getPayments().get(0).getPaymentId()); assertTrue(invoice2.getChargedAmount().compareTo(new BigDecimal("249.95")) == 0); assertEquals(invoice2.getPayments().size(), 1); assertTrue(invoice2.getPayments().get(0).isSuccess());
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()); }
assertEquals(invoice1.getPayments().get(0).getAmount().compareTo(new BigDecimal("249.95")), 0); assertEquals(invoice1.getPayments().get(0).getCurrency(), Currency.USD); assertFalse(invoice1.getPayments().get(0).isSuccess()); assertNotNull(invoice1.getPayments().get(0).getPaymentId());
assertEquals(invoice1.getPayments().get(0).getAmount().compareTo(new BigDecimal("249.95")), 0); assertEquals(invoice1.getPayments().get(0).getCurrency(), Currency.USD); assertTrue(invoice1.getPayments().get(0).isSuccess()); assertNotNull(invoice1.getPayments().get(0).getPaymentId()); assertEquals(invoice2.getPayments().get(0).getAmount().compareTo(BigDecimal.ZERO), 0); assertEquals(invoice2.getPayments().get(0).getCurrency(), Currency.USD); assertFalse(invoice2.getPayments().get(0).isSuccess()); assertNotNull(invoice2.getPayments().get(0).getPaymentId());
assertEquals(invoice1.getPayments().get(0).getAmount().compareTo(new BigDecimal("249.95")), 0); assertEquals(invoice1.getPayments().get(0).getCurrency(), Currency.USD); assertFalse(invoice1.getPayments().get(0).isSuccess()); assertNotNull(invoice1.getPayments().get(0).getPaymentId()); assertTrue(invoice2.getChargedAmount().compareTo(new BigDecimal("249.95")) == 0); assertEquals(invoice2.getPayments().size(), 1); assertTrue(invoice2.getPayments().get(0).isSuccess());
assertEquals(invoice1.getPayments().get(0).getAmount().compareTo(BigDecimal.ZERO), 0); assertEquals(invoice1.getPayments().get(0).getCurrency(), Currency.USD); assertFalse(invoice1.getPayments().get(0).isSuccess()); assertNotNull(invoice1.getPayments().get(0).getPaymentId()); assertEquals(invoice2.getPayments().get(0).getAmount().compareTo(new BigDecimal("249.95")), 0); assertEquals(invoice2.getPayments().get(0).getCurrency(), Currency.USD); assertTrue(invoice2.getPayments().get(0).isSuccess()); assertNotNull(invoice2.getPayments().get(0).getPaymentId());
assertEquals(invoice1.getPayments().get(0).getAmount().compareTo(BigDecimal.ZERO), 0); assertEquals(invoice1.getPayments().get(0).getCurrency(), Currency.USD); assertFalse(invoice1.getPayments().get(0).isSuccess()); assertNotNull(invoice1.getPayments().get(0).getPaymentId()); assertEquals(invoice2.getPayments().get(0).getAmount().compareTo(new BigDecimal("249.95")), 0); assertEquals(invoice2.getPayments().get(0).getCurrency(), Currency.USD); assertTrue(invoice2.getPayments().get(0).isSuccess()); assertNotNull(invoice2.getPayments().get(0).getPaymentId());
Assert.assertEquals(updateInvoice3.getPayments().size(), 1); Assert.assertEquals(updateInvoice3.getPayments().get(0).getPaymentCookieId(), originalTransaction.getExternalKey()); Assert.assertTrue(updateInvoice3.getPayments().get(0).isSuccess()); Assert.assertEquals(invoiceUserApi.getAccountBalance(account.getId(), callContext).compareTo(invoice2.getBalance()), 0);
assertEquals(invoice1.getPayments().get(0).getAmount().compareTo(BigDecimal.ZERO), 0); assertEquals(invoice1.getPayments().get(0).getCurrency(), Currency.USD); assertFalse(invoice1.getPayments().get(0).isSuccess()); assertNotNull(invoice1.getPayments().get(0).getPaymentId()); assertEquals(invoice2.getPayments().get(0).getAmount().compareTo(new BigDecimal("249.95")), 0); assertEquals(invoice2.getPayments().get(0).getCurrency(), Currency.USD); assertTrue(invoice2.getPayments().get(0).isSuccess()); assertNotNull(invoice2.getPayments().get(0).getPaymentId());
Assert.assertEquals(invoice1.getPayments().get(0).getPaymentId(), payment1.getId()); Assert.assertEquals(invoice1.getPayments().get(0).getType(), InvoicePaymentType.ATTEMPT); Assert.assertTrue(invoice1.getPayments().get(0).isSuccess()); Assert.assertEquals(invoice1.getPayments().get(1).getPaymentId(), payment2.getId()); Assert.assertEquals(invoice1.getPayments().get(1).getType(), InvoicePaymentType.ATTEMPT); Assert.assertTrue(invoice1.getPayments().get(1).isSuccess()); Assert.assertEquals(invoice1.getPayments().get(2).getPaymentId(), payment1.getId()); Assert.assertEquals(invoice1.getPayments().get(2).getType(), InvoicePaymentType.REFUND); Assert.assertTrue(invoice1.getPayments().get(2).isSuccess()); Assert.assertEquals(invoice1.getPayments().get(3).getPaymentId(), payment2.getId()); Assert.assertEquals(invoice1.getPayments().get(3).getType(), InvoicePaymentType.REFUND); Assert.assertTrue(invoice1.getPayments().get(3).isSuccess());