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);
}
}
}
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);
}
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);
}
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) {
}
}
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);
}
Aggregations