Search in sources :

Example 26 with Subscription

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

the class TestEntitlement method testOverwriteEntitlementBCDOnCreate.

@Test(groups = "slow", description = "Verify we can move the BCD associated with the subscription")
public void testOverwriteEntitlementBCDOnCreate() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithDefaultPaymentMethod();
    callbackServlet.pushExpectedEvents(ExtBusEventType.ACCOUNT_CHANGE, ExtBusEventType.ENTITLEMENT_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_BCD_CHANGE, ExtBusEventType.INVOICE_CREATION);
    final Subscription input = new Subscription();
    input.setAccountId(accountJson.getAccountId());
    input.setPlanName("shotgun-monthly");
    input.setBillCycleDayLocal(28);
    final Subscription subscription = subscriptionApi.createSubscription(input, null, null, true, false, null, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertEquals(subscription.getBillCycleDayLocal().intValue(), 28);
    callbackServlet.assertListenerStatus();
    final AccountTimeline timeline = accountApi.getAccountTimeline(accountJson.getAccountId(), false, AuditLevel.FULL, requestOptions);
    Assert.assertEquals(timeline.getBundles().size(), 1);
    Assert.assertEquals(timeline.getBundles().get(0).getSubscriptions().size(), 1);
    final Subscription subscriptionT = timeline.getBundles().get(0).getSubscriptions().get(0);
    Assert.assertEquals(subscriptionT.getBillCycleDayLocal().intValue(), 28);
    // Note that we are START_ENTITLEMENT, START_BILLING, PHASE
    // TODO : we should add the BCD_CHANGE event in the timeline (does not exist in SubscriptionEventType)
    Assert.assertEquals(subscriptionT.getEvents().size(), 3);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) AccountTimeline(org.killbill.billing.client.model.gen.AccountTimeline) Subscription(org.killbill.billing.client.model.gen.Subscription) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 27 with Subscription

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

the class TestEntitlement method testSubscriptionEventsWithCatalogChange.

@Test(groups = "slow", description = "See https://github.com/killbill/killbill/issues/1397")
public void testSubscriptionEventsWithCatalogChange() throws Exception {
    // effDt = 2013-02-08T00:00:00+00:00
    callbackServlet.pushExpectedEvents(ExtBusEventType.TENANT_CONFIG_CHANGE);
    String catalog1 = uploadTenantCatalog("org/killbill/billing/server/SpyCarBasic.xml", true);
    callbackServlet.assertListenerStatus();
    Assert.assertNotNull(catalog1);
    // effDt = 2014-02-08T00:00:00+00:00
    callbackServlet.pushExpectedEvents(ExtBusEventType.TENANT_CONFIG_CHANGE);
    String catalog2 = uploadTenantCatalog("org/killbill/billing/server/SpyCarBasic.v2.xml", true);
    callbackServlet.assertListenerStatus();
    Assert.assertNotNull(catalog2);
    final DateTime initialDate = new DateTime(2014, 1, 2, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithDefaultPaymentMethod();
    final Subscription input = new Subscription();
    input.setAccountId(accountJson.getAccountId());
    input.setPlanName("super-monthly");
    callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.ENTITLEMENT_CREATION, // The BCD is updated in that case
    ExtBusEventType.ACCOUNT_CHANGE, // $0 Fixed price
    ExtBusEventType.INVOICE_CREATION);
    final Subscription entitlementJson = subscriptionApi.createSubscription(input, null, null, false, false, false, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertEquals(entitlementJson.getPlanName(), "super-monthly");
    callbackServlet.assertListenerStatus();
    // MOVE AFTER TRIAL
    callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_SUCCESS, ExtBusEventType.PAYMENT_SUCCESS);
    // 2014-02-01
    clock.addDays(30);
    callbackServlet.assertListenerStatus();
    // Go to catalog V2
    // 2014-02-09
    clock.addDays(8);
    callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_CHANGE, ExtBusEventType.SUBSCRIPTION_CHANGE);
    subscriptionApi.changeSubscriptionPlan(entitlementJson.getSubscriptionId(), input, null, BillingActionPolicy.IMMEDIATE, NULL_PLUGIN_PROPERTIES, requestOptions);
    Subscription refreshedSubscription1 = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
    callbackServlet.assertListenerStatus();
    Assert.assertNotNull(refreshedSubscription1);
    final Subscription subscription = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
    Assert.assertEquals(subscription.getPrices().size(), 3);
    Assert.assertEquals(subscription.getPrices().get(0).getPhaseName(), "super-monthly-trial");
    Assert.assertEquals(subscription.getPrices().get(0).getFixedPrice(), BigDecimal.ZERO);
    Assert.assertNull(subscription.getPrices().get(0).getRecurringPrice());
    Assert.assertEquals(subscription.getPrices().get(1).getPhaseName(), "super-monthly-evergreen");
    Assert.assertNull(subscription.getPrices().get(1).getFixedPrice());
    Assert.assertEquals(subscription.getPrices().get(1).getRecurringPrice(), new BigDecimal("1000.00"));
    // Should reflect the catalog change price
    Assert.assertEquals(subscription.getPrices().get(2).getPhaseName(), "super-monthly-evergreen");
    Assert.assertNull(subscription.getPrices().get(2).getFixedPrice());
    Assert.assertEquals(subscription.getPrices().get(2).getRecurringPrice(), new BigDecimal("1200.00"));
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Subscription(org.killbill.billing.client.model.gen.Subscription) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 28 with Subscription

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

