Search in sources :

Example 1 with InvoicePayments

use of org.killbill.billing.client.model.InvoicePayments 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 2 with InvoicePayments

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

the class TestPayment method testWithFailedPaymentAndScheduledAttemptsGetInvoicePayment.

@Test(groups = "slow")
public void testWithFailedPaymentAndScheduledAttemptsGetInvoicePayment() throws Exception {
    mockPaymentProviderPlugin.makeNextPaymentFailWithError();
    final Account account = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // Getting Invoice #2 (first after Trial period)
    UUID failedInvoiceId = killBillClient.getInvoicesForAccount(account.getAccountId(), false, false, RequestOptions.empty()).get(1).getInvoiceId();
    HashMultimap<String, String> queryParams = HashMultimap.create();
    queryParams.put("withAttempts", "true");
    RequestOptions inputOptions = RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).withQueryParams(queryParams).build();
    InvoicePayments invoicePayments = killBillClient.getInvoicePayment(failedInvoiceId, inputOptions);
    Assert.assertEquals(invoicePayments.get(0).getTargetInvoiceId(), failedInvoiceId);
    Assert.assertNotNull(invoicePayments.get(0).getPaymentAttempts());
    Assert.assertEquals(invoicePayments.get(0).getPaymentAttempts().size(), 2);
    Assert.assertEquals(invoicePayments.get(0).getPaymentAttempts().get(0).getStateName(), "RETRIED");
    Assert.assertEquals(invoicePayments.get(0).getPaymentAttempts().get(1).getStateName(), "SCHEDULED");
    // Remove the future notification and check SCHEDULED does not appear any longer
    killBillClient.cancelScheduledPaymentTransaction(null, invoicePayments.get(0).getPaymentAttempts().get(1).getTransactionExternalKey(), inputOptions);
    invoicePayments = killBillClient.getInvoicePayment(failedInvoiceId, inputOptions);
    Assert.assertEquals(invoicePayments.get(0).getPaymentAttempts().size(), 1);
    Assert.assertEquals(invoicePayments.get(0).getPaymentAttempts().get(0).getStateName(), "RETRIED");
}
Also used : Account(org.killbill.billing.client.model.Account) RequestOptions(org.killbill.billing.client.RequestOptions) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 3 with InvoicePayments

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

the class TestAccount method testAccountPaymentsWithRefund.

@Test(groups = "slow")
public void testAccountPaymentsWithRefund() throws Exception {
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // Verify payments
    final InvoicePayments objFromJson = killBillClient.getInvoicePaymentsForAccount(accountJson.getAccountId(), requestOptions);
    Assert.assertEquals(objFromJson.size(), 1);
}
Also used : Account(org.killbill.billing.client.model.Account) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) Test(org.testng.annotations.Test)

Example 4 with InvoicePayments

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

the class TestExternalRefund method assertInvoicePaymentsExternalRefund.

private void assertInvoicePaymentsExternalRefund(final UUID accountId, final InvoicePayment invoicePaymentExternalRefund) throws KillBillClientException {
    final InvoicePayments invoicePaymentsForAccount = killBillClient.getInvoicePaymentsForAccount(accountId, requestOptions);
    assertEquals(invoicePaymentsForAccount.size(), 2);
    // INVOICE PAYMENT FOR ORIGINAL PURCHASE
    final InvoicePayment invoicePaymentPurchase = invoicePaymentsForAccount.get(0);
    assertEquals(invoicePaymentPurchase.getPurchasedAmount().compareTo(BigDecimal.valueOf(249.95)), 0);
    assertEquals(invoicePaymentPurchase.getCreditedAmount().compareTo(BigDecimal.ZERO), 0);
    assertEquals(invoicePaymentPurchase.getTransactions().get(0).getTransactionType(), TransactionType.PURCHASE.toString());
    assertEquals(invoicePaymentPurchase.getTransactions().get(0).getAmount().compareTo(BigDecimal.valueOf(249.95)), 0);
    // INVOICE PAYMENT FOR EXTERNAL REFUND
    final InvoicePayment creditInvoicePayment = invoicePaymentsForAccount.get(1);
    assertTrue(creditInvoicePayment.equals(invoicePaymentExternalRefund));
    assertEquals(creditInvoicePayment.getPurchasedAmount().compareTo(BigDecimal.ZERO), 0);
    assertEquals(creditInvoicePayment.getCreditedAmount().compareTo(BigDecimal.valueOf(249.95)), 0);
    assertEquals(creditInvoicePayment.getTransactions().size(), 1);
    assertEquals(creditInvoicePayment.getTransactions().get(0).getTransactionType(), TransactionType.CREDIT.toString());
    assertEquals(creditInvoicePayment.getTransactions().get(0).getAmount().compareTo(BigDecimal.valueOf(249.95)), 0);
}
Also used : InvoicePayment(org.killbill.billing.client.model.InvoicePayment) InvoicePayments(org.killbill.billing.client.model.InvoicePayments)

Example 5 with InvoicePayments

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

the class TestChargeback method getPayment.

private Payment getPayment(final Invoice invoice) throws KillBillClientException {
    final InvoicePayments payments = killBillClient.getInvoicePayment(invoice.getInvoiceId());
    assertNotNull(payments);
    assertEquals(payments.size(), 1);
    return payments.get(0);
}
Also used : InvoicePayments(org.killbill.billing.client.model.InvoicePayments)

Aggregations

InvoicePayments (org.killbill.billing.client.model.InvoicePayments)7 Test (org.testng.annotations.Test)5 Account (org.killbill.billing.client.model.Account)4 InvoicePayment (org.killbill.billing.client.model.InvoicePayment)3 DateTime (org.joda.time.DateTime)2 Invoice (org.killbill.billing.client.model.Invoice)2 Predicate (com.google.common.base.Predicate)1 UUID (java.util.UUID)1 RequestOptions (org.killbill.billing.client.RequestOptions)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 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)1 Payments (org.killbill.billing.client.model.Payments)1