use of org.killbill.billing.client.model.InvoicePaymentTransaction 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.InvoicePaymentTransaction in project killbill by killbill.
the class TestInvoicePayment method testPartialRefundWithInvoiceItemAdjustment.
@Test(groups = "slow", description = "Can create a partial refund with invoice item adjustment")
public void testPartialRefundWithInvoiceItemAdjustment() throws Exception {
final InvoicePayment paymentJson = setupScenarioWithPayment();
// Get the individual items for the invoice
final Invoice invoice = killBillClient.getInvoice(paymentJson.getTargetInvoiceId(), true);
final InvoiceItem itemToAdjust = invoice.getItems().get(0);
// Issue a refund for a fraction of the amount
final BigDecimal refundAmount = getFractionOfAmount(itemToAdjust.getAmount());
final BigDecimal expectedInvoiceBalance = BigDecimal.ZERO;
// Post and verify the refund
final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
refund.setPaymentId(paymentJson.getPaymentId());
refund.setIsAdjusted(true);
final InvoiceItem adjustment = new InvoiceItem();
adjustment.setInvoiceItemId(itemToAdjust.getInvoiceItemId());
adjustment.setAmount(refundAmount);
refund.setAdjustments(ImmutableList.<InvoiceItem>of(adjustment));
final Payment paymentAfterRefundJson = killBillClient.createInvoicePaymentRefund(refund, createdBy, reason, comment);
verifyRefund(paymentJson, paymentAfterRefundJson, refundAmount);
// Verify the invoice balance
verifyInvoice(paymentJson, expectedInvoiceBalance);
}
use of org.killbill.billing.client.model.InvoicePaymentTransaction in project killbill by killbill.
the class TestInvoicePayment method testPaymentsAndRefundsPagination.
@Test(groups = "slow", description = "Can paginate through all payments and refunds")
public void testPaymentsAndRefundsPagination() throws Exception {
InvoicePayment lastPayment = setupScenarioWithPayment();
for (int i = 0; i < 5; i++) {
final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
refund.setPaymentId(lastPayment.getPaymentId());
refund.setAmount(lastPayment.getPurchasedAmount());
killBillClient.createInvoicePaymentRefund(refund, createdBy, reason, comment);
final InvoicePayment invoicePayment = new InvoicePayment();
invoicePayment.setPurchasedAmount(lastPayment.getPurchasedAmount());
invoicePayment.setAccountId(lastPayment.getAccountId());
invoicePayment.setTargetInvoiceId(lastPayment.getTargetInvoiceId());
final InvoicePayment payment = killBillClient.createInvoicePayment(invoicePayment, false, createdBy, reason, comment);
lastPayment = payment;
}
final InvoicePayments allPayments = killBillClient.getInvoicePaymentsForAccount(lastPayment.getAccountId());
Assert.assertEquals(allPayments.size(), 6);
final List<PaymentTransaction> objRefundFromJson = getPaymentTransactions(allPayments, TransactionType.REFUND.toString());
Assert.assertEquals(objRefundFromJson.size(), 5);
Payments paymentsPage = killBillClient.getPayments(0L, 1L);
for (int i = 0; i < 6; i++) {
Assert.assertNotNull(paymentsPage);
Assert.assertEquals(paymentsPage.size(), 1);
Assert.assertTrue(paymentsPage.get(0).equals((Payment) allPayments.get(i)));
paymentsPage = paymentsPage.getNext();
}
Assert.assertNull(paymentsPage);
}
use of org.killbill.billing.client.model.InvoicePaymentTransaction in project killbill by killbill.
the class TestChargeback method testInvoicePaymentDoesNotExist.
@Test(groups = "slow", description = "Cannot add a chargeback for non existent payment")
public void testInvoicePaymentDoesNotExist() {
final InvoicePaymentTransaction input = new InvoicePaymentTransaction();
input.setPaymentId(input.getPaymentId());
input.setAmount(BigDecimal.TEN);
try {
killBillClient.createInvoicePaymentChargeback(input, createdBy, reason, comment);
fail();
} catch (NullPointerException e) {
} catch (KillBillClientException e) {
fail();
}
}
use of org.killbill.billing.client.model.InvoicePaymentTransaction 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);
}
Aggregations