Search in sources :

Example 11 with InvoicePayment

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

the class TestInvoicePayment method setupScenarioWithPayment.

private InvoicePayment setupScenarioWithPayment(final boolean invoicePaymentSuccess) throws Exception {
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice("Shotgun", invoicePaymentSuccess, true);
    final List<InvoicePayment> paymentsForAccount = accountApi.getInvoicePayments(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    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 = paymentMethodApi.getPaymentMethod(paymentMethodId, NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertEquals(paymentMethodJson.getPaymentMethodId(), paymentMethodId);
    Assert.assertEquals(paymentMethodJson.getAccountId(), accountJson.getAccountId());
    // Verify the refunds
    final List<PaymentTransaction> objRefundFromJson = getInvoicePaymentTransactions(paymentsForAccount, TransactionType.REFUND);
    Assert.assertEquals(objRefundFromJson.size(), 0);
    return paymentJson;
}
Also used : InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) PaymentMethod(org.killbill.billing.client.model.gen.PaymentMethod) UUID(java.util.UUID)

Example 12 with InvoicePayment

use of org.killbill.billing.client.model.gen.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(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 = 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));
    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 13 with InvoicePayment

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

the class TestInvoicePayment method testRetrievePayment.

@Test(groups = "slow")
public void testRetrievePayment() throws Exception {
    final InvoicePayment paymentJson = setupScenarioWithPayment(true);
    final Payment retrievedPaymentJson = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    verifyInvoicePaymentAgainstPayment(paymentJson, retrievedPaymentJson);
}
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) Test(org.testng.annotations.Test)

Example 14 with InvoicePayment

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

the class TestOverdue method testOverdueStatus.

@Test(groups = "slow", description = "Can retrieve the account overdue status")
public void testOverdueStatus() throws Exception {
    // Create an account without a payment method
    final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // Get the invoices
    final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
    // 2 invoices but look for the non zero dollar one
    assertEquals(invoices.size(), 2);
    // We're still clear - see the configuration
    Assert.assertTrue(accountApi.getOverdueAccount(accountJson.getAccountId(), requestOptions).isClearState());
    callbackServlet.pushExpectedEvents(ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_FAILED, ExtBusEventType.BLOCKING_STATE, ExtBusEventType.OVERDUE_CHANGE);
    clock.addDays(30);
    callbackServlet.assertListenerStatus();
    Assert.assertEquals(accountApi.getOverdueAccount(accountJson.getAccountId(), requestOptions).getName(), "OD1");
    callbackServlet.pushExpectedEvents(ExtBusEventType.TAG_CREATION, ExtBusEventType.BLOCKING_STATE, ExtBusEventType.OVERDUE_CHANGE);
    clock.addDays(10);
    callbackServlet.assertListenerStatus();
    Assert.assertEquals(accountApi.getOverdueAccount(accountJson.getAccountId(), requestOptions).getName(), "OD2");
    callbackServlet.pushExpectedEvents(ExtBusEventType.BLOCKING_STATE, ExtBusEventType.OVERDUE_CHANGE);
    clock.addDays(10);
    callbackServlet.assertListenerStatus();
    Assert.assertEquals(accountApi.getOverdueAccount(accountJson.getAccountId(), requestOptions).getName(), "OD3");
    // Post external payments, paying the most recent invoice first: this is to avoid a race condition where
    // a refresh overdue notification kicks in after the first payment, which makes the account goes CLEAR and
    // triggers an AUTO_INVOICE_OFF tag removal (hence adjustment of the other invoices balance).
    final Invoices invoicesForAccount = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
    final List<Invoice> mostRecentInvoiceFirst = Ordering.<Invoice>from(new Comparator<Invoice>() {

        @Override
        public int compare(final Invoice invoice1, final Invoice invoice2) {
            return invoice1.getInvoiceDate().compareTo(invoice2.getInvoiceDate());
        }
    }).reverse().sortedCopy(invoicesForAccount);
    for (final Invoice invoice : mostRecentInvoiceFirst) {
        if (invoice.getBalance().compareTo(BigDecimal.ZERO) > 0) {
            final InvoicePayment invoicePayment = new InvoicePayment();
            invoicePayment.setPurchasedAmount(invoice.getAmount());
            invoicePayment.setAccountId(accountJson.getAccountId());
            invoicePayment.setTargetInvoiceId(invoice.getInvoiceId());
            callbackServlet.pushExpectedEvents(ExtBusEventType.INVOICE_PAYMENT_SUCCESS, ExtBusEventType.PAYMENT_SUCCESS);
            invoiceApi.createInstantPayment(invoice.getInvoiceId(), invoicePayment, true, ImmutableList.of(), NULL_PLUGIN_PROPERTIES, requestOptions);
            callbackServlet.assertListenerStatus();
        }
    }
    // Wait a bit for overdue to pick up the payment events...
    callbackServlet.pushExpectedEvents(ExtBusEventType.TAG_DELETION, ExtBusEventType.BLOCKING_STATE, ExtBusEventType.OVERDUE_CHANGE);
    callbackServlet.assertListenerStatus();
    // Verify we're in clear state
    Assert.assertTrue(accountApi.getOverdueAccount(accountJson.getAccountId(), requestOptions).isClearState());
}
Also used : Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Invoice(org.killbill.billing.client.model.gen.Invoice) Invoices(org.killbill.billing.client.model.Invoices) Test(org.testng.annotations.Test)

Example 15 with InvoicePayment

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

the class TestExternalRefund method testAutomaticPaymentAndExternalRefund.

@Test(groups = "slow", description = "#255 - Scenario 2a - Can refund an automatic payment though an external refund")
public void testAutomaticPaymentAndExternalRefund() 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();
    // delete PM
    paymentMethodApi.deletePaymentMethod(accountJson.getPaymentMethodId(), true, true, NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payments paymentsForAccount = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payment payment = paymentsForAccount.get(paymentsForAccount.size() - 1);
    // external refund
    final InvoicePaymentTransaction invoicePaymentTransactionRequest = new InvoicePaymentTransaction();
    invoicePaymentTransactionRequest.setAmount(BigDecimal.valueOf(249.95));
    invoicePaymentTransactionRequest.setCurrency(accountJson.getCurrency());
    invoicePaymentTransactionRequest.setPaymentId(payment.getPaymentId());
    final InvoicePayment invoicePaymentExternalRefund = invoicePaymentApi.createRefundWithAdjustments(payment.getPaymentId(), invoicePaymentTransactionRequest, true, null, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertNotNull(invoicePaymentExternalRefund);
    assertInvoicePaymentsExternalRefund(accountJson.getAccountId(), invoicePaymentExternalRefund);
    assertRefundInvoiceNoAdjustments(accountJson.getAccountId());
    assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.valueOf(249.95), 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) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) Payments(org.killbill.billing.client.model.Payments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) DateTime(org.joda.time.DateTime) 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