Search in sources :

Example 6 with InvoicePayment

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());
}
Also used : Account(org.killbill.billing.client.model.Account) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) Invoice(org.killbill.billing.client.model.Invoice) Invoices(org.killbill.billing.client.model.Invoices) Test(org.testng.annotations.Test)

Example 7 with InvoicePayment

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);
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) InvoicePaymentTransaction(org.killbill.billing.client.model.InvoicePaymentTransaction) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) Payment(org.killbill.billing.client.model.Payment) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) InvoicePaymentTransaction(org.killbill.billing.client.model.InvoicePaymentTransaction) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 8 with InvoicePayment

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());
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) InvoicePaymentTransaction(org.killbill.billing.client.model.InvoicePaymentTransaction) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) InvoicePaymentTransaction(org.killbill.billing.client.model.InvoicePaymentTransaction)

Example 9 with InvoicePayment

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());
    }
}
Also used : Account(org.killbill.billing.client.model.Account) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) InvoicePaymentTransaction(org.killbill.billing.client.model.InvoicePaymentTransaction) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Example 10 with InvoicePayment

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);
}
Also used : Account(org.killbill.billing.client.model.Account) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) Payment(org.killbill.billing.client.model.Payment) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) InvoiceItem(org.killbill.billing.client.model.InvoiceItem) InvoicePaymentTransaction(org.killbill.billing.client.model.InvoicePaymentTransaction) Payments(org.killbill.billing.client.model.Payments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) Invoices(org.killbill.billing.client.model.Invoices) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

InvoicePayment (org.killbill.billing.client.model.InvoicePayment)25 Test (org.testng.annotations.Test)20 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)19 Payment (org.killbill.billing.client.model.Payment)14 Account (org.killbill.billing.client.model.Account)13 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)10 DateTime (org.joda.time.DateTime)9 Invoice (org.killbill.billing.client.model.Invoice)9 Invoices (org.killbill.billing.client.model.Invoices)8 Payments (org.killbill.billing.client.model.Payments)8 InvoiceItem (org.killbill.billing.client.model.InvoiceItem)7 BigDecimal (java.math.BigDecimal)6 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)6 PaymentMethod (org.killbill.billing.client.model.PaymentMethod)3 UUID (java.util.UUID)2 KillBillClientException (org.killbill.billing.client.KillBillClientException)1 AccountTimeline (org.killbill.billing.client.model.AccountTimeline)1 AuditLog (org.killbill.billing.client.model.AuditLog)1 PaymentMethodPluginDetail (org.killbill.billing.client.model.PaymentMethodPluginDetail)1 AuditLevel (org.killbill.billing.util.api.AuditLevel)1