Search in sources :

Example 1 with InvoicePaymentTransaction

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

the class TestAccountTimeline method testAccountTimelineWithAudits.

@Test(groups = "slow", description = "Can retrieve the timeline with audits")
public void testAccountTimelineWithAudits() throws Exception {
    final DateTime startTime = clock.getUTCNow();
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    final DateTime endTime = clock.getUTCNow();
    // Add credit
    final Invoice invoice = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions).get(1);
    final BigDecimal creditAmount = BigDecimal.ONE;
    final InvoiceItem credit = new InvoiceItem();
    credit.setAccountId(accountJson.getAccountId());
    credit.setAmount(creditAmount);
    final InvoiceItems credits = new InvoiceItems();
    credits.add(credit);
    creditApi.createCredits(credits, true, NULL_PLUGIN_PROPERTIES, requestOptions);
    // Add refund
    final Payment postedPayment = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions).get(0);
    final BigDecimal refundAmount = BigDecimal.ONE;
    final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
    refund.setPaymentId(postedPayment.getPaymentId());
    refund.setAmount(refundAmount);
    invoicePaymentApi.createRefundWithAdjustments(postedPayment.getPaymentId(), refund, accountJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    // Add chargeback
    final BigDecimal chargebackAmount = BigDecimal.ONE;
    final InvoicePaymentTransaction chargeback = new InvoicePaymentTransaction();
    chargeback.setPaymentId(postedPayment.getPaymentId());
    chargeback.setAmount(chargebackAmount);
    invoicePaymentApi.createChargeback(postedPayment.getPaymentId(), chargeback, NULL_PLUGIN_PROPERTIES, requestOptions);
    // Verify payments
    verifyPayments(accountJson.getAccountId(), startTime, endTime, refundAmount, chargebackAmount);
    // Verify invoices
    verifyInvoices(accountJson.getAccountId(), startTime, endTime);
    // Verify credits
    verifyCredits(accountJson.getAccountId(), startTime, endTime, creditAmount);
    // Verify bundles
    verifyBundles(accountJson.getAccountId(), startTime, endTime);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) 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) InvoiceItems(org.killbill.billing.client.model.InvoiceItems) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 2 with InvoicePaymentTransaction

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

the class TestChargeback method testInvoicePaymentDoesNotExist.

@Test(groups = "slow", description = "Cannot add a chargeback for non existent payment")
public void testInvoicePaymentDoesNotExist() {
    final InvoicePaymentTransaction input = new InvoicePaymentTransaction();
    input.setPaymentId(input.getPaymentId());
    input.setAmount(BigDecimal.TEN);
    try {
        invoicePaymentApi.createChargeback(input.getPaymentId(), input, NULL_PLUGIN_PROPERTIES, requestOptions);
        fail();
    } catch (NullPointerException e) {
    } catch (KillBillClientException e) {
        fail();
    }
}
Also used : InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Example 3 with InvoicePaymentTransaction

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

the class TestChargeback method testMultipleChargeback.

@Test(groups = "slow", description = "Can create multiple chargebacks")
public void testMultipleChargeback() throws Exception {
    final InvoicePayment payment = createAccountWithInvoiceAndPayment();
    // We get a 249.95 payment so we do 4 chargeback and then the fifth should fail
    final InvoicePaymentTransaction input = new InvoicePaymentTransaction();
    input.setPaymentId(payment.getPaymentId());
    input.setAmount(new BigDecimal("50.00"));
    int count = 4;
    while (count-- > 0) {
        assertNotNull(invoicePaymentApi.createChargeback(payment.getPaymentId(), input, NULL_PLUGIN_PROPERTIES, requestOptions));
    }
    // Last attempt should fail because this is more than the Payment
    final InvoicePayment foo = invoicePaymentApi.createChargeback(payment.getPaymentId(), input, NULL_PLUGIN_PROPERTIES, requestOptions);
    final InvoicePayments payments = accountApi.getInvoicePayments(payment.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final List<PaymentTransaction> transactions = getInvoicePaymentTransactions(payments, TransactionType.CHARGEBACK);
    Assert.assertEquals(transactions.size(), 5);
    int found = 0;
    for (final PaymentTransaction transaction : transactions) {
        if (transaction.getStatus().equals(TransactionStatus.SUCCESS)) {
            assertTrue(transaction.getAmount().compareTo(input.getAmount()) == 0);
            assertEquals(transaction.getPaymentId(), input.getPaymentId());
            found++;
        } else {
            assertEquals(transaction.getStatus(), TransactionStatus.PAYMENT_FAILURE);
            found++;
        }
    }
    assertEquals(found, 5);
}
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) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 4 with InvoicePaymentTransaction

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

the class TestExceptions method testExceptionMapping.

@Test(groups = "slow", enabled = false)
public void testExceptionMapping() throws Exception {
    final Account account = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    final List<InvoicePayment> payments = accountApi.getInvoicePayments(account.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final InvoicePaymentTransaction input = new InvoicePaymentTransaction();
    input.setPaymentId(payments.get(0).getPaymentId());
    input.setAmount(BigDecimal.TEN.negate());
    try {
        invoicePaymentApi.createChargeback(payments.get(0).getPaymentId(), input, NULL_PLUGIN_PROPERTIES, requestOptions);
        fail();
    } catch (final KillBillClientException e) {
        Assert.assertEquals(e.getBillingException().getClassName(), InvoiceApiException.class.getName());
        Assert.assertEquals(e.getBillingException().getCode(), (Integer) ErrorCode.CHARGE_BACK_AMOUNT_IS_NEGATIVE.getCode());
        Assert.assertFalse(e.getBillingException().getStackTrace().isEmpty());
    }
}
Also used : Account(org.killbill.billing.client.model.gen.Account) 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 5 with InvoicePaymentTransaction

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

the class TestExternalRefund method testAutomaticPaymentAndRefundWithAdjustments.

@Test(groups = "slow", description = "#255 - Scenario 0 - Can refund an automatic payment over item adjustments. This is a test to validate the correct behaviour.")
public void testAutomaticPaymentAndRefundWithAdjustments() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    final Payments paymentsForAccount = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payment payment = paymentsForAccount.get(paymentsForAccount.size() - 1);
    Invoices invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, true, false, false, null, AuditLevel.NONE, requestOptions);
    final List<InvoiceItem> itemsToBeAdjusted = invoices.get(1).getItems();
    // regular refund
    final InvoicePaymentTransaction invoicePaymentTransactionRequest = new InvoicePaymentTransaction();
    invoicePaymentTransactionRequest.setAmount(BigDecimal.valueOf(249.95));
    invoicePaymentTransactionRequest.setCurrency(accountJson.getCurrency());
    invoicePaymentTransactionRequest.setPaymentId(payment.getPaymentId());
    invoicePaymentTransactionRequest.setIsAdjusted(true);
    invoicePaymentTransactionRequest.setAdjustments(itemsToBeAdjusted);
    invoicePaymentApi.createRefundWithAdjustments(payment.getPaymentId(), invoicePaymentTransactionRequest, payment.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final InvoicePayment invoicePaymentRefund = invoicePaymentApi.getInvoicePayment(payment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertNotNull(invoicePaymentRefund);
    assertSingleInvoicePaymentRefund(invoicePaymentRefund);
    assertRefundInvoiceAdjustments(accountJson.getAccountId());
    assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.ZERO, BigDecimal.ZERO);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) Payments(org.killbill.billing.client.model.Payments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) Invoices(org.killbill.billing.client.model.Invoices) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

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