Search in sources :

Example 6 with Credit

use of org.killbill.billing.client.model.Credit in project killbill by killbill.

the class TestCredit method testAccountDoesNotExist.

@Test(groups = "slow", description = "Cannot add a credit if the account doesn't exist")
public void testAccountDoesNotExist() throws Exception {
    final Credit credit = new Credit();
    credit.setAccountId(UUID.randomUUID());
    credit.setCreditAmount(BigDecimal.TEN);
    // Try to create the credit
    assertNull(killBillClient.createCredit(credit, true, createdBy, reason, comment));
}
Also used : Credit(org.killbill.billing.client.model.Credit) Test(org.testng.annotations.Test)

Example 7 with Credit

use of org.killbill.billing.client.model.Credit in project killbill by killbill.

the class TestInvoice method testInvoiceTransferCreditToParentAccount.

@Test(groups = "slow", description = "Can transfer credit to parent account")
public void testInvoiceTransferCreditToParentAccount() throws Exception {
    final Account parentAccount = createAccount();
    final Account childAccount = createAccount(parentAccount.getAccountId());
    final BigDecimal creditAmount = BigDecimal.TEN;
    final Credit credit = new Credit();
    credit.setAccountId(childAccount.getAccountId());
    credit.setInvoiceId(null);
    credit.setCreditAmount(creditAmount);
    // insert credit to child account
    final Credit creditJson = killBillClient.createCredit(credit, true, requestOptions);
    Invoices childInvoices = killBillClient.getInvoicesForAccount(childAccount.getAccountId(), true, false);
    Assert.assertEquals(childInvoices.size(), 1);
    Assert.assertEquals(childInvoices.get(0).getCreditAdj().compareTo(BigDecimal.TEN), 0);
    Invoices parentInvoices = killBillClient.getInvoicesForAccount(parentAccount.getAccountId(), true, false);
    Assert.assertEquals(parentInvoices.size(), 0);
    // transfer credit to parent account
    killBillClient.transferChildCreditToParent(childAccount.getAccountId(), requestOptions);
    childInvoices = killBillClient.getInvoicesForAccount(childAccount.getAccountId(), true, false);
    Assert.assertEquals(childInvoices.size(), 2);
    Assert.assertEquals(childInvoices.get(1).getCreditAdj().compareTo(BigDecimal.TEN.negate()), 0);
    parentInvoices = killBillClient.getInvoicesForAccount(parentAccount.getAccountId(), true, false);
    Assert.assertEquals(parentInvoices.size(), 1);
    Assert.assertEquals(parentInvoices.get(0).getCreditAdj().compareTo(BigDecimal.TEN), 0);
}
Also used : Account(org.killbill.billing.client.model.Account) Credit(org.killbill.billing.client.model.Credit) Invoices(org.killbill.billing.client.model.Invoices) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 8 with Credit

use of org.killbill.billing.client.model.Credit in project killbill by killbill.

the class TestInvoice method testCreateCreditInvoiceAndMoveStatus.

@Test(groups = "slow", description = "Can add a credit to a new invoice")
public void testCreateCreditInvoiceAndMoveStatus() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    final DateTime effectiveDate = clock.getUTCNow();
    final BigDecimal creditAmount = BigDecimal.TEN;
    final Credit credit = new Credit();
    credit.setAccountId(account.getAccountId());
    credit.setInvoiceId(null);
    credit.setCreditAmount(creditAmount);
    final Credit creditJson = killBillClient.createCredit(credit, false, createdBy, reason, comment);
    Invoice invoice = killBillClient.getInvoice(creditJson.getInvoiceId());
    Assert.assertEquals(invoice.getStatus(), InvoiceStatus.DRAFT.toString());
    killBillClient.commitInvoice(invoice.getInvoiceId(), createdBy, reason, comment);
    invoice = killBillClient.getInvoice(creditJson.getInvoiceId());
    Assert.assertEquals(invoice.getStatus(), InvoiceStatus.COMMITTED.toString());
}
Also used : Account(org.killbill.billing.client.model.Account) Credit(org.killbill.billing.client.model.Credit) Invoice(org.killbill.billing.client.model.Invoice) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

Credit (org.killbill.billing.client.model.Credit)8 Test (org.testng.annotations.Test)7 BigDecimal (java.math.BigDecimal)5 DateTime (org.joda.time.DateTime)4 Account (org.killbill.billing.client.model.Account)3 Invoice (org.killbill.billing.client.model.Invoice)3 UUID (java.util.UUID)1 KillBillClientException (org.killbill.billing.client.KillBillClientException)1 AccountTimeline (org.killbill.billing.client.model.AccountTimeline)1 AuditLog (org.killbill.billing.client.model.AuditLog)1 InvoicePayment (org.killbill.billing.client.model.InvoicePayment)1 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)1 Invoices (org.killbill.billing.client.model.Invoices)1 Payment (org.killbill.billing.client.model.Payment)1 AuditLevel (org.killbill.billing.util.api.AuditLevel)1