Search in sources :

Example 1 with Credit

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

the class TestAccountTimeline method verifyCredits.

private void verifyCredits(final UUID accountId, final DateTime startTime, final DateTime endTime, final BigDecimal creditAmount) throws Exception {
    for (final AuditLevel auditLevel : AuditLevel.values()) {
        final AccountTimeline timeline = getAccountTimeline(accountId, auditLevel);
        // Verify credits
        final List<Credit> credits = timeline.getInvoices().get(1).getCredits();
        Assert.assertEquals(credits.size(), 1);
        Assert.assertEquals(credits.get(0).getCreditAmount().compareTo(creditAmount.negate()), 0);
        // Verify audits
        final List<AuditLog> creditAuditLogs = credits.get(0).getAuditLogs();
        if (AuditLevel.NONE.equals(auditLevel)) {
            Assert.assertEquals(creditAuditLogs.size(), 0);
        } else {
            Assert.assertEquals(creditAuditLogs.size(), 1);
            verifyAuditLog(creditAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
        }
    }
}
Also used : Credit(org.killbill.billing.client.model.Credit) AuditLevel(org.killbill.billing.util.api.AuditLevel) AccountTimeline(org.killbill.billing.client.model.AccountTimeline) AuditLog(org.killbill.billing.client.model.AuditLog)

Example 2 with Credit

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

the class TestAccountTimeline method testAccountTimelineWithAudits.

@Test(groups = "slow", description = "Can retrieve the timeline with audits")
public void testAccountTimelineWithAudits() throws Exception {
    final DateTime startTime = clock.getUTCNow();
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    final DateTime endTime = clock.getUTCNow();
    // Add credit
    final Invoice invoice = killBillClient.getInvoicesForAccount(accountJson.getAccountId()).get(1);
    final BigDecimal creditAmount = BigDecimal.ONE;
    final Credit credit = new Credit();
    credit.setAccountId(accountJson.getAccountId());
    credit.setCreditAmount(creditAmount);
    killBillClient.createCredit(credit, true, createdBy, reason, comment);
    // Add refund
    final Payment postedPayment = killBillClient.getPaymentsForAccount(accountJson.getAccountId()).get(0);
    final BigDecimal refundAmount = BigDecimal.ONE;
    final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
    refund.setPaymentId(postedPayment.getPaymentId());
    refund.setAmount(refundAmount);
    killBillClient.createInvoicePaymentRefund(refund, createdBy, reason, comment);
    // Add chargeback
    final BigDecimal chargebackAmount = BigDecimal.ONE;
    final InvoicePaymentTransaction chargeback = new InvoicePaymentTransaction();
    chargeback.setPaymentId(postedPayment.getPaymentId());
    chargeback.setAmount(chargebackAmount);
    killBillClient.createInvoicePaymentChargeback(chargeback, createdBy, reason, comment);
    // Verify payments
    verifyPayments(accountJson.getAccountId(), startTime, endTime, refundAmount, chargebackAmount);
    // Verify invoices
    verifyInvoices(accountJson.getAccountId(), startTime, endTime);
    // Verify credits
    verifyCredits(accountJson.getAccountId(), startTime, endTime, creditAmount);
    // Verify bundles
    verifyBundles(accountJson.getAccountId(), startTime, endTime);
}
Also used : Account(org.killbill.billing.client.model.Account) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) Payment(org.killbill.billing.client.model.Payment) Invoice(org.killbill.billing.client.model.Invoice) Credit(org.killbill.billing.client.model.Credit) InvoicePaymentTransaction(org.killbill.billing.client.model.InvoicePaymentTransaction) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 3 with Credit

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

the class TestCredit method testAddCreditToInvoice.

@Test(groups = "slow", description = "Can add a credit to an existing invoice")
public void testAddCreditToInvoice() throws Exception {
    //final Invoice invoice = killBillClient.getInvoicesForAccount(accountJson.getAccountId()).get(1);
    final DateTime effectiveDate = clock.getUTCNow();
    final BigDecimal creditAmount = BigDecimal.ONE;
    final Credit credit = new Credit();
    credit.setAccountId(accountJson.getAccountId());
    credit.setCreditAmount(creditAmount);
    credit.setDescription("description");
    Credit objFromJson = killBillClient.createCredit(credit, false, createdBy, reason, comment);
    final UUID invoiceId = objFromJson.getInvoiceId();
    credit.setInvoiceId(invoiceId);
    objFromJson = killBillClient.createCredit(credit, false, createdBy, reason, comment);
    // We can't just compare the object via .equals() due e.g. to the invoice id
    assertEquals(objFromJson.getAccountId(), accountJson.getAccountId());
    assertEquals(objFromJson.getInvoiceId(), invoiceId);
    assertEquals(objFromJson.getCreditAmount().compareTo(creditAmount), 0);
    assertEquals(objFromJson.getEffectiveDate().compareTo(effectiveDate.toLocalDate()), 0);
    assertEquals(objFromJson.getDescription().compareTo("description"), 0);
}
Also used : Credit(org.killbill.billing.client.model.Credit) UUID(java.util.UUID) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 4 with Credit

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

the class TestCredit method testBadRequest.

@Test(groups = "slow", description = "Cannot credit a badly formatted credit")
public void testBadRequest() throws Exception {
    final Credit credit = new Credit();
    credit.setAccountId(accountJson.getAccountId());
    credit.setCreditAmount(BigDecimal.TEN.negate());
    // Try to create the credit
    try {
        killBillClient.createCredit(credit, true, createdBy, reason, comment);
        fail();
    } catch (final KillBillClientException e) {
    }
}
Also used : Credit(org.killbill.billing.client.model.Credit) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Example 5 with Credit

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

the class TestCredit method testAddCreditToCommittedInvoice.

@Test(groups = "slow", description = "Can add a credit to an existing account", expectedExceptions = KillBillClientException.class, expectedExceptionsMessageRegExp = ".*it is already in COMMITTED status")
public void testAddCreditToCommittedInvoice() throws Exception {
    final Invoice invoice = killBillClient.getInvoicesForAccount(accountJson.getAccountId()).get(1);
    final DateTime effectiveDate = clock.getUTCNow();
    final BigDecimal creditAmount = BigDecimal.ONE;
    final Credit credit = new Credit();
    credit.setAccountId(accountJson.getAccountId());
    credit.setInvoiceId(invoice.getInvoiceId());
    credit.setCreditAmount(creditAmount);
    final Credit objFromJson = killBillClient.createCredit(credit, true, createdBy, reason, comment);
}
Also used : Invoice(org.killbill.billing.client.model.Invoice) Credit(org.killbill.billing.client.model.Credit) 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