Search in sources :

Example 1 with InvoicePaymentTransaction

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);
}
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 2 with InvoicePaymentTransaction

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

Example 3 with InvoicePaymentTransaction

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

Example 4 with InvoicePaymentTransaction

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

Example 5 with InvoicePaymentTransaction

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

Aggregations

InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)19 InvoicePayment (org.killbill.billing.client.model.InvoicePayment)18 Test (org.testng.annotations.Test)18 Payment (org.killbill.billing.client.model.Payment)14 Account (org.killbill.billing.client.model.Account)9 DateTime (org.joda.time.DateTime)8 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)8 Payments (org.killbill.billing.client.model.Payments)8 BigDecimal (java.math.BigDecimal)7 InvoiceItem (org.killbill.billing.client.model.InvoiceItem)7 Invoice (org.killbill.billing.client.model.Invoice)6 Invoices (org.killbill.billing.client.model.Invoices)6 KillBillClientException (org.killbill.billing.client.KillBillClientException)3 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)3 Credit (org.killbill.billing.client.model.Credit)1 PaymentMethod (org.killbill.billing.client.model.PaymentMethod)1 PaymentMethodPluginDetail (org.killbill.billing.client.model.PaymentMethodPluginDetail)1