the class TestEntitlement method testEntitlementWithAddOnsWithWRITTEN_OFF.

@Test(groups = "slow", description = "Create a base entitlement and also addOns entitlements under the same bundle")
public void testEntitlementWithAddOnsWithWRITTEN_OFF() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final String bundleExternalKey = "bundleKey12346542";
    final Account accountJson = createAccount();
    final Subscription base = new Subscription();
    base.setAccountId(accountJson.getAccountId());
    base.setBundleExternalKey(bundleExternalKey);
    base.setExternalKey("Base");
    base.setProductName("Shotgun");
    base.setProductCategory(ProductCategory.BASE);
    base.setBillingPeriod(BillingPeriod.MONTHLY);
    base.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final Subscription addOn1 = new Subscription();
    addOn1.setAccountId(accountJson.getAccountId());
    addOn1.setExternalKey("addOn1");
    addOn1.setProductName("Telescopic-Scope");
    addOn1.setProductCategory(ProductCategory.ADD_ON);
    addOn1.setBillingPeriod(BillingPeriod.MONTHLY);
    addOn1.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final Subscription addOn2 = new Subscription();
    addOn2.setAccountId(accountJson.getAccountId());
    addOn2.setExternalKey("addOn2");
    addOn2.setProductName("Laser-Scope");
    addOn2.setProductCategory(ProductCategory.ADD_ON);
    addOn2.setBillingPeriod(BillingPeriod.MONTHLY);
    addOn2.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final Subscriptions subscriptions = new Subscriptions();
    subscriptions.add(base);
    subscriptions.add(addOn1);
    subscriptions.add(addOn2);
    final Bundle bundle = subscriptionApi.createSubscriptionWithAddOns(subscriptions, null, null, null, null, null, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertNotNull(bundle);
    assertEquals(bundle.getExternalKey(), bundleExternalKey);
    assertEquals(bundle.getSubscriptions().size(), 3);
    int found = 0;
    for (int i = 0; i < 3; i++) {
        final Subscription cur = bundle.getSubscriptions().get(i);
        assertEquals(cur.getBundleExternalKey(), bundleExternalKey);
        if ("Shotgun".equals(cur.getProductName())) {
            assertEquals(cur.getExternalKey(), "Base");
            found++;
        } else if ("Telescopic-Scope".equals(cur.getProductName())) {
            assertEquals(cur.getExternalKey(), "addOn1");
            found++;
        } else if ("Laser-Scope".equals(cur.getProductName())) {
            assertEquals(cur.getExternalKey(), "addOn2");
            found++;
        }
    }
    assertEquals(found, 3);
    final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
    assertEquals(invoices.size(), 1);
    assertEquals(invoices.get(0).getBalance().compareTo(BigDecimal.ZERO), 1);
    assertEquals(invoiceApi.getInvoiceTags(invoices.get(0).getInvoiceId(), requestOptions).size(), 0);
    final Bundles accountBundles = accountApi.getAccountBundles(accountJson.getAccountId(), null, null, requestOptions);
    assertEquals(accountBundles.size(), 1);
    for (final Subscription subscription : accountBundles.get(0).getSubscriptions()) {
        assertEquals(subscription.getState(), EntitlementState.ACTIVE);
    }
    accountApi.closeAccount(accountJson.getAccountId(), true, true, false, true, requestOptions);
    final Bundles accountBundlesAfterClose = accountApi.getAccountBundles(accountJson.getAccountId(), null, null, requestOptions);
    assertEquals(accountBundlesAfterClose.size(), 1);
    for (final Subscription subscription : accountBundlesAfterClose.get(0).getSubscriptions()) {
        assertEquals(subscription.getState(), EntitlementState.CANCELLED);
    }
    final List<Invoice> invoicesAfterClose = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
    assertEquals(invoicesAfterClose.size(), 1);
    assertEquals(invoicesAfterClose.get(0).getBalance().compareTo(BigDecimal.ZERO), 0);
    assertEquals(invoiceApi.getInvoiceTags(invoicesAfterClose.get(0).getInvoiceId(), requestOptions).size(), 1);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Invoice(org.killbill.billing.client.model.gen.Invoice) Subscriptions(org.killbill.billing.client.model.Subscriptions) BulkSubscriptionsBundle(org.killbill.billing.client.model.gen.BulkSubscriptionsBundle) Bundle(org.killbill.billing.client.model.gen.Bundle) Subscription(org.killbill.billing.client.model.gen.Subscription) DateTime(org.joda.time.DateTime) BulkSubscriptionsBundles(org.killbill.billing.client.model.BulkSubscriptionsBundles) Bundles(org.killbill.billing.client.model.Bundles) Test(org.testng.annotations.Test)

Example 29 with Subscription

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

the class TestEntitlement method testEntitlementUncancel.

@Test(groups = "slow", description = "Can cancel and uncancel a subscription")
public void testEntitlementUncancel() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithDefaultPaymentMethod();
    final String productName = "Shotgun";
    final BillingPeriod term = BillingPeriod.MONTHLY;
    final Subscription entitlementJson = createSubscription(accountJson.getAccountId(), "99999", productName, ProductCategory.BASE, term);
    // Retrieves with GET
    Subscription objFromJson = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
    Assert.assertEquals(objFromJson.getPrices().size(), 2);
    Assert.assertEquals(objFromJson.getPrices().get(0).getPhaseName(), "shotgun-monthly-trial");
    Assert.assertEquals(objFromJson.getPrices().get(0).getFixedPrice(), BigDecimal.ZERO);
    Assert.assertNull(objFromJson.getPrices().get(0).getRecurringPrice());
    Assert.assertEquals(objFromJson.getPrices().get(1).getPhaseName(), "shotgun-monthly-evergreen");
    Assert.assertNull(objFromJson.getPrices().get(1).getFixedPrice());
    Assert.assertEquals(objFromJson.getPrices().get(1).getRecurringPrice(), new BigDecimal("249.95"));
    // Equality in java client is not correctly implemented so manually check PriceOverrides section and then reset before equality
    objFromJson.setPriceOverrides(null);
    entitlementJson.setPriceOverrides(null);
    Assert.assertTrue(objFromJson.equals(entitlementJson));
    // MOVE AFTER TRIAL
    callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_SUCCESS, ExtBusEventType.PAYMENT_SUCCESS);
    clock.addDays(31);
    callbackServlet.assertListenerStatus();
    // Cancel EOT
    subscriptionApi.cancelSubscriptionPlan(entitlementJson.getSubscriptionId(), null, EntitlementActionPolicy.END_OF_TERM, BillingActionPolicy.END_OF_TERM, NULL_PLUGIN_PROPERTIES, requestOptions);
    // Retrieves to check EndDate
    objFromJson = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
    assertNotNull(objFromJson.getCancelledDate());
    Assert.assertEquals(objFromJson.getPrices().size(), 2);
    Assert.assertEquals(objFromJson.getPrices().get(0).getPhaseName(), "shotgun-monthly-trial");
    Assert.assertEquals(objFromJson.getPrices().get(0).getFixedPrice(), BigDecimal.ZERO);
    Assert.assertNull(objFromJson.getPrices().get(0).getRecurringPrice());
    Assert.assertEquals(objFromJson.getPrices().get(1).getPhaseName(), "shotgun-monthly-evergreen");
    Assert.assertNull(objFromJson.getPrices().get(1).getFixedPrice());
    Assert.assertEquals(objFromJson.getPrices().get(1).getRecurringPrice(), new BigDecimal("249.95"));
    // Uncancel
    subscriptionApi.uncancelSubscriptionPlan(entitlementJson.getSubscriptionId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    objFromJson = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
    assertNull(objFromJson.getCancelledDate());
    Assert.assertEquals(objFromJson.getPrices().size(), 2);
    Assert.assertEquals(objFromJson.getPrices().get(0).getPhaseName(), "shotgun-monthly-trial");
    Assert.assertEquals(objFromJson.getPrices().get(0).getFixedPrice(), BigDecimal.ZERO);
    Assert.assertNull(objFromJson.getPrices().get(0).getRecurringPrice());
    Assert.assertEquals(objFromJson.getPrices().get(1).getPhaseName(), "shotgun-monthly-evergreen");
    Assert.assertNull(objFromJson.getPrices().get(1).getFixedPrice());
    Assert.assertEquals(objFromJson.getPrices().get(1).getRecurringPrice(), new BigDecimal("249.95"));
}
Also used : Account(org.killbill.billing.client.model.gen.Account) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) Subscription(org.killbill.billing.client.model.gen.Subscription) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 30 with Subscription

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

the class TestEntitlement method testEntitlementUsingPlanName.

@Test(groups = "slow", description = "Can create subscription and change plan using planName")
public void testEntitlementUsingPlanName() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithDefaultPaymentMethod();
    final Subscription input = new Subscription();
    input.setAccountId(accountJson.getAccountId());
    input.setBundleExternalKey("somethingSpecial");
    input.setPlanName("shotgun-monthly");
    final Subscription entitlementJson = subscriptionApi.createSubscription(input, null, null, false, false, false, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertEquals(entitlementJson.getProductName(), "Shotgun");
    Assert.assertEquals(entitlementJson.getBillingPeriod(), BillingPeriod.MONTHLY);
    Assert.assertEquals(entitlementJson.getPriceList(), DefaultPriceListSet.DEFAULT_PRICELIST_NAME);
    Assert.assertEquals(entitlementJson.getPlanName(), "shotgun-monthly");
    final Subscription newInput = new Subscription();
    newInput.setAccountId(entitlementJson.getAccountId());
    newInput.setSubscriptionId(entitlementJson.getSubscriptionId());
    newInput.setPlanName("pistol-monthly");
    subscriptionApi.changeSubscriptionPlan(entitlementJson.getSubscriptionId(), newInput, null, null, NULL_PLUGIN_PROPERTIES, requestOptions);
    final Subscription newEntitlementJson = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
    Assert.assertEquals(newEntitlementJson.getProductName(), "Pistol");
    Assert.assertEquals(newEntitlementJson.getBillingPeriod(), BillingPeriod.MONTHLY);
    Assert.assertEquals(newEntitlementJson.getPriceList(), DefaultPriceListSet.DEFAULT_PRICELIST_NAME);
    Assert.assertEquals(newEntitlementJson.getPlanName(), "pistol-monthly");
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Subscription(org.killbill.billing.client.model.gen.Subscription) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

Subscription (org.killbill.billing.client.model.gen.Subscription)35 Account (org.killbill.billing.client.model.gen.Account)34 Test (org.testng.annotations.Test)29 DateTime (org.joda.time.DateTime)21 BigDecimal (java.math.BigDecimal)8 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)8 Bundles (org.killbill.billing.client.model.Bundles)7 UUID (java.util.UUID)6 Bundle (org.killbill.billing.client.model.gen.Bundle)6 Invoice (org.killbill.billing.client.model.gen.Invoice)6 LocalDate (org.joda.time.LocalDate)5 BulkSubscriptionsBundles (org.killbill.billing.client.model.BulkSubscriptionsBundles)5 Tags (org.killbill.billing.client.model.Tags)5 ArrayList (java.util.ArrayList)4 BulkSubscriptionsBundle (org.killbill.billing.client.model.gen.BulkSubscriptionsBundle)4 KillBillClientException (org.killbill.billing.client.KillBillClientException)3 Subscriptions (org.killbill.billing.client.model.Subscriptions)3 Predicate (com.google.common.base.Predicate)2 Invoices (org.killbill.billing.client.model.Invoices)2 SubscriptionUsageRecord (org.killbill.billing.client.model.gen.SubscriptionUsageRecord)2