Search in sources :

Example 31 with InvoicePayment

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

the class TestChargeback method testAddChargebackForDeletedPaymentMethod.

@Test(groups = "slow", description = "Can add a chargeback for deleted payment methods")
public void testAddChargebackForDeletedPaymentMethod() throws Exception {
    final InvoicePayment payment = createAccountWithInvoiceAndPayment();
    // Check the payment method exists
    assertEquals(accountApi.getAccount(payment.getAccountId(), requestOptions).getPaymentMethodId(), payment.getPaymentMethodId());
    assertEquals(paymentMethodApi.getPaymentMethod(payment.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions).getAccountId(), payment.getAccountId());
    // Delete the payment method
    paymentMethodApi.deletePaymentMethod(payment.getPaymentMethodId(), true, false, NULL_PLUGIN_PROPERTIES, requestOptions);
    // Check the payment method was deleted
    assertNull(accountApi.getAccount(payment.getAccountId(), requestOptions).getPaymentMethodId());
    createAndVerifyChargeback(payment);
}
Also used : InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Test(org.testng.annotations.Test)

Example 32 with InvoicePayment

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

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

Example 34 with InvoicePayment

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

the class TestChargeback method testAddChargeback.

@Test(groups = "slow", description = "Can create a chargeback")
public void testAddChargeback() throws Exception {
    final InvoicePayment payment = createAccountWithInvoiceAndPayment();
    createAndVerifyChargeback(payment);
}
Also used : InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Test(org.testng.annotations.Test)

Aggregations

InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)34 Test (org.testng.annotations.Test)28 InvoicePaymentTransaction (org.killbill.billing.client.model.gen.InvoicePaymentTransaction)21 Account (org.killbill.billing.client.model.gen.Account)18 Invoice (org.killbill.billing.client.model.gen.Invoice)14 Payment (org.killbill.billing.client.model.gen.Payment)13 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)12 DateTime (org.joda.time.DateTime)9 Payments (org.killbill.billing.client.model.Payments)9 Invoices (org.killbill.billing.client.model.Invoices)8 BigDecimal (java.math.BigDecimal)7 PaymentTransaction (org.killbill.billing.client.model.gen.PaymentTransaction)7 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)6 KillBillClientException (org.killbill.billing.client.KillBillClientException)5 PaymentMethod (org.killbill.billing.client.model.gen.PaymentMethod)3 UUID (java.util.UUID)2 RequestOptions (org.killbill.billing.client.RequestOptions)1 AccountTimeline (org.killbill.billing.client.model.gen.AccountTimeline)1 AuditLog (org.killbill.billing.client.model.gen.AuditLog)1 PaymentMethodPluginDetail (org.killbill.billing.client.model.gen.PaymentMethodPluginDetail)1