Search in sources :

Example 16 with InvoicePaymentTransaction

use of org.killbill.billing.client.model.gen.InvoicePaymentTransaction 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(true);
    // Get the individual items for the invoice
    final Invoice invoice = invoiceApi.getInvoice(paymentJson.getTargetInvoiceId(), false, AuditLevel.NONE, 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));
    invoicePaymentApi.createRefundWithAdjustments(paymentJson.getPaymentId(), refund, paymentJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payment paymentAfterRefundJson = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, 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.gen.InvoicePayment) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) Invoice(org.killbill.billing.client.model.gen.Invoice) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 17 with InvoicePaymentTransaction

use of org.killbill.billing.client.model.gen.InvoicePaymentTransaction 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(true);
    // 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);
    invoicePaymentApi.createRefundWithAdjustments(invoicePaymentJson.getPaymentId(), refund, invoicePaymentJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payment paymentAfterRefundJson = paymentApi.getPayment(invoicePaymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    verifyRefund(invoicePaymentJson, paymentAfterRefundJson, refundAmount);
    // Verify the invoice balance
    verifyInvoice(invoicePaymentJson, expectedInvoiceBalance);
}
Also used : InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 18 with InvoicePaymentTransaction

use of org.killbill.billing.client.model.gen.InvoicePaymentTransaction 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(true);
    // Get the individual items for the invoice
    final Invoice invoice = invoiceApi.getInvoice(paymentJson.getTargetInvoiceId(), false, AuditLevel.NONE, requestOptions);
    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));
    invoicePaymentApi.createRefundWithAdjustments(paymentJson.getPaymentId(), refund, paymentJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payment paymentAfterRefundJson = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    verifyRefund(paymentJson, paymentAfterRefundJson, refundAmount);
    // Verify the invoice balance
    verifyInvoice(paymentJson, expectedInvoiceBalance);
}
Also used : InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) Invoice(org.killbill.billing.client.model.gen.Invoice) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 19 with InvoicePaymentTransaction

use of org.killbill.billing.client.model.gen.InvoicePaymentTransaction in project killbill by killbill.

the class TestChargeback method testBadRequest.

@Test(groups = "slow", description = "Cannot add a badly formatted chargeback")
public void testBadRequest() throws Exception {
    final InvoicePayment payment = createAccountWithInvoiceAndPayment();
    final InvoicePaymentTransaction input = new InvoicePaymentTransaction();
    input.setPaymentId(payment.getPaymentId());
    try {
        invoicePaymentApi.createChargeback(payment.getPaymentId(), input, NULL_PLUGIN_PROPERTIES, requestOptions);
        fail();
    } catch (final KillBillClientException e) {
    }
}
Also used : InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Example 20 with InvoicePaymentTransaction

use of org.killbill.billing.client.model.gen.InvoicePaymentTransaction in project killbill by killbill.

the class TestChargeback method createAndVerifyChargeback.

private void createAndVerifyChargeback(final InvoicePayment payment) throws KillBillClientException {
    List<Invoice> invoices = accountApi.getInvoicesForAccount(payment.getAccountId(), null, null, null, requestOptions);
    // We should have two invoices, one for the trial (zero dollar amount) and one for the first month
    Assert.assertEquals(invoices.size(), 2);
    Assert.assertEquals(invoices.get(1).getBalance().compareTo(BigDecimal.ZERO), 0);
    // Create the chargeback
    final InvoicePaymentTransaction chargeback = new InvoicePaymentTransaction();
    chargeback.setPaymentId(payment.getPaymentId());
    chargeback.setAmount(BigDecimal.TEN);
    final InvoicePayment chargebackJson = invoicePaymentApi.createChargeback(payment.getPaymentId(), chargeback, NULL_PLUGIN_PROPERTIES, requestOptions);
    final List<PaymentTransaction> chargebackTransactions = getInvoicePaymentTransactions(ImmutableList.of(chargebackJson), TransactionType.CHARGEBACK);
    assertEquals(chargebackTransactions.size(), 1);
    assertEquals(chargebackTransactions.get(0).getAmount().compareTo(chargeback.getAmount()), 0);
    assertEquals(chargebackTransactions.get(0).getPaymentId(), chargeback.getPaymentId());
    // Find the chargeback by account
    final List<InvoicePayment> payments = accountApi.getInvoicePayments(payment.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final List<PaymentTransaction> transactions = getInvoicePaymentTransactions(payments, TransactionType.CHARGEBACK);
    Assert.assertEquals(transactions.size(), 1);
    assertEquals(transactions.get(0).getAmount().compareTo(chargeback.getAmount()), 0);
    assertEquals(transactions.get(0).getPaymentId(), chargeback.getPaymentId());
    // Verify invoice balance
    invoices = accountApi.getInvoicesForAccount(payment.getAccountId(), null, null, null, requestOptions);
    Assert.assertEquals(invoices.size(), 2);
    Assert.assertEquals(invoices.get(1).getBalance().compareTo(BigDecimal.ZERO), 1);
}
Also used : InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Invoice(org.killbill.billing.client.model.gen.Invoice) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction)

Aggregations

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