Search in sources :

Example 21 with FixedPriceInvoiceItem

use of org.killbill.billing.invoice.model.FixedPriceInvoiceItem in project killbill by killbill.

the class TestDefaultInvoiceItemFormatter method testBasicUSD.

@Test(groups = "fast", enabled = false, description = "JDK dependent")
public void testBasicUSD() throws Exception {
    final FixedPriceInvoiceItem fixedItemUSD = new FixedPriceInvoiceItem(UUID.randomUUID(), UUID.randomUUID(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), null, new LocalDate(), new BigDecimal("-1114.751625346"), Currency.USD);
    checkOutput(fixedItemUSD, "{{#invoiceItem}}<td class=\"amount\">{{formattedAmount}}</td>{{/invoiceItem}}", "<td class=\"amount\">($1,114.75)</td>", LocaleUtils.toLocale("en_US"));
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 22 with FixedPriceInvoiceItem

use of org.killbill.billing.invoice.model.FixedPriceInvoiceItem in project killbill by killbill.

the class TestDefaultInvoiceItemFormatter method testFormattedAmount.

@Test(groups = "fast", enabled = false, description = "JDK dependent")
public void testFormattedAmount() throws Exception {
    final FixedPriceInvoiceItem fixedItemEUR = new FixedPriceInvoiceItem(UUID.randomUUID(), UUID.randomUUID(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), null, new LocalDate(), new BigDecimal("1499.95"), Currency.EUR);
    checkOutput(fixedItemEUR, "{{#invoiceItem}}<td class=\"amount\">{{formattedAmount}}</td>{{/invoiceItem}}", "<td class=\"amount\">1 499,95 €</td>", Locale.FRANCE);
    final FixedPriceInvoiceItem fixedItemUSD = new FixedPriceInvoiceItem(UUID.randomUUID(), UUID.randomUUID(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), null, new LocalDate(), new BigDecimal("-1114.751625346"), Currency.USD);
    checkOutput(fixedItemUSD, "{{#invoiceItem}}<td class=\"amount\">{{formattedAmount}}</td>{{/invoiceItem}}", "<td class=\"amount\">($1,114.75)</td>");
    // Check locale/currency mismatch (locale is set at the account level)
    final FixedPriceInvoiceItem fixedItemGBP = new FixedPriceInvoiceItem(UUID.randomUUID(), UUID.randomUUID(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), null, new LocalDate(), new BigDecimal("8.07"), Currency.GBP);
    checkOutput(fixedItemGBP, "{{#invoiceItem}}<td class=\"amount\">{{formattedAmount}}</td>{{/invoiceItem}}", "<td class=\"amount\">8,07 GBP</td>", Locale.FRANCE);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 23 with FixedPriceInvoiceItem

use of org.killbill.billing.invoice.model.FixedPriceInvoiceItem in project killbill by killbill.

the class TestFixedAndRecurringInvoiceItemGenerator method testTooManyFixedInvoiceItemsForGivenSubscriptionAndStartDatePostMerge.

// 
// 
// SAFETY_BOUNDS TESTS
// 
// 
// Simulate a bug in the generator where two fixed items for the same day and subscription end up in the resulting items
@Test(groups = "fast", description = "https://github.com/killbill/killbill/issues/664")
public void testTooManyFixedInvoiceItemsForGivenSubscriptionAndStartDatePostMerge() throws InvoiceApiException {
    final Multimap<UUID, LocalDate> createdItemsPerDayPerSubscription = LinkedListMultimap.<UUID, LocalDate>create();
    final LocalDate startDate = new LocalDate("2016-01-01");
    final Collection<InvoiceItem> resultingItems = new LinkedList<InvoiceItem>();
    final InvoiceItem fixedPriceInvoiceItem = new FixedPriceInvoiceItem(UUID.randomUUID(), clock.getUTCNow(), null, account.getId(), subscription.getBundleId(), subscription.getId(), null, "planName", "phaseName", null, "description", startDate, BigDecimal.ONE, account.getCurrency());
    resultingItems.add(fixedPriceInvoiceItem);
    resultingItems.add(fixedPriceInvoiceItem);
    try {
        fixedAndRecurringInvoiceItemGenerator.safetyBounds(resultingItems, createdItemsPerDayPerSubscription, internalCallContext);
        fail();
    } catch (final InvoiceApiException e) {
        assertEquals(e.getCode(), ErrorCode.UNEXPECTED_ERROR.getCode());
    }
    resultingItems.clear();
    for (int i = 0; i < 2; i++) {
        resultingItems.add(new FixedPriceInvoiceItem(UUID.randomUUID(), clock.getUTCNow(), null, account.getId(), subscription.getBundleId(), subscription.getId(), null, "planName", "phaseName", null, "description", startDate, // Amount shouldn't have any effect
        BigDecimal.ONE.add(new BigDecimal(i)), account.getCurrency()));
    }
    try {
        fixedAndRecurringInvoiceItemGenerator.safetyBounds(resultingItems, createdItemsPerDayPerSubscription, internalCallContext);
        fail();
    } catch (final InvoiceApiException e) {
        assertEquals(e.getCode(), ErrorCode.UNEXPECTED_ERROR.getCode());
    }
}
Also used : InvoiceApiException(org.killbill.billing.invoice.api.InvoiceApiException) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) LinkedList(java.util.LinkedList) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 24 with FixedPriceInvoiceItem

use of org.killbill.billing.invoice.model.FixedPriceInvoiceItem in project killbill by killbill.

the class InvoicePluginDispatcher method validateAndSanitizeInvoiceItemFromPlugin.

private InvoiceItem validateAndSanitizeInvoiceItemFromPlugin(final UUID originalInvoiceId, final Map<UUID, InvoiceItem> invoiceItemsByItemId, final InvoiceItem additionalInvoiceItem, final InvoicePluginApi invoicePlugin) throws InvoiceApiException {
    final InvoiceItem existingItem = invoiceItemsByItemId.get(additionalInvoiceItem.getId());
    if (!ALLOWED_INVOICE_ITEM_TYPES.contains(additionalInvoiceItem.getInvoiceItemType()) && existingItem == null) {
        log.warn("Ignoring invoice item of type {} from InvoicePlugin {}: {}", additionalInvoiceItem.getInvoiceItemType(), invoicePlugin, additionalInvoiceItem);
        throw new InvoiceApiException(ErrorCode.INVOICE_ITEM_TYPE_INVALID, additionalInvoiceItem.getInvoiceItemType());
    }
    final UUID invoiceId = MoreObjects.firstNonNull(mutableField("invoiceId", existingItem != null ? existingItem.getInvoiceId() : null, additionalInvoiceItem.getInvoiceId(), invoicePlugin), originalInvoiceId);
    final UUID additionalInvoiceId = MoreObjects.firstNonNull(additionalInvoiceItem.getId(), UUIDs.randomUUID());
    final InvoiceItemCatalogBase tmp = new InvoiceItemCatalogBase(additionalInvoiceId, mutableField("createdDate", existingItem != null ? existingItem.getCreatedDate() : null, additionalInvoiceItem.getCreatedDate(), invoicePlugin), invoiceId, immutableField("accountId", existingItem, existingItem != null ? existingItem.getAccountId() : null, additionalInvoiceItem.getAccountId(), invoicePlugin), immutableField("bundleId", existingItem, existingItem != null ? existingItem.getBundleId() : null, additionalInvoiceItem.getBundleId(), invoicePlugin), immutableField("subscriptionId", existingItem, existingItem != null ? existingItem.getSubscriptionId() : null, additionalInvoiceItem.getSubscriptionId(), invoicePlugin), mutableField("description", existingItem != null ? existingItem.getDescription() : null, additionalInvoiceItem.getDescription(), invoicePlugin), immutableField("productName", existingItem, existingItem != null ? existingItem.getProductName() : null, additionalInvoiceItem.getProductName(), invoicePlugin), immutableField("planName", existingItem, existingItem != null ? existingItem.getPlanName() : null, additionalInvoiceItem.getPlanName(), invoicePlugin), immutableField("phaseName", existingItem, existingItem != null ? existingItem.getPhaseName() : null, additionalInvoiceItem.getPhaseName(), invoicePlugin), immutableField("usageName", existingItem, existingItem != null ? existingItem.getUsageName() : null, additionalInvoiceItem.getUsageName(), invoicePlugin), immutableField("catalogEffectiveDate", existingItem, existingItem != null ? existingItem.getCatalogEffectiveDate() : null, additionalInvoiceItem.getCatalogEffectiveDate(), invoicePlugin), mutableField("prettyProductName", existingItem != null ? existingItem.getPrettyProductName() : null, additionalInvoiceItem.getPrettyProductName(), invoicePlugin), mutableField("prettyPlanName", existingItem != null ? existingItem.getPrettyPlanName() : null, additionalInvoiceItem.getPrettyPlanName(), invoicePlugin), mutableField("prettyPhaseName", existingItem != null ? existingItem.getPrettyPhaseName() : null, additionalInvoiceItem.getPrettyPhaseName(), invoicePlugin), mutableField("prettyUsageName", existingItem != null ? existingItem.getPrettyUsageName() : null, additionalInvoiceItem.getPrettyUsageName(), invoicePlugin), immutableField("startDate", existingItem, existingItem != null ? existingItem.getStartDate() : null, additionalInvoiceItem.getStartDate(), invoicePlugin), immutableField("endDate", existingItem, existingItem != null ? existingItem.getEndDate() : null, additionalInvoiceItem.getEndDate(), invoicePlugin), mutableField("amount", existingItem != null ? existingItem.getAmount() : null, additionalInvoiceItem.getAmount(), invoicePlugin), immutableField("rate", existingItem, existingItem != null ? existingItem.getRate() : null, additionalInvoiceItem.getRate(), invoicePlugin), immutableField("currency", existingItem, existingItem != null ? existingItem.getCurrency() : null, additionalInvoiceItem.getCurrency(), invoicePlugin), immutableField("linkedItemId", existingItem, existingItem != null ? existingItem.getLinkedItemId() : null, additionalInvoiceItem.getLinkedItemId(), invoicePlugin), immutableField("quantity", existingItem, existingItem != null ? existingItem.getQuantity() : null, additionalInvoiceItem.getQuantity(), invoicePlugin), mutableField("itemDetails", existingItem != null ? existingItem.getItemDetails() : null, additionalInvoiceItem.getItemDetails(), invoicePlugin), immutableField("invoiceItemType", existingItem, existingItem != null ? existingItem.getInvoiceItemType() : null, additionalInvoiceItem.getInvoiceItemType(), invoicePlugin));
    switch(tmp.getInvoiceItemType()) {
        case RECURRING:
            return new RecurringInvoiceItem(tmp);
        case USAGE:
            return new UsageInvoiceItem(tmp);
        case FIXED:
            return new FixedPriceInvoiceItem(tmp);
        case TAX:
            return new TaxInvoiceItem(tmp);
        case EXTERNAL_CHARGE:
            return new ExternalChargeInvoiceItem(tmp);
        default:
            // As long as there is no explicit cast to the expected type this works
            return tmp;
    }
}
Also used : TaxInvoiceItem(org.killbill.billing.invoice.model.TaxInvoiceItem) InvoiceApiException(org.killbill.billing.invoice.api.InvoiceApiException) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) UsageInvoiceItem(org.killbill.billing.invoice.model.UsageInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) TaxInvoiceItem(org.killbill.billing.invoice.model.TaxInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) ExternalChargeInvoiceItem(org.killbill.billing.invoice.model.ExternalChargeInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) UsageInvoiceItem(org.killbill.billing.invoice.model.UsageInvoiceItem) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) UUID(java.util.UUID) InvoiceItemCatalogBase(org.killbill.billing.invoice.model.InvoiceItemCatalogBase) ExternalChargeInvoiceItem(org.killbill.billing.invoice.model.ExternalChargeInvoiceItem)

