use of org.killbill.billing.client.model.InvoicePayment in project killbill by killbill.
the class TestOverdue method testOverdueStatus.
@Test(groups = "slow", description = "Can retrieve the account overdue status")
public void testOverdueStatus() throws Exception {
// Create an account without a payment method
final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
// Get the invoices
final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), requestOptions);
// 2 invoices but look for the non zero dollar one
assertEquals(invoices.size(), 2);
// We're still clear - see the configuration
Assert.assertTrue(killBillClient.getOverdueStateForAccount(accountJson.getAccountId(), requestOptions).getIsClearState());
clock.addDays(30);
crappyWaitForLackOfProperSynchonization();
Assert.assertEquals(killBillClient.getOverdueStateForAccount(accountJson.getAccountId(), requestOptions).getName(), "OD1");
clock.addDays(10);
crappyWaitForLackOfProperSynchonization();
Assert.assertEquals(killBillClient.getOverdueStateForAccount(accountJson.getAccountId(), requestOptions).getName(), "OD2");
clock.addDays(10);
crappyWaitForLackOfProperSynchonization();
Assert.assertEquals(killBillClient.getOverdueStateForAccount(accountJson.getAccountId(), requestOptions).getName(), "OD3");
// Post external payments, paying the most recent invoice first: this is to avoid a race condition where
// a refresh overdue notification kicks in after the first payment, which makes the account goes CLEAR and
// triggers an AUTO_INVOICE_OFF tag removal (hence adjustment of the other invoices balance).
final Invoices invoicesForAccount = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), requestOptions);
final List<Invoice> mostRecentInvoiceFirst = Ordering.<Invoice>from(new Comparator<Invoice>() {
@Override
public int compare(final Invoice invoice1, final Invoice invoice2) {
return invoice1.getInvoiceDate().compareTo(invoice2.getInvoiceDate());
}
}).reverse().sortedCopy(invoicesForAccount);
for (final Invoice invoice : mostRecentInvoiceFirst) {
if (invoice.getBalance().compareTo(BigDecimal.ZERO) > 0) {
final InvoicePayment invoicePayment = new InvoicePayment();
invoicePayment.setPurchasedAmount(invoice.getAmount());
invoicePayment.setAccountId(accountJson.getAccountId());
invoicePayment.setTargetInvoiceId(invoice.getInvoiceId());
killBillClient.createInvoicePayment(invoicePayment, true, requestOptions);
}
}
// Wait a bit for overdue to pick up the payment events...
crappyWaitForLackOfProperSynchonization();
// Verify we're in clear state
Assert.assertTrue(killBillClient.getOverdueStateForAccount(accountJson.getAccountId(), requestOptions).getIsClearState());
}
use of org.killbill.billing.client.model.InvoicePayment in project killbill by killbill.
the class TestChargeback method testMultipleChargeback.
@Test(groups = "slow", description = "Can create multiple chargebacks")
public void testMultipleChargeback() throws Exception {
final Payment payment = createAccountWithInvoiceAndPayment();
// We get a 249.95 payment so we do 4 chargeback and then the fifth should fail
final InvoicePaymentTransaction input = new InvoicePaymentTransaction();
input.setPaymentId(payment.getPaymentId());
input.setAmount(new BigDecimal("50.00"));
int count = 4;
while (count-- > 0) {
assertNotNull(killBillClient.createInvoicePaymentChargeback(input, createdBy, reason, comment));
}
// Last attempt should fail because this is more than the Payment
final InvoicePayment foo = killBillClient.createInvoicePaymentChargeback(input, createdBy, reason, comment);
final List<InvoicePayment> payments = killBillClient.getInvoicePaymentsForAccount(payment.getAccountId());
final List<PaymentTransaction> transactions = getPaymentTransactions(payments, TransactionType.CHARGEBACK.toString());
Assert.assertEquals(transactions.size(), 5);
int found = 0;
for (final PaymentTransaction transaction : transactions) {
if (transaction.getStatus().equals("SUCCESS")) {
assertTrue(transaction.getAmount().compareTo(input.getAmount()) == 0);
assertEquals(transaction.getPaymentId(), input.getPaymentId());
found++;
} else {
assertEquals(transaction.getStatus(), "PAYMENT_FAILURE");
found++;
}
}
assertEquals(found, 5);
}
use of org.killbill.billing.client.model.InvoicePayment in project killbill by killbill.
the class TestChargeback method createAndVerifyChargeback.
private void createAndVerifyChargeback(final Payment payment) throws KillBillClientException {
// Create the chargeback
final InvoicePaymentTransaction chargeback = new InvoicePaymentTransaction();
chargeback.setPaymentId(payment.getPaymentId());
chargeback.setAmount(BigDecimal.TEN);
final InvoicePayment chargebackJson = killBillClient.createInvoicePaymentChargeback(chargeback, createdBy, reason, comment);
final List<PaymentTransaction> chargebackTransactions = getPaymentTransactions(ImmutableList.of(chargebackJson), TransactionType.CHARGEBACK.toString());
assertEquals(chargebackTransactions.size(), 1);
assertEquals(chargebackTransactions.get(0).getAmount().compareTo(chargeback.getAmount()), 0);
assertEquals(chargebackTransactions.get(0).getPaymentId(), chargeback.getPaymentId());
// Find the chargeback by account
final List<InvoicePayment> payments = killBillClient.getInvoicePaymentsForAccount(payment.getAccountId());
final List<PaymentTransaction> transactions = getPaymentTransactions(payments, TransactionType.CHARGEBACK.toString());
Assert.assertEquals(transactions.size(), 1);
assertEquals(transactions.get(0).getAmount().compareTo(chargeback.getAmount()), 0);
assertEquals(transactions.get(0).getPaymentId(), chargeback.getPaymentId());
}
use of org.killbill.billing.client.model.InvoicePayment in project killbill by killbill.
the class TestExceptions method testExceptionMapping.
@Test(groups = "slow", enabled = false)
public void testExceptionMapping() throws Exception {
final Account account = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
final List<InvoicePayment> payments = killBillClient.getInvoicePaymentsForAccount(account.getAccountId());
final InvoicePaymentTransaction input = new InvoicePaymentTransaction();
input.setPaymentId(payments.get(0).getPaymentId());
input.setAmount(BigDecimal.TEN.negate());
try {
killBillClient.createInvoicePaymentChargeback(input, createdBy, reason, comment);
fail();
} catch (final KillBillClientException e) {
Assert.assertEquals(e.getBillingException().getClassName(), InvoiceApiException.class.getName());
Assert.assertEquals(e.getBillingException().getCode(), (Integer) ErrorCode.CHARGE_BACK_AMOUNT_IS_NEGATIVE.getCode());
Assert.assertFalse(e.getBillingException().getStackTrace().isEmpty());
}
}
use of org.killbill.billing.client.model.InvoicePayment in project killbill by killbill.
the class TestExternalRefund method testAutomaticPaymentAndRefundWithAdjustments.
@Test(groups = "slow", description = "#255 - Scenario 0 - Can refund an automatic payment over item adjustments. This is a test to validate the correct behaviour.")
public void testAutomaticPaymentAndRefundWithAdjustments() throws Exception {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
final Payments paymentsForAccount = killBillClient.getPaymentsForAccount(accountJson.getAccountId(), requestOptions);
final Payment payment = paymentsForAccount.get(paymentsForAccount.size() - 1);
Invoices invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, true, requestOptions);
final List<InvoiceItem> itemsToBeAdjusted = invoices.get(1).getItems();
// regular refund
final InvoicePaymentTransaction invoicePaymentTransactionRequest = new InvoicePaymentTransaction();
invoicePaymentTransactionRequest.setAmount(BigDecimal.valueOf(249.95));
invoicePaymentTransactionRequest.setCurrency(accountJson.getCurrency().toString());
invoicePaymentTransactionRequest.setPaymentId(payment.getPaymentId());
invoicePaymentTransactionRequest.setIsAdjusted(true);
invoicePaymentTransactionRequest.setAdjustments(itemsToBeAdjusted);
final InvoicePayment invoicePaymentRefund = killBillClient.createInvoicePaymentRefund(invoicePaymentTransactionRequest, requestOptions);
assertNotNull(invoicePaymentRefund);
assertSingleInvoicePaymentRefund(invoicePaymentRefund);
assertRefundInvoiceAdjustments(accountJson.getAccountId());
assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.ZERO, BigDecimal.ZERO);
}
Aggregations