Search in sources :

Example 31 with Subscription

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

the class TestEntitlement method testCreateChangeAndCancelSubscriptionWithAutoPayOff.

@Test(groups = "slow", description = "Can create an entitlement with an account with autoPayOff -- https://github.com/killbill/killbill/issues/1193")
public void testCreateChangeAndCancelSubscriptionWithAutoPayOff() throws Exception {
    final Account accountJson = createAccount();
    assertNotNull(accountJson);
    // assign autoPaymentOff tag to account
    callbackServlet.pushExpectedEvents(ExtBusEventType.TAG_CREATION);
    final Tags tags = accountApi.createAccountTags(accountJson.getAccountId(), ImmutableList.<UUID>of(new UUID(0L, 1L)), requestOptions);
    assertEquals(tags.get(0).getTagDefinitionName(), "AUTO_PAY_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.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.ENTITLEMENT_CREATION, ExtBusEventType.ACCOUNT_CHANGE, // The BCD is updated in that case
    ExtBusEventType.INVOICE_CREATION);
    final Subscription subscriptionJson = subscriptionApi.createSubscription(input, null, null, null, null, null, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertNotNull(subscriptionJson);
    callbackServlet.assertListenerStatus();
    // verify that number of invoices is now 1
    assertEquals(accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions).size(), 1);
    // 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, ExtBusEventType.INVOICE_CREATION);
    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 IMM, billing EOT)
    callbackServlet.pushExpectedEvents(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 32 with Subscription

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

the class TestEntitlement method testCreateSubscriptionBillingInThePast.

@Test(groups = "slow", description = "Can create an entitlement with a past billing date")
public void testCreateSubscriptionBillingInThePast() 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().minusMonths(1), false, false, false, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertEquals(entitlementJson.getState(), EntitlementState.ACTIVE);
    verifyChargedThroughDate(entitlementJson.getSubscriptionId(), new LocalDate("2012-05-24"));
    Assert.assertEquals(entitlementJson.getBillingStartDate(), initialDate.toLocalDate().minusMonths(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) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 33 with Subscription

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

the class TestEntitlement method testCreateSubscriptionsWithoutBase.

@Test(groups = "slow", description = "Create a bulk of base entitlements and addOns under the same transaction", expectedExceptions = KillBillClientException.class, expectedExceptionsMessageRegExp = "SubscriptionJson productName needs to be set when no planName is specified")
public void testCreateSubscriptionsWithoutBase() 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 bp1 = new Subscription();
    bp1.setAccountId(accountJson.getAccountId());
    bp1.setProductCategory(ProductCategory.BASE);
    bp1.setBundleExternalKey("12345");
    final Subscription addOn1 = new Subscription();
    addOn1.setAccountId(accountJson.getAccountId());
    addOn1.setProductName("Telescopic-Scope");
    addOn1.setProductCategory(ProductCategory.ADD_ON);
    addOn1.setBillingPeriod(BillingPeriod.MONTHLY);
    addOn1.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final List<Subscription> subscriptions1 = new ArrayList<Subscription>();
    subscriptions1.add(bp1);
    subscriptions1.add(addOn1);
    final Subscription bp2 = new Subscription();
    bp2.setAccountId(accountJson.getAccountId());
    bp2.setProductCategory(ProductCategory.BASE);
    bp2.setBundleExternalKey("54321");
    final Subscription addOn2 = new Subscription();
    addOn2.setAccountId(accountJson.getAccountId());
    addOn2.setProductName("Telescopic-Scope");
    addOn2.setProductCategory(ProductCategory.ADD_ON);
    addOn2.setBillingPeriod(BillingPeriod.MONTHLY);
    addOn2.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final List<Subscription> subscriptions2 = new ArrayList<Subscription>();
    subscriptions2.add(bp1);
    subscriptions2.add(addOn1);
    final BulkSubscriptionsBundle bulkList1 = new BulkSubscriptionsBundle();
    bulkList1.setBaseEntitlementAndAddOns(subscriptions1);
    final BulkSubscriptionsBundle bulkList2 = new BulkSubscriptionsBundle();
    bulkList2.setBaseEntitlementAndAddOns(subscriptions2);
    final BulkSubscriptionsBundles input = new BulkSubscriptionsBundles();
    input.add(bulkList1);
    input.add(bulkList2);
    final Bundles res = subscriptionApi.createSubscriptionsWithAddOns(input, null, null, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(res.size(), 2);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) 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 34 with Subscription

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

the class TestTag method testGetAllTagsByType.

@Test(groups = "slow", description = "Can search all tags for an account")
public void testGetAllTagsByType() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account account = createAccountWithDefaultPaymentMethod();
    final Subscription subscriptionJson = createSubscription(account.getAccountId(), "87544332", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
    int nbAllowedControlTagType = 0;
    for (final ControlTagType controlTagType : ControlTagType.values()) {
        if (controlTagType.getApplicableObjectTypes().contains(ObjectType.ACCOUNT)) {
            accountApi.createAccountTags(account.getAccountId(), ImmutableList.<UUID>of(controlTagType.getId()), requestOptions);
            nbAllowedControlTagType++;
        }
    }
    final TagDefinition bundleTagDefInput = new TagDefinition(null, false, "bundletagdef", "nothing special", ImmutableList.<ObjectType>of(ObjectType.TRANSACTION), null);
    final TagDefinition bundleTagDef = tagDefinitionApi.createTagDefinition(bundleTagDefInput, requestOptions);
    bundleApi.createBundleTags(subscriptionJson.getBundleId(), ImmutableList.<UUID>of(bundleTagDef.getId()), requestOptions);
    final Tags allBundleTags = bundleApi.getBundleTags(subscriptionJson.getBundleId(), requestOptions);
    Assert.assertEquals(allBundleTags.size(), 1);
    final Tags allAccountTags = accountApi.getAllTags(account.getAccountId(), null, requestOptions);
    Assert.assertEquals(allAccountTags.size(), nbAllowedControlTagType + 1);
    final Tags allBundleTagsForAccount = accountApi.getAllTags(account.getAccountId(), ObjectType.BUNDLE, requestOptions);
    Assert.assertEquals(allBundleTagsForAccount.size(), 1);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) ControlTagType(org.killbill.billing.util.tag.ControlTagType) TagDefinition(org.killbill.billing.client.model.gen.TagDefinition) Subscription(org.killbill.billing.client.model.gen.Subscription) DateTime(org.joda.time.DateTime) Tags(org.killbill.billing.client.model.Tags) SystemTags(org.killbill.billing.util.tag.dao.SystemTags) Test(org.testng.annotations.Test)

Example 35 with Subscription

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

the class TestChargeback method createAccountWithInvoice.

private Invoice createAccountWithInvoice() throws Exception {
    // Create account
    final Account accountJson = createAccountWithDefaultPaymentMethod();
    // Create subscription
    final Subscription subscriptionJson = createSubscription(accountJson.getAccountId(), "6253283", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
    assertNotNull(subscriptionJson);
    // Move after the trial period to trigger an invoice with a non-zero invoice item
    callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_SUCCESS, ExtBusEventType.PAYMENT_SUCCESS);
    clock.addDays(32);
    callbackServlet.assertListenerStatus();
    // Retrieve the invoice
    final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
    // We should have two invoices, one for the trial (zero dollar amount) and one for the first month
    assertEquals(invoices.size(), 2);
    assertTrue(invoices.get(1).getAmount().doubleValue() > 0);
    return invoices.get(1);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Invoice(org.killbill.billing.client.model.gen.Invoice) Subscription(org.killbill.billing.client.model.gen.Subscription)

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