Example 25 with FixedPriceInvoiceItem

use of org.killbill.billing.invoice.model.FixedPriceInvoiceItem in project killbill by killbill.

the class FixedAndRecurringInvoiceItemGenerator method generateFixedPriceItem.

private InvoiceItem generateFixedPriceItem(final UUID invoiceId, final UUID accountId, final BillingEvent thisEvent, final LocalDate targetDate, final Currency currency, final InvoiceItemGeneratorLogger invoiceItemGeneratorLogger, final InternalCallContext internalCallContext) throws InvoiceApiException {
    final LocalDate roundedStartDate = internalCallContext.toLocalDate(thisEvent.getEffectiveDate());
    if (roundedStartDate.isAfter(targetDate)) {
        return null;
    } else {
        final BigDecimal fixedPrice = thisEvent.getFixedPrice();
        if (fixedPrice != null) {
            final Plan currentPlan = thisEvent.getPlan();
            Preconditions.checkNotNull(currentPlan, String.format("Unexpected null Plan name event = %s", thisEvent));
            final DateTime catalogEffectiveDate = thisEvent.getCatalogEffectiveDate() != null ? thisEvent.getCatalogEffectiveDate() : null;
            final FixedPriceInvoiceItem fixedPriceInvoiceItem = new FixedPriceInvoiceItem(invoiceId, accountId, thisEvent.getBundleId(), thisEvent.getSubscriptionId(), currentPlan.getProduct().getName(), currentPlan.getName(), thisEvent.getPlanPhase().getName(), catalogEffectiveDate, roundedStartDate, fixedPrice, currency);
            // For debugging purposes
            invoiceItemGeneratorLogger.append(thisEvent, fixedPriceInvoiceItem);
            return fixedPriceInvoiceItem;
        } else {
            return null;
        }
    }
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) Plan(org.killbill.billing.catalog.api.Plan) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) DateTime(org.joda.time.DateTime)

