killbill-uncached

Details

diff --git a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestCatalogRetireElements.java b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestCatalogRetireElements.java
index 47eceb3..80fb354 100644
--- a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestCatalogRetireElements.java
+++ b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestCatalogRetireElements.java
@@ -57,7 +57,49 @@ public class TestCatalogRetireElements extends TestIntegrationBase {
         return super.getConfigSource(null, allExtraProperties);
     }
 
-    @Test(groups = "slow")
+    @Test(groups = "slow", description = "See https://github.com/killbill/killbill/issues/1110")
+    public void testChangePlanTwiceWithNewPlan() throws Exception {
+        // Catalog v1 starts in 2011-01-01
+        // Catalog v2 starts in 2015-12-01
+        // -> Start on catalog V1
+        final LocalDate today = new LocalDate(2015, 11, 5);
+
+        // Set clock to the initial start date - we implicitly assume here that the account timezone is UTC
+        clock.setDay(today);
+
+        final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(null));
+
+        final String productName = "Shotgun";
+        final BillingPeriod term = BillingPeriod.MONTHLY;
+        final PlanPhaseSpecifier spec1 = new PlanPhaseSpecifier(productName, term, "DEFAULT", null);
+
+        busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
+        final UUID bpEntitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec1), "externalKey", null, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
+        assertListenerStatus();
+        Entitlement bpEntitlement = entitlementApi.getEntitlementForId(bpEntitlementId, callContext);
+
+        // Move out a month. Date > caralog V2
+        busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
+        clock.addMonths(1);
+        assertListenerStatus();
+
+        // Current date is > catalog V2
+        // Change to a plan that exists in V2 but not in V1
+        final PlanPhaseSpecifier spec2 = new PlanPhaseSpecifier("bazooka-monthly", null);
+        busHandler.pushExpectedEvents(NextEvent.CHANGE, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
+        bpEntitlement = bpEntitlement.changePlanWithDate(new DefaultEntitlementSpecifier(spec2), clock.getUTCToday(), ImmutableList.<PluginProperty>of(), callContext);
+        assertListenerStatus();
+
+
+        // Change back to original plan -- because we use the latest catalog version the change plan succeeds
+        busHandler.pushExpectedEvents(NextEvent.CHANGE, NextEvent.INVOICE);
+        bpEntitlement.changePlanWithDate(new DefaultEntitlementSpecifier(spec1), clock.getUTCToday(), ImmutableList.<PluginProperty>of(), callContext);
+        assertListenerStatus();
+
+    }
+
+
+        @Test(groups = "slow")
     public void testRetirePlan() throws Exception {
         // Catalog v1 starts in 2011-01-01
         // Catalog v2 starts in 2015-12-01
diff --git a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/usage/TestInArrearWithCatalogVersions.java b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/usage/TestInArrearWithCatalogVersions.java
index 6f2971d..bac0ef8 100644
--- a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/usage/TestInArrearWithCatalogVersions.java
+++ b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/usage/TestInArrearWithCatalogVersions.java
@@ -141,7 +141,7 @@ public class TestInArrearWithCatalogVersions extends TestIntegrationBase {
 
         final PlanPhaseSpecifier spec2 = new PlanPhaseSpecifier("electricity-monthly-special");
 
-        bp.changePlanWithDate(new DefaultEntitlementSpecifier(spec2), new LocalDate("2016-05-09"), null, callContext);
+        bp.changePlanWithDate(new DefaultEntitlementSpecifier(spec2), new LocalDate("2016-05-07"), null, callContext);
         assertListenerStatus();
 
         busHandler.pushExpectedEvents(NextEvent.CHANGE, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
@@ -149,7 +149,7 @@ public class TestInArrearWithCatalogVersions extends TestIntegrationBase {
         assertListenerStatus();
 
         curInvoice = invoiceChecker.checkInvoice(account.getId(), 2, callContext,
-                                    new ExpectedInvoiceItemCheck(new LocalDate(2016, 5, 1), new LocalDate(2016, 5, 9), InvoiceItemType.USAGE, new BigDecimal("150.00")));
+                                    new ExpectedInvoiceItemCheck(new LocalDate(2016, 5, 1), new LocalDate(2016, 5, 7), InvoiceItemType.USAGE, new BigDecimal("150.00")));
         invoiceChecker.checkTrackingIds(curInvoice, ImmutableSet.of("t3"), internalCallContext);
 
 
@@ -160,7 +160,7 @@ public class TestInArrearWithCatalogVersions extends TestIntegrationBase {
         assertListenerStatus();
 
         curInvoice = invoiceChecker.checkInvoice(account.getId(), 3, callContext,
-                                    new ExpectedInvoiceItemCheck(new LocalDate(2016, 5, 9), new LocalDate(2016, 6, 1), InvoiceItemType.USAGE, new BigDecimal("100.00")));
+                                    new ExpectedInvoiceItemCheck(new LocalDate(2016, 5, 7), new LocalDate(2016, 6, 1), InvoiceItemType.USAGE, new BigDecimal("100.00")));
         invoiceChecker.checkTrackingIds(curInvoice, ImmutableSet.of("t4"), internalCallContext);
 
     }
diff --git a/catalog/src/main/java/org/killbill/billing/catalog/DefaultVersionedCatalog.java b/catalog/src/main/java/org/killbill/billing/catalog/DefaultVersionedCatalog.java
index 5edf0dc..4eb9ff3 100644
--- a/catalog/src/main/java/org/killbill/billing/catalog/DefaultVersionedCatalog.java
+++ b/catalog/src/main/java/org/killbill/billing/catalog/DefaultVersionedCatalog.java
@@ -319,7 +319,7 @@ public class DefaultVersionedCatalog extends ValidatingConfig<DefaultVersionedCa
                                        final DateTime subscriptionStartDate)
             throws CatalogApiException {
         // Use the "to" specifier, to make sure the new plan always exists
-        final StaticCatalog staticCatalog = getStaticCatalog(to, requestedDate, subscriptionStartDate);
+        final StaticCatalog staticCatalog = versionForDate(requestedDate);
         return staticCatalog.planChange(from, to);
     }
 
diff --git a/catalog/src/test/java/org/killbill/billing/catalog/TestVersionedCatalog.java b/catalog/src/test/java/org/killbill/billing/catalog/TestVersionedCatalog.java
index 964fa3a..4a24cf6 100644
--- a/catalog/src/test/java/org/killbill/billing/catalog/TestVersionedCatalog.java
+++ b/catalog/src/test/java/org/killbill/billing/catalog/TestVersionedCatalog.java
@@ -41,15 +41,18 @@ import io.netty.buffer.ByteBuf;
 
 public class TestVersionedCatalog extends CatalogTestSuiteNoDB {
 
-    final DateTime dt0 = new DateTime("2010-01-01T00:00:00+00:00");
     // WeaponsHireSmall-1.xml
-    final DateTime dt1 = new DateTime("2011-01-01T00:01:00+00:00");
+    final DateTime dt1 = new DateTime("2010-01-01T00:00:00+00:00");
+
     // WeaponsHireSmall-2.xml
     final DateTime dt2 = new DateTime("2011-02-02T00:01:00+00:00");
+
     // WeaponsHireSmall-2a.xml
     final DateTime dt2a = new DateTime("2011-02-03T00:01:00+00:00");
+
     // effectiveDateForExistingSubscriptions from the catalogs 2 and 2a
-    final DateTime dt214 = new DateTime("2011-02-14T00:01:00+00:00");
+    final DateTime dEffectiveDateForExistingSubscriptions = new DateTime("2011-02-14T00:01:00+00:00");
+
     // WeaponsHireSmall-3.xml
     final DateTime dt3 = new DateTime("2011-03-03T00:01:00+00:00");
 
@@ -65,92 +68,104 @@ public class TestVersionedCatalog extends CatalogTestSuiteNoDB {
         vc = loader.loadDefaultCatalog("versionedCatalog");
     }
 
-    @Test(groups = "fast")
-    public void testFindPlanWithDates() throws Exception {
-        // We find it although the date provided is too early because we default to first catalog version (see also testErrorOnDateTooEarly below)
-        final Plan newSubPlan0 = vc.findPlan("pistol-monthly", dt0, dt0);
 
-        final Plan newSubPlan1 = vc.findPlan("pistol-monthly", dt1, dt1);
-        final Plan newSubPlan2 = vc.findPlan("pistol-monthly", dt2, dt2);
-        final Plan newSubPlan214 = vc.findPlan("pistol-monthly", dt214, dt214);
-        final Plan newSubPlan3 = vc.findPlan("pistol-monthly", dt3, dt3);
 
-        Assert.assertEquals(newSubPlan1.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("29.95"));
-        Assert.assertEquals(newSubPlan2.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95"));
-        Assert.assertEquals(newSubPlan214.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95"));
-        Assert.assertEquals(newSubPlan3.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("49.95"));
+    //
+    // We use shotgun-quarterly only available from dt2 (v2) and with a price change in V2a
+    //
+    @Test(groups = "fast", description = "See https://github.com/killbill/killbill/issues/1110")
+    public void testFindPlanAcrossVersions() throws Exception {
 
         // Existing subscription
+        final DateTime subscriptionStartDate = new DateTime("2011-02-02T00:01:00+00:00"); // dt2 (v2) < subscriptionStartDate < dt2a (v2a)
+
+
+        Plan plan = vc.findPlan("shotgun-quarterly", dt2, subscriptionStartDate);
+        Assert.assertEquals(plan.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("249.95"));
 
-        final Plan exSubPlan2 = vc.findPlan("pistol-monthly", dt2, dt1);
-        final Plan exSubPlan214 = vc.findPlan("pistol-monthly", dt214, dt1);
-        final Plan exSubPlan3 = vc.findPlan("pistol-monthly", dt3, dt1);
-        // Plan added in subsequent catalog (at dt2)
-        final Plan exSubPlan4 = vc.findPlan("shotgun-quarterly", dt2, dt1);
-        final Plan exSubPlan5 = vc.findPlan("shotgun-quarterly", dt2a, dt1);
-        final Plan exSubPlan6 = vc.findPlan("shotgun-quarterly", dt214, dt1);
-        final Plan exSubPlan7 = vc.findPlan("shotgun-quarterly", dt214, dt214);
-
-        Assert.assertEquals(exSubPlan2.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("29.95"));
-        Assert.assertEquals(exSubPlan214.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95"));
-        Assert.assertEquals(exSubPlan3.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95"));
-        Assert.assertEquals(exSubPlan4.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("249.95"));
-        // Old price
-        Assert.assertEquals(exSubPlan5.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("249.95"));
-        // New price
-        Assert.assertEquals(exSubPlan6.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("259.95"));
-        Assert.assertEquals(exSubPlan7.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("259.95"));
+        // We still see old price because the requested date is >= dt2a and there is no effectiveDateForExistingSubscriptions
+        plan = vc.findPlan("shotgun-quarterly", dt2a, subscriptionStartDate);
+        Assert.assertEquals(plan.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("249.95"));
     }
 
+
+
+    //
+    // We use pistol-monthly available from dt1 (v1) and with a first price change in V2a, and then in v3
+    // Also  dt2a < effectiveDateForExistingSubscriptions < dt3
+    //
+    @Test(groups = "fast")
+    public void testFindPlanAcrossVersionsUsingEffectiveDateForExistingSubscriptions() throws Exception {
+
+        // Easy cases where subscriptionStartDate = requestedDate -> fetch date from the only valid version
+        Plan plan = vc.findPlan("pistol-monthly", dt1, dt1);
+        Assert.assertEquals(plan.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("29.95"));
+
+        plan = vc.findPlan("pistol-monthly", dt2, dt2);
+        Assert.assertEquals(plan.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95"));
+
+        plan = vc.findPlan("pistol-monthly", dEffectiveDateForExistingSubscriptions, dEffectiveDateForExistingSubscriptions);
+        Assert.assertEquals(plan.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95"));
+
+        plan = vc.findPlan("pistol-monthly", dt3, dt3);
+        Assert.assertEquals(plan.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("49.95"));
+
+        // Case with an existing subscription (prior first price change)
+        final DateTime subscriptionStartDate = new DateTime("2011-01-01T00:01:00+00:00"); // dt1 (v1) < subscriptionStartDate < dt2 (v2)
+
+        // Returns old price because of effectiveDateForExistingSubscriptions > requestedDate = dt2
+        plan = vc.findPlan("pistol-monthly", dt2, subscriptionStartDate);
+        Assert.assertEquals(plan.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("29.95"));
+
+        // Returns nw  price because of effectiveDateForExistingSubscriptions = requestedDate = dt2
+        plan = vc.findPlan("pistol-monthly", dEffectiveDateForExistingSubscriptions, subscriptionStartDate);
+        Assert.assertEquals(plan.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95"));
+
+        plan = vc.findPlan("pistol-monthly", dt3, subscriptionStartDate);
+        Assert.assertEquals(plan.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95"));
+    }
+
+
+
     // Similar to testFindPlanWithDates, but use the API with PlanSpecifier
     @Test(groups = "fast")
     public void testFindPlanWithDatesAndPlanSpecifier() throws Exception {
+
         final PlanSpecifier pistolMonthly = new PlanSpecifier("Pistol", BillingPeriod.MONTHLY, "DEFAULT");
-        final PlanSpecifier shotgunQuarterly = new PlanSpecifier("Shotgun", BillingPeriod.QUARTERLY, "DEFAULT");
 
-        // We find it although the date provided is too early because we default to first catalog version (see also testErrorOnDateTooEarly below)
-        final Plan newSubPlan0 = vc.createOrFindPlan(pistolMonthly, null, dt0, dt0);
+        // Easy cases where subscriptionStartDate = requestedDate -> fetch date from the only valid version
+        Plan plan = vc.createOrFindPlan(pistolMonthly, null, dt1, dt1);
+        Assert.assertEquals(plan.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("29.95"));
 
-        final Plan newSubPlan1 = vc.createOrFindPlan(pistolMonthly, null, dt1, dt1);
-        final Plan newSubPlan2 = vc.createOrFindPlan(pistolMonthly, null, dt2, dt2);
-        final Plan newSubPlan214 = vc.createOrFindPlan(pistolMonthly, null, dt214, dt214);
-        final Plan newSubPlan3 = vc.createOrFindPlan(pistolMonthly, null, dt3, dt3);
+        plan = vc.createOrFindPlan(pistolMonthly, null, dt2, dt2);
+        Assert.assertEquals(plan.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95"));
 
-        Assert.assertEquals(newSubPlan1.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("29.95"));
-        Assert.assertEquals(newSubPlan2.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95"));
-        Assert.assertEquals(newSubPlan214.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95"));
-        Assert.assertEquals(newSubPlan3.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("49.95"));
+        plan = vc.createOrFindPlan(pistolMonthly, null, dEffectiveDateForExistingSubscriptions, dEffectiveDateForExistingSubscriptions);
+        Assert.assertEquals(plan.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95"));
 
-        // Existing subscription
+        plan = vc.createOrFindPlan(pistolMonthly, null, dt3, dt3);
+        Assert.assertEquals(plan.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("49.95"));
+
+        // Cases for existing subscription
+        plan = vc.createOrFindPlan(pistolMonthly, null, dt2, dt1);
+        Assert.assertEquals(plan.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("29.95"));
+
+        plan = vc.createOrFindPlan(pistolMonthly, null, dEffectiveDateForExistingSubscriptions, dt1);
+        Assert.assertEquals(plan.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95"));
+
+        plan = vc.createOrFindPlan(pistolMonthly, null, dt3, dt1);
+        Assert.assertEquals(plan.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95"));
 
-        final Plan exSubPlan2 = vc.createOrFindPlan(pistolMonthly, null, dt2, dt1);
-        final Plan exSubPlan214 = vc.createOrFindPlan(pistolMonthly, null, dt214, dt1);
-        final Plan exSubPlan3 = vc.createOrFindPlan(pistolMonthly, null, dt3, dt1);
-        // Plan added in subsequent catalog (at dt2)
-        final Plan exSubPlan4 = vc.createOrFindPlan(shotgunQuarterly, null, dt2, dt1);
-        final Plan exSubPlan5 = vc.createOrFindPlan(shotgunQuarterly, null, dt2a, dt1);
-        final Plan exSubPlan6 = vc.createOrFindPlan(shotgunQuarterly, null, dt214, dt1);
-        final Plan exSubPlan7 = vc.createOrFindPlan(shotgunQuarterly, null, dt214, dt214);
-
-        Assert.assertEquals(exSubPlan2.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("29.95"));
-        Assert.assertEquals(exSubPlan214.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95"));
-        Assert.assertEquals(exSubPlan3.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95"));
-        Assert.assertEquals(exSubPlan4.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("249.95"));
-        // Old price
-        Assert.assertEquals(exSubPlan5.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("249.95"));
-        // New price
-        Assert.assertEquals(exSubPlan6.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("259.95"));
-        Assert.assertEquals(exSubPlan7.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("259.95"));
     }
 
     @Test(groups = "fast")
     public void testErrorOnDateTooEarly() throws CatalogApiException {
         // We find it although the date provided is too early because we default to first catalog version
-        vc.findPlan("shotgun-monthly", dt0);
+        vc.findPlan("shotgun-monthly", dt1);
 
         try {
             // We **don't find it** because date is too early and not part of first catalog version
-            vc.findPlan("shotgun-quarterly", dt0);
+            vc.findPlan("shotgun-quarterly", dt1);
             Assert.fail("Date is too early an exception should have been thrown");
         } catch (final CatalogApiException e) {
             Assert.assertEquals(e.getCode(), ErrorCode.CAT_NO_SUCH_PLAN.getCode());
diff --git a/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-2a.xml b/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-2a.xml
index c2ecfd6..77ee340 100644
--- a/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-2a.xml
+++ b/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-2a.xml
@@ -192,8 +192,6 @@ Changes compared to WeaponsHireSmall-2.xml:
             </finalPhase>
         </plan>
         <plan name="shotgun-quarterly">
-            <effectiveDateForExistingSubscriptions>2011-02-14T00:00:00+00:00</effectiveDateForExistingSubscriptions>
-
             <product>Shotgun</product>
             <initialPhases>
                 <phase type="TRIAL">
diff --git a/subscription/src/main/java/org/killbill/billing/subscription/api/svcs/DefaultSubscriptionInternalApi.java b/subscription/src/main/java/org/killbill/billing/subscription/api/svcs/DefaultSubscriptionInternalApi.java
index 2680ba5..0e830df 100644
--- a/subscription/src/main/java/org/killbill/billing/subscription/api/svcs/DefaultSubscriptionInternalApi.java
+++ b/subscription/src/main/java/org/killbill/billing/subscription/api/svcs/DefaultSubscriptionInternalApi.java
@@ -368,7 +368,7 @@ public class DefaultSubscriptionInternalApi extends DefaultSubscriptionBaseCreat
         final DateTime effectiveDate = (requestedDateWithMs != null) ? DefaultClock.truncateMs(requestedDateWithMs) : null;
         final DateTime effectiveCatalogDate = effectiveDate != null ? effectiveDate : context.getCreatedDate();
         final PlanPhasePriceOverridesWithCallContext overridesWithContext = new DefaultPlanPhasePriceOverridesWithCallContext(spec.getOverrides(), callContext);
-        final Plan plan = catalog.createOrFindPlan(spec.getPlanPhaseSpecifier(), overridesWithContext, effectiveCatalogDate, subscription.getStartDate());
+        final Plan plan = catalog.createOrFindPlan(spec.getPlanPhaseSpecifier(), overridesWithContext, effectiveCatalogDate);
         if (ProductCategory.ADD_ON.toString().equalsIgnoreCase(plan.getProduct().getCategory().toString())) {
             if (plan.getPlansAllowedInBundle() != -1
                 && plan.getPlansAllowedInBundle() > 0
diff --git a/subscription/src/main/java/org/killbill/billing/subscription/api/user/DefaultSubscriptionBaseApiService.java b/subscription/src/main/java/org/killbill/billing/subscription/api/user/DefaultSubscriptionBaseApiService.java
index ff95732..4ca12f8 100644
--- a/subscription/src/main/java/org/killbill/billing/subscription/api/user/DefaultSubscriptionBaseApiService.java
+++ b/subscription/src/main/java/org/killbill/billing/subscription/api/user/DefaultSubscriptionBaseApiService.java
@@ -422,7 +422,7 @@ public class DefaultSubscriptionBaseApiService implements SubscriptionBaseApiSer
 
         final Catalog fullCatalog = catalogInternalApi.getFullCatalog(true, true, internalCallContext);
         final PlanPhaseSpecifier planPhaseSpecifier = spec.getPlanPhaseSpecifier();
-        final Plan newPlan = fullCatalog.createOrFindPlan(planPhaseSpecifier, overridesWithContext, effectiveDate, subscription.getStartDate());
+        final Plan newPlan = fullCatalog.createOrFindPlan(planPhaseSpecifier, overridesWithContext, effectiveDate);
 
         final PhaseType initialPhaseType = planPhaseSpecifier.getPhaseType();
         if (ProductCategory.ADD_ON.toString().equalsIgnoreCase(newPlan.getProduct().getCategory().toString())) {