Search in sources :

Example 21 with InvoicePayment

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

the class TestInvoicePayment method testFullRefundWithNoAdjustment.

@Test(groups = "slow", description = "Can create a full refund with no adjustment")
public void testFullRefundWithNoAdjustment() throws Exception {
    final InvoicePayment invoicePaymentJson = setupScenarioWithPayment();
    // Issue a refund for the full amount
    final BigDecimal refundAmount = invoicePaymentJson.getPurchasedAmount();
    final BigDecimal expectedInvoiceBalance = refundAmount;
    // Post and verify the refund
    final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
    refund.setPaymentId(invoicePaymentJson.getPaymentId());
    refund.setAmount(refundAmount);
    final Payment paymentAfterRefundJson = killBillClient.createInvoicePaymentRefund(refund, createdBy, reason, comment);
    verifyRefund(invoicePaymentJson, paymentAfterRefundJson, refundAmount);
    // Verify the invoice balance
    verifyInvoice(invoicePaymentJson, expectedInvoiceBalance);
}
Also used : 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) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 22 with InvoicePayment

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

the class TestInvoicePayment method testPartialRefundWithFullInvoiceItemAdjustment.

@Test(groups = "slow", description = "Cannot create invoice item adjustments for more than the refund amount")
public void testPartialRefundWithFullInvoiceItemAdjustment() throws Exception {
    final InvoicePayment paymentJson = setupScenarioWithPayment();
    // Get the individual items for the invoice
    final Invoice invoice = killBillClient.getInvoice(paymentJson.getTargetInvoiceId(), true, false, requestOptions);
    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 = invoice.getBalance();
    // Post and verify the refund
    final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
    refund.setPaymentId(paymentJson.getPaymentId());
    refund.setAmount(refundAmount);
    refund.setIsAdjusted(true);
    final InvoiceItem adjustment = new InvoiceItem();
    adjustment.setInvoiceItemId(itemToAdjust.getInvoiceItemId());
    // Ask for an adjustment for the full amount (bigger than the refund amount)
    adjustment.setAmount(itemToAdjust.getAmount());
    refund.setAdjustments(ImmutableList.<InvoiceItem>of(adjustment));
    final Payment paymentAfterRefundJson = killBillClient.createInvoicePaymentRefund(refund, requestOptions);
    // The refund did go through
    verifyRefund(paymentJson, paymentAfterRefundJson, refundAmount);
    // But not the adjustments
    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 23 with InvoicePayment

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

the class TestInvoicePayment method testRefundWithFullInvoiceItemAdjustment.

@Test(groups = "slow", description = "Can create a full refund with invoice item adjustment")
public void testRefundWithFullInvoiceItemAdjustment() 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 the full amount
    final BigDecimal refundAmount = itemToAdjust.getAmount();
    final BigDecimal expectedInvoiceBalance = BigDecimal.ZERO;
    // Post and verify the refund
    final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
    refund.setPaymentId(paymentJson.getPaymentId());
    refund.setAmount(refundAmount);
    refund.setIsAdjusted(true);
    final InvoiceItem adjustment = new InvoiceItem();
    adjustment.setInvoiceItemId(itemToAdjust.getInvoiceItemId());
    /* null amount means full adjustment for that item */
    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 24 with InvoicePayment

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

the class TestInvoicePayment method testPartialRefundWithNoAdjustment.

@Test(groups = "slow", description = "Can create a partial refund with no adjustment")
public void testPartialRefundWithNoAdjustment() throws Exception {
    final InvoicePayment paymentJson = setupScenarioWithPayment();
    // Issue a refund for a fraction of the amount
    final BigDecimal refundAmount = getFractionOfAmount(paymentJson.getPurchasedAmount());
    final BigDecimal expectedInvoiceBalance = refundAmount;
    // Post and verify the refund
    final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
    refund.setPaymentId(paymentJson.getPaymentId());
    refund.setAmount(refundAmount);
    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) InvoicePaymentTransaction(org.killbill.billing.client.model.InvoicePaymentTransaction) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 25 with InvoicePayment

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

the class TestInvoicePayment method testWithFailedInvoicePayment.

@Test(groups = "slow")
public void testWithFailedInvoicePayment() throws Exception {
    mockPaymentProviderPlugin.makeNextPaymentFailWithError();
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    InvoicePayments invoicePayments = killBillClient.getInvoicePaymentsForAccount(accountJson.getAccountId(), requestOptions);
    assertEquals(invoicePayments.size(), 1);
    final InvoicePayment invoicePayment = invoicePayments.get(0);
    // Verify targetInvoiceId is not Null. See #593
    assertNotNull(invoicePayment.getTargetInvoiceId());
    final Invoices invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), requestOptions);
    assertEquals(invoices.size(), 2);
    final Invoice invoice = invoices.get(1);
    // Verify this is the correct value
    assertEquals(invoicePayment.getTargetInvoiceId(), invoice.getInvoiceId());
    // Make a payment and verify both invoice payment point to the same targetInvoiceId
    killBillClient.payAllInvoices(accountJson.getAccountId(), false, null, requestOptions);
    invoicePayments = killBillClient.getInvoicePaymentsForAccount(accountJson.getAccountId(), requestOptions);
    assertEquals(invoicePayments.size(), 2);
    for (final InvoicePayment cur : invoicePayments) {
        assertEquals(cur.getTargetInvoiceId(), invoice.getInvoiceId());
    }
}
Also used : Account(org.killbill.billing.client.model.Account) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) Invoice(org.killbill.billing.client.model.Invoice) Invoices(org.killbill.billing.client.model.Invoices) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

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