Aggregations

FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)37 Test (org.testng.annotations.Test)33 LocalDate (org.joda.time.LocalDate)32 BigDecimal (java.math.BigDecimal)29 Invoice (org.killbill.billing.invoice.api.Invoice)21 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)21 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)18 UUID (java.util.UUID)17 RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)16 RepairAdjInvoiceItem (org.killbill.billing.invoice.model.RepairAdjInvoiceItem)14 ItemAdjInvoiceItem (org.killbill.billing.invoice.model.ItemAdjInvoiceItem)10 DateTime (org.joda.time.DateTime)9 CreditBalanceAdjInvoiceItem (org.killbill.billing.invoice.model.CreditBalanceAdjInvoiceItem)9 Plan (org.killbill.billing.catalog.api.Plan)7 CreditAdjInvoiceItem (org.killbill.billing.invoice.model.CreditAdjInvoiceItem)7 ExternalChargeInvoiceItem (org.killbill.billing.invoice.model.ExternalChargeInvoiceItem)7 DefaultPrice (org.killbill.billing.catalog.DefaultPrice)6 MockInternationalPrice (org.killbill.billing.catalog.MockInternationalPrice)6 MockPlan (org.killbill.billing.catalog.MockPlan)6 MockPlanPhase (org.killbill.billing.catalog.MockPlanPhase)6