Search in sources :

Example 11 with ExpectedPaymentCheck

use of org.killbill.billing.beatrix.util.PaymentChecker.ExpectedPaymentCheck in project killbill by killbill.

the class TestPaymentRefund method setupRefundTest.

private void setupRefundTest() throws Exception {
    final int billingDay = 31;
    initialCreationDate = new DateTime(2012, 2, 1, 0, 3, 42, 0, testTimeZone);
    account = createAccountWithNonOsgiPaymentMethod(getAccountData(billingDay));
    // set clock to the initial start date
    clock.setTime(initialCreationDate);
    invoiceItemCount = 0;
    //
    // CREATE SUBSCRIPTION AND EXPECT BOTH EVENTS: NextEvent.CREATE, NextEvent.BLOCK NextEvent.INVOICE
    //
    final DefaultEntitlement bpEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "externalKey", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
    assertNotNull(bpEntitlement);
    invoiceChecker.checkInvoice(account.getId(), ++invoiceItemCount, callContext, new ExpectedInvoiceItemCheck(initialCreationDate.toLocalDate(), null, InvoiceItemType.FIXED, new BigDecimal("0")));
    // No end date for the trial item (fixed price of zero), and CTD should be today (i.e. when the trial started)
    invoiceChecker.checkChargedThroughDate(bpEntitlement.getId(), clock.getUTCToday(), callContext);
    setDateAndCheckForCompletion(new DateTime(2012, 3, 2, 23, 59, 59, 0, testTimeZone), NextEvent.PHASE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    invoice = invoiceChecker.checkInvoice(account.getId(), ++invoiceItemCount, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 3, 2), new LocalDate(2012, 3, 31), InvoiceItemType.RECURRING, new BigDecimal("233.82")));
    payment = paymentChecker.checkPayment(account.getId(), 1, callContext, new ExpectedPaymentCheck(new LocalDate(2012, 3, 2), new BigDecimal("233.82"), TransactionStatus.SUCCESS, invoice.getId(), Currency.USD));
    // Filter and extract UUId from all Recuring invoices
    invoiceItems = new HashSet<UUID>(Collections2.transform(Collections2.filter(invoice.getInvoiceItems(), new Predicate<InvoiceItem>() {

        @Override
        public boolean apply(@Nullable final InvoiceItem invoiceItem) {
            return invoiceItem.getInvoiceItemType() == InvoiceItemType.RECURRING;
        }
    }), new Function<InvoiceItem, UUID>() {

        @Nullable
        @Override
        public UUID apply(@Nullable final InvoiceItem invoiceItem) {
            return invoiceItem.getId();
        }
    }));
}
Also used : InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) ExpectedInvoiceItemCheck(org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) ExpectedPaymentCheck(org.killbill.billing.beatrix.util.PaymentChecker.ExpectedPaymentCheck) Predicate(com.google.common.base.Predicate) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) UUID(java.util.UUID) Nullable(javax.annotation.Nullable)

Aggregations

BigDecimal (java.math.BigDecimal)11 LocalDate (org.joda.time.LocalDate)11 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)11 ExpectedPaymentCheck (org.killbill.billing.beatrix.util.PaymentChecker.ExpectedPaymentCheck)11 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)11 Account (org.killbill.billing.account.api.Account)10 Invoice (org.killbill.billing.invoice.api.Invoice)10 Test (org.testng.annotations.Test)10 DateTime (org.joda.time.DateTime)8 Payment (org.killbill.billing.payment.api.Payment)8 AccountData (org.killbill.billing.account.api.AccountData)7 UUID (java.util.UUID)5 HashMap (java.util.HashMap)3 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)3 ArrayList (java.util.ArrayList)2 Predicate (com.google.common.base.Predicate)1 Nullable (javax.annotation.Nullable)1 Entitlement (org.killbill.billing.entitlement.api.Entitlement)1 Subscription (org.killbill.billing.entitlement.api.Subscription)1 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)1