Search in sources :

Example 1 with InvoicePayment

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

the class TestInvoicePayment method testRetrievePayment.

@Test(groups = "slow")
public void testRetrievePayment() throws Exception {
    final InvoicePayment paymentJson = setupScenarioWithPayment();
    final Payment retrievedPaymentJson = killBillClient.getPayment(paymentJson.getPaymentId(), false);
    Assert.assertTrue(retrievedPaymentJson.equals((Payment) paymentJson));
}
Also used : InvoicePayment(org.killbill.billing.client.model.InvoicePayment) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) Payment(org.killbill.billing.client.model.Payment) Test(org.testng.annotations.Test)

Example 2 with InvoicePayment

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

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

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

the class TestInvoicePayment method verifyRefund.

private void verifyRefund(final InvoicePayment paymentJson, final Payment paymentAfterRefund, final BigDecimal refundAmount) throws KillBillClientException {
    final List<PaymentTransaction> transactions = getPaymentTransactions(ImmutableList.of(paymentAfterRefund), TransactionType.REFUND.toString());
    Assert.assertEquals(transactions.size(), 1);
    final PaymentTransaction refund = transactions.get(0);
    Assert.assertEquals(refund.getPaymentId(), paymentJson.getPaymentId());
    Assert.assertEquals(refund.getAmount().setScale(2, RoundingMode.HALF_UP), refundAmount.setScale(2, RoundingMode.HALF_UP));
    Assert.assertEquals(refund.getCurrency(), DEFAULT_CURRENCY);
    Assert.assertEquals(refund.getStatus(), "SUCCESS");
    Assert.assertEquals(refund.getEffectiveDate().getYear(), clock.getUTCNow().getYear());
    Assert.assertEquals(refund.getEffectiveDate().getMonthOfYear(), clock.getUTCNow().getMonthOfYear());
    Assert.assertEquals(refund.getEffectiveDate().getDayOfMonth(), clock.getUTCNow().getDayOfMonth());
    // Verify the refund via the payment API
    final Payment retrievedPaymentJson = killBillClient.getPayment(paymentJson.getPaymentId(), true);
    Assert.assertEquals(retrievedPaymentJson.getPaymentId(), paymentJson.getPaymentId());
    Assert.assertEquals(retrievedPaymentJson.getPurchasedAmount().setScale(2, RoundingMode.HALF_UP), paymentJson.getPurchasedAmount().setScale(2, RoundingMode.HALF_UP));
    Assert.assertEquals(retrievedPaymentJson.getAccountId(), paymentJson.getAccountId());
    Assert.assertEquals(retrievedPaymentJson.getCurrency(), paymentJson.getCurrency());
    Assert.assertEquals(retrievedPaymentJson.getPaymentMethodId(), paymentJson.getPaymentMethodId());
}
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)

Example 5 with InvoicePayment

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

the class TestInvoicePayment method setupScenarioWithPayment.

private InvoicePayment setupScenarioWithPayment() throws Exception {
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    final List<InvoicePayment> paymentsForAccount = killBillClient.getInvoicePaymentsForAccount(accountJson.getAccountId());
    Assert.assertEquals(paymentsForAccount.size(), 1);
    final InvoicePayment paymentJson = paymentsForAccount.get(0);
    // Check the PaymentMethod from paymentMethodId returned in the Payment object
    final UUID paymentMethodId = paymentJson.getPaymentMethodId();
    final PaymentMethod paymentMethodJson = killBillClient.getPaymentMethod(paymentMethodId, true);
    Assert.assertEquals(paymentMethodJson.getPaymentMethodId(), paymentMethodId);
    Assert.assertEquals(paymentMethodJson.getAccountId(), accountJson.getAccountId());
    // Verify the refunds
    final List<PaymentTransaction> objRefundFromJson = getPaymentTransactions(paymentsForAccount, TransactionType.REFUND.toString());
    Assert.assertEquals(objRefundFromJson.size(), 0);
    return paymentJson;
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) InvoicePaymentTransaction(org.killbill.billing.client.model.InvoicePaymentTransaction) Account(org.killbill.billing.client.model.Account) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) PaymentMethod(org.killbill.billing.client.model.PaymentMethod) UUID(java.util.UUID)

Aggregations

InvoicePayment (org.killbill.billing.client.model.InvoicePayment)25 Test (org.testng.annotations.Test)20 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)19 Payment (org.killbill.billing.client.model.Payment)14 Account (org.killbill.billing.client.model.Account)13 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)10 DateTime (org.joda.time.DateTime)9 Invoice (org.killbill.billing.client.model.Invoice)9 Invoices (org.killbill.billing.client.model.Invoices)8 Payments (org.killbill.billing.client.model.Payments)8 InvoiceItem (org.killbill.billing.client.model.InvoiceItem)7 BigDecimal (java.math.BigDecimal)6 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)6 PaymentMethod (org.killbill.billing.client.model.PaymentMethod)3 UUID (java.util.UUID)2 KillBillClientException (org.killbill.billing.client.KillBillClientException)1 AccountTimeline (org.killbill.billing.client.model.AccountTimeline)1 AuditLog (org.killbill.billing.client.model.AuditLog)1 PaymentMethodPluginDetail (org.killbill.billing.client.model.PaymentMethodPluginDetail)1 AuditLevel (org.killbill.billing.util.api.AuditLevel)1