Search in sources :

Example 1 with Subscription

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

the class KillbillClient method createAccountWithExternalPMBundleAndSubscriptionAndManualPayTagAndWaitForFirstInvoice.

protected Account createAccountWithExternalPMBundleAndSubscriptionAndManualPayTagAndWaitForFirstInvoice() throws Exception {
    final Account accountJson = createAccountWithExternalPaymentMethod();
    assertNotNull(accountJson);
    callbackServlet.pushExpectedEvent(ExtBusEventType.TAG_CREATION);
    final Tags accountTag = accountApi.createAccountTags(accountJson.getAccountId(), ImmutableList.<UUID>of(ControlTagType.MANUAL_PAY.getId()), requestOptions);
    callbackServlet.assertListenerStatus();
    assertNotNull(accountTag);
    assertEquals(accountTag.get(0).getTagDefinitionId(), ControlTagType.MANUAL_PAY.getId());
    // Add a bundle, subscription and move the clock to get the first invoice
    final Subscription subscriptionJson = createSubscription(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
    assertNotNull(subscriptionJson);
    callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION);
    clock.addDays(32);
    callbackServlet.assertListenerStatus();
    return accountJson;
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Subscription(org.killbill.billing.client.model.gen.Subscription) Tags(org.killbill.billing.client.model.Tags)

Example 2 with Subscription

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

the class KillbillClient method createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice.

protected Account createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice() throws Exception {
    // Create an account with no payment method
    final Account accountJson = createAccount();
    assertNotNull(accountJson);
    // Add a bundle, subscription and move the clock to get the first invoice
    final Subscription subscriptionJson = createSubscription(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
    assertNotNull(subscriptionJson);
    // No payment will be triggered as the account doesn't have a payment method
    callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_FAILED);
    clock.addMonths(1);
    callbackServlet.assertListenerStatus();
    return accountJson;
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Subscription(org.killbill.billing.client.model.gen.Subscription)

Example 3 with Subscription

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

the class TestBundle method testBlockBundle.

@Test(groups = "slow", description = "Block a bundle")
public void testBlockBundle() 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 String bundleExternalKey = "93199";
    final Subscription entitlement = createSubscription(accountJson.getAccountId(), bundleExternalKey, productName, ProductCategory.BASE, term);
    Bundles existingBundles = bundleApi.getBundleByKey(bundleExternalKey, requestOptions);
    assertEquals(existingBundles.size(), 1);
    final Bundle bundle = existingBundles.get(0);
    assertEquals(bundle.getAccountId(), accountJson.getAccountId());
    assertEquals(bundle.getExternalKey(), bundleExternalKey);
    final BlockingState blockingState = new BlockingState(bundle.getBundleId(), "block", "service", false, true, true, null, BlockingStateType.SUBSCRIPTION_BUNDLE, null);
    bundleApi.addBundleBlockingState(bundle.getBundleId(), blockingState, clock.getToday(DateTimeZone.forID(accountJson.getTimeZone())), ImmutableMap.<String, String>of(), requestOptions);
    final Subscription subscription = subscriptionApi.getSubscription(entitlement.getSubscriptionId(), requestOptions);
    assertEquals(subscription.getState(), EntitlementState.BLOCKED);
    clock.addDays(1);
    final BlockingState unblockingState = new BlockingState(bundle.getBundleId(), "unblock", "service", false, false, false, null, BlockingStateType.SUBSCRIPTION_BUNDLE, null);
    bundleApi.addBundleBlockingState(bundle.getBundleId(), unblockingState, clock.getToday(DateTimeZone.forID(accountJson.getTimeZone())), ImmutableMap.<String, String>of(), requestOptions);
    final Subscription subscription2 = subscriptionApi.getSubscription(entitlement.getSubscriptionId(), requestOptions);
    assertEquals(subscription2.getState(), EntitlementState.ACTIVE);
    final BlockingStates blockingStates = accountApi.getBlockingStates(accountJson.getAccountId(), null, ImmutableList.<String>of("service"), AuditLevel.FULL, requestOptions);
    Assert.assertEquals(blockingStates.size(), 2);
    final BlockingStates blockingStates2 = accountApi.getBlockingStates(accountJson.getAccountId(), ImmutableList.<BlockingStateType>of(BlockingStateType.SUBSCRIPTION_BUNDLE), null, AuditLevel.FULL, requestOptions);
    Assert.assertEquals(blockingStates2.size(), 2);
    final BlockingStates blockingStates3 = accountApi.getBlockingStates(accountJson.getAccountId(), null, null, AuditLevel.FULL, requestOptions);
    Assert.assertEquals(blockingStates3.size(), 3);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) BlockingStates(org.killbill.billing.client.model.BlockingStates) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) Bundle(org.killbill.billing.client.model.gen.Bundle) BlockingState(org.killbill.billing.client.model.gen.BlockingState) Subscription(org.killbill.billing.client.model.gen.Subscription) DateTime(org.joda.time.DateTime) Bundles(org.killbill.billing.client.model.Bundles) Test(org.testng.annotations.Test)

Example 4 with Subscription

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

the class TestBundle method testBundleTransfer.

@Test(groups = "slow", description = "Can transfer bundle")
public void testBundleTransfer() 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 String bundleExternalKey = "93199";
    final Subscription entitlementJsonNoEvents = createSubscription(accountJson.getAccountId(), bundleExternalKey, productName, ProductCategory.BASE, term);
    Bundles existingBundles = bundleApi.getBundleByKey(bundleExternalKey, requestOptions);
    assertEquals(existingBundles.size(), 1);
    Bundle originalBundle = existingBundles.get(0);
    existingBundles = bundleApi.getBundleByKey(bundleExternalKey, requestOptions);
    assertEquals(existingBundles.size(), 1);
    originalBundle = existingBundles.get(0);
    assertEquals(originalBundle.getAccountId(), accountJson.getAccountId());
    assertEquals(originalBundle.getAccountId(), accountJson.getAccountId());
    assertEquals(originalBundle.getExternalKey(), bundleExternalKey);
    final Account newAccount = createAccountWithDefaultPaymentMethod();
    final Bundle bundle = new Bundle();
    bundle.setAccountId(newAccount.getAccountId());
    bundle.setBundleId(entitlementJsonNoEvents.getBundleId());
    bundleApi.transferBundle(entitlementJsonNoEvents.getBundleId(), bundle, null, NULL_PLUGIN_PROPERTIES, requestOptions);
    existingBundles = bundleApi.getBundleByKey(bundleExternalKey, requestOptions);
    assertEquals(existingBundles.size(), 1);
    final Bundle newBundle = existingBundles.get(0);
    assertNotEquals(newBundle.getBundleId(), originalBundle.getBundleId());
    assertEquals(newBundle.getExternalKey(), originalBundle.getExternalKey());
    assertEquals(newBundle.getAccountId(), newAccount.getAccountId());
    final Bundles bundles = bundleApi.getBundleByKey(bundleExternalKey, true, AuditLevel.NONE, requestOptions);
    assertEquals(bundles.size(), 2);
    assertSubscriptionState(bundles, originalBundle.getBundleId(), EntitlementState.CANCELLED);
    assertSubscriptionState(bundles, newBundle.getBundleId(), EntitlementState.ACTIVE);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) Bundle(org.killbill.billing.client.model.gen.Bundle) Subscription(org.killbill.billing.client.model.gen.Subscription) DateTime(org.joda.time.DateTime) Bundles(org.killbill.billing.client.model.Bundles) Test(org.testng.annotations.Test)

Example 5 with Subscription

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

the class TestEntitlement method testOverridePrice.

@Test(groups = "slow", description = "Can override a price when creating a subscription")
public void testOverridePrice() 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.ANNUAL;
    final Subscription input = new Subscription();
    input.setAccountId(accountJson.getAccountId());
    input.setBundleExternalKey("identical");
    input.setProductName(productName);
    input.setProductCategory(ProductCategory.BASE);
    input.setBillingPeriod(BillingPeriod.MONTHLY);
    input.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final List<PhasePrice> overrides = new ArrayList<PhasePrice>();
    overrides.add(new PhasePrice(null, null, PhaseType.TRIAL.toString(), BigDecimal.TEN, null, null));
    input.setPriceOverrides(overrides);
    callbackServlet.pushExpectedEvents(ExtBusEventType.ACCOUNT_CHANGE, ExtBusEventType.ENTITLEMENT_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_SUCCESS, ExtBusEventType.PAYMENT_SUCCESS);
    final Subscription subscription = subscriptionApi.createSubscription(input, null, null, null, null, false, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
    callbackServlet.assertListenerStatus();
    Assert.assertEquals(subscription.getPrices().size(), 2);
    Assert.assertEquals(subscription.getEvents().size(), 3);
    Assert.assertEquals(subscription.getEvents().get(0).getEventType(), SubscriptionEventType.START_ENTITLEMENT);
    assertMatches(subscription.getEvents().get(0).getPlan(), "shotgun-monthly-[1-9]+");
    assertMatches(subscription.getEvents().get(0).getPhase(), "shotgun-monthly-[1-9]+-trial");
    Assert.assertEquals(subscription.getEvents().get(0).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME);
    Assert.assertEquals(subscription.getEvents().get(0).getProduct(), "Shotgun");
    Assert.assertEquals(subscription.getEvents().get(1).getEventType(), SubscriptionEventType.START_BILLING);
    assertMatches(subscription.getEvents().get(1).getPlan(), "shotgun-monthly-[1-9]+");
    assertMatches(subscription.getEvents().get(1).getPhase(), "shotgun-monthly-[1-9]+-trial");
    Assert.assertEquals(subscription.getEvents().get(1).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME);
    Assert.assertEquals(subscription.getEvents().get(1).getProduct(), "Shotgun");
    Assert.assertEquals(subscription.getEvents().get(2).getEventType(), SubscriptionEventType.PHASE);
    assertMatches(subscription.getEvents().get(2).getPlan(), "shotgun-monthly-[1-9]+");
    assertMatches(subscription.getEvents().get(2).getPhase(), "shotgun-monthly-[1-9]+-evergreen");
    Assert.assertEquals(subscription.getEvents().get(2).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME);
    Assert.assertEquals(subscription.getEvents().get(2).getProduct(), "Shotgun");
    final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.FULL, requestOptions);
    assertEquals(invoices.size(), 1);
    assertEquals(invoices.get(0).getAmount().compareTo(BigDecimal.TEN), 0);
    // Move clock after phase
    callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_SUCCESS, ExtBusEventType.PAYMENT_SUCCESS);
    clock.addDays(30);
    callbackServlet.assertListenerStatus();
    final Subscription subscription2 = subscriptionApi.getSubscription(subscription.getSubscriptionId(), requestOptions);
    Assert.assertEquals(subscription2.getEvents().size(), 3);
    clock.addDays(3);
    // Change Plan
    final Subscription newInput = new Subscription();
    newInput.setSubscriptionId(subscription2.getSubscriptionId());
    newInput.setPlanName("pistol-monthly");
    subscriptionApi.changeSubscriptionPlan(subscription2.getSubscriptionId(), newInput, null, BillingActionPolicy.IMMEDIATE, NULL_PLUGIN_PROPERTIES, requestOptions);
    final Subscription subscription3 = subscriptionApi.getSubscription(subscription.getSubscriptionId(), requestOptions);
    Assert.assertEquals(subscription3.getEvents().size(), 4);
    Assert.assertEquals(subscription3.getEvents().get(0).getEventType(), SubscriptionEventType.START_ENTITLEMENT);
    assertMatches(subscription3.getEvents().get(0).getPlan(), "shotgun-monthly-[1-9]+");
    assertMatches(subscription3.getEvents().get(0).getPhase(), "shotgun-monthly-[1-9]+-trial");
    Assert.assertEquals(subscription3.getEvents().get(0).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
    Assert.assertEquals(subscription3.getEvents().get(0).getProduct(), "Shotgun");
    Assert.assertEquals(subscription3.getEvents().get(1).getEventType(), SubscriptionEventType.START_BILLING);
    assertMatches(subscription3.getEvents().get(1).getPlan(), "shotgun-monthly-[1-9]+");
    assertMatches(subscription3.getEvents().get(1).getPhase(), "shotgun-monthly-[1-9]+-trial");
    Assert.assertEquals(subscription3.getEvents().get(1).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
    Assert.assertEquals(subscription3.getEvents().get(1).getProduct(), "Shotgun");
    Assert.assertEquals(subscription3.getEvents().get(2).getEventType(), SubscriptionEventType.PHASE);
    assertMatches(subscription3.getEvents().get(2).getPlan(), "shotgun-monthly-[1-9]+");
    assertMatches(subscription3.getEvents().get(2).getPhase(), "shotgun-monthly-[1-9]+-evergreen");
    Assert.assertEquals(subscription3.getEvents().get(2).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
    Assert.assertEquals(subscription3.getEvents().get(2).getProduct(), "Shotgun");
    Assert.assertEquals(subscription3.getEvents().get(3).getEventType(), SubscriptionEventType.CHANGE);
    Assert.assertEquals(subscription3.getEvents().get(3).getPlan(), "pistol-monthly");
    Assert.assertEquals(subscription3.getEvents().get(3).getPhase(), "pistol-monthly-evergreen");
    Assert.assertEquals(subscription3.getEvents().get(3).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
    Assert.assertEquals(subscription3.getEvents().get(3).getProduct(), "Pistol");
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Invoice(org.killbill.billing.client.model.gen.Invoice) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) ArrayList(java.util.ArrayList) PhasePrice(org.killbill.billing.client.model.gen.PhasePrice) 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