Search in sources :

Example 16 with Subscription

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

the class TestEntitlement method testCreateSubscriptionEntitlementInTheFuture.

@Test(groups = "slow", description = "Can create an entitlement with a future entitlement date")
public void testCreateSubscriptionEntitlementInTheFuture() 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.setProductName("Shotgun");
    input.setProductCategory(ProductCategory.BASE);
    input.setBillingPeriod(BillingPeriod.MONTHLY);
    input.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    // Verify callCompletion works (related to https://github.com/killbill/killbill/issues/1193)
    final Subscription entitlementJson = subscriptionApi.createSubscription(input, initialDate.toLocalDate().plusMonths(1), null, false, false, false, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertEquals(entitlementJson.getState(), EntitlementState.PENDING);
    Assert.assertEquals(entitlementJson.getChargedThroughDate(), initialDate.toLocalDate());
    Assert.assertEquals(entitlementJson.getBillingStartDate(), initialDate.toLocalDate());
    Assert.assertEquals(entitlementJson.getStartDate(), initialDate.toLocalDate().plusMonths(1));
    Assert.assertEquals(entitlementJson.getProductName(), input.getProductName());
    Assert.assertEquals(entitlementJson.getProductCategory(), input.getProductCategory());
    Assert.assertEquals(entitlementJson.getBillingPeriod(), input.getBillingPeriod());
    Assert.assertEquals(entitlementJson.getPriceList(), input.getPriceList());
    // Retrieves with GET
    final Subscription subscription = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
    Assert.assertEquals(subscription, entitlementJson);
    Assert.assertEquals(subscription.getPrices().size(), 2);
    Assert.assertEquals(subscription.getPrices().get(0).getPhaseName(), "shotgun-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(), "shotgun-monthly-evergreen");
    Assert.assertNull(subscription.getPrices().get(1).getFixedPrice());
    Assert.assertEquals(subscription.getPrices().get(1).getRecurringPrice(), new BigDecimal("249.95"));
}
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 17 with Subscription

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

the class TestEntitlement method testCreateChangeAndCancelSubscriptionWithAutoInvoicingOff.

@Test(groups = "slow", description = "Can create an entitlement with an account with autoInvoicingOff -- https://github.com/killbill/killbill/pull/1196")
public void testCreateChangeAndCancelSubscriptionWithAutoInvoicingOff() throws Exception {
    final Account accountJson = createAccount();
    assertNotNull(accountJson);
    // assign autoInvoicingOff tag to account
    callbackServlet.pushExpectedEvents(ExtBusEventType.TAG_CREATION);
    final Tags tags = accountApi.createAccountTags(accountJson.getAccountId(), ImmutableList.<UUID>of(new UUID(0L, 2L)), requestOptions);
    assertEquals(tags.get(0).getTagDefinitionName(), "AUTO_INVOICING_OFF");
    callbackServlet.assertListenerStatus();
    // verify that number of invoices and payments for account is still 0
    assertEquals(accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions).size(), 0);
    assertEquals(accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions).size(), 0);
    // create a subscription with no trial plan
    final Subscription input = new Subscription();
    input.setAccountId(accountJson.getAccountId());
    input.setProductName("Blowdart");
    input.setProductCategory(ProductCategory.BASE);
    input.setBillingPeriod(BillingPeriod.MONTHLY);
    input.setPriceList("notrial");
    callbackServlet.pushExpectedEvents(ExtBusEventType.ACCOUNT_CHANGE, /* BCD Update */
    ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, // Note that the BCD isn't set
    ExtBusEventType.ENTITLEMENT_CREATION);
    final Subscription subscriptionJson = subscriptionApi.createSubscription(input, null, null, false, false, false, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertNotNull(subscriptionJson);
    callbackServlet.assertListenerStatus();
    // verify that number of invoices is still 0
    assertEquals(accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions).size(), 0);
    // verify that number of payments is still 0 (no attempts)
    assertEquals(accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions).size(), 0);
    // Avoid test timing issues
    clock.addDays(1);
    callbackServlet.assertListenerStatus();
    // Change Plan
    final Subscription newInput = new Subscription();
    newInput.setSubscriptionId(subscriptionJson.getSubscriptionId());
    newInput.setPlanName("pistol-monthly");
    callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_CHANGE, ExtBusEventType.SUBSCRIPTION_CHANGE);
    subscriptionApi.changeSubscriptionPlan(subscriptionJson.getSubscriptionId(), newInput, null, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, BillingActionPolicy.IMMEDIATE, NULL_PLUGIN_PROPERTIES, requestOptions);
    callbackServlet.assertListenerStatus();
    // Avoid test timing issues
    clock.addDays(1);
    callbackServlet.assertListenerStatus();
    // Cancel subscription (entitlement and billing IMM since there is no BCD set)
    callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.ENTITLEMENT_CANCEL);
    subscriptionApi.cancelSubscriptionPlan(newInput.getSubscriptionId(), null, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, null, null, null, NULL_PLUGIN_PROPERTIES, requestOptions);
    callbackServlet.assertListenerStatus();
}
Also used : Account(org.killbill.billing.client.model.gen.Account) UUID(java.util.UUID) Subscription(org.killbill.billing.client.model.gen.Subscription) Tags(org.killbill.billing.client.model.Tags) Test(org.testng.annotations.Test)

Example 18 with Subscription

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

the class TestEntitlement method testWithNonExistentEntitlement.

@Test(groups = "slow", description = "Can handle non existent subscription")
public void testWithNonExistentEntitlement() throws Exception {
    final UUID subscriptionId = UUID.randomUUID();
    final Subscription subscription = new Subscription();
    subscription.setAccountId(UUID.randomUUID());
    subscription.setSubscriptionId(subscriptionId);
    subscription.setProductName("Pistol");
    subscription.setProductCategory(ProductCategory.BASE);
    subscription.setBillingPeriod(BillingPeriod.ANNUAL);
    subscription.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    subscriptionApi.changeSubscriptionPlan(subscriptionId, subscription, null, null, null, requestOptions);
    subscriptionApi.cancelSubscriptionPlan(subscriptionId, null, null, null, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertNull(subscriptionApi.getSubscription(subscriptionId, requestOptions));
}
Also used : UUID(java.util.UUID) Subscription(org.killbill.billing.client.model.gen.Subscription) Test(org.testng.annotations.Test)

Example 19 with Subscription

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

the class TestEntitlement method testEntitlementsWithAddOnsAndAlreadyExistingBP.

@Test(groups = "slow", description = "Create addOns in a bundle where BP subscription already exist")
public void testEntitlementsWithAddOnsAndAlreadyExistingBP() 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("foobarxyz");
    input.setProductName("Shotgun");
    input.setProductCategory(ProductCategory.BASE);
    input.setBillingPeriod(BillingPeriod.MONTHLY);
    input.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final Subscription subscription = subscriptionApi.createSubscription(input, null, null, null, null, null, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
    final Subscription addOn1 = new Subscription();
    addOn1.setAccountId(accountJson.getAccountId());
    addOn1.setBundleId(subscription.getBundleId());
    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.setBundleId(subscription.getBundleId());
    addOn2.setProductName("Laser-Scope");
    addOn2.setProductCategory(ProductCategory.ADD_ON);
    addOn2.setBillingPeriod(BillingPeriod.MONTHLY);
    addOn2.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final List<Subscription> subscriptions = new ArrayList<Subscription>();
    subscriptions.add(addOn1);
    subscriptions.add(addOn2);
    final BulkSubscriptionsBundles bulkSubscriptionsBundles = new BulkSubscriptionsBundles();
    final BulkSubscriptionsBundle bulkSubscriptionsBundle = new BulkSubscriptionsBundle();
    bulkSubscriptionsBundle.setBaseEntitlementAndAddOns(subscriptions);
    bulkSubscriptionsBundles.add(bulkSubscriptionsBundle);
    final Bundles bundles = subscriptionApi.createSubscriptionsWithAddOns(bulkSubscriptionsBundles, null, null, false, false, null, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertNotNull(bundles);
    assertEquals(bundles.size(), 1);
    assertEquals(bundles.get(0).getSubscriptions().size(), 3);
    final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
    assertEquals(invoices.size(), 2);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Invoice(org.killbill.billing.client.model.gen.Invoice) ArrayList(java.util.ArrayList) BulkSubscriptionsBundle(org.killbill.billing.client.model.gen.BulkSubscriptionsBundle) BulkSubscriptionsBundles(org.killbill.billing.client.model.BulkSubscriptionsBundles) 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 20 with Subscription

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

the class TestEntitlement method testCreateSubscriptionBillingInTheFuture.

@Test(groups = "slow", description = "Can create an entitlement with a future billing date")
public void testCreateSubscriptionBillingInTheFuture() 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.setProductName("Shotgun");
    input.setProductCategory(ProductCategory.BASE);
    input.setBillingPeriod(BillingPeriod.MONTHLY);
    input.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    // Verify callCompletion works (related to https://github.com/killbill/killbill/issues/1193)
    final Subscription entitlementJson = subscriptionApi.createSubscription(input, null, initialDate.toLocalDate().plusMonths(1), false, false, false, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertEquals(entitlementJson.getState(), EntitlementState.ACTIVE);
    Assert.assertNull(entitlementJson.getChargedThroughDate());
    Assert.assertEquals(entitlementJson.getBillingStartDate(), initialDate.toLocalDate().plusMonths(1));
    Assert.assertEquals(entitlementJson.getStartDate(), initialDate.toLocalDate());
    Assert.assertEquals(entitlementJson.getProductName(), input.getProductName());
    Assert.assertEquals(entitlementJson.getProductCategory(), input.getProductCategory());
    Assert.assertEquals(entitlementJson.getBillingPeriod(), input.getBillingPeriod());
    Assert.assertEquals(entitlementJson.getPriceList(), input.getPriceList());
    // Retrieves with GET
    final Subscription subscription = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
    Assert.assertEquals(subscription, entitlementJson);
    Assert.assertEquals(subscription.getPrices().size(), 2);
    Assert.assertEquals(subscription.getPrices().get(0).getPhaseName(), "shotgun-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(), "shotgun-monthly-evergreen");
    Assert.assertNull(subscription.getPrices().get(1).getFixedPrice());
    Assert.assertEquals(subscription.getPrices().get(1).getRecurringPrice(), new BigDecimal("249.95"));
}
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)

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