Search in sources :

Example 1 with Subscription

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

the class KillbillClient method createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice.

protected Account createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice() throws Exception {
    final Account accountJson = createAccountWithDefaultPaymentMethod();
    assertNotNull(accountJson);
    // Add a bundle, subscription and move the clock to get the first invoice
    final Subscription subscriptionJson = createEntitlement(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, true);
    assertNotNull(subscriptionJson);
    clock.addDays(32);
    crappyWaitForLackOfProperSynchonization();
    return accountJson;
}
Also used : Account(org.killbill.billing.client.model.Account) Subscription(org.killbill.billing.client.model.Subscription)

Example 2 with Subscription

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

the class KillbillClient method createEntitlement.

protected Subscription createEntitlement(final UUID accountId, final String bundleExternalKey, final String productName, final ProductCategory productCategory, final BillingPeriod billingPeriod, final boolean waitCompletion) throws Exception {
    final Subscription input = new Subscription();
    input.setAccountId(accountId);
    input.setExternalKey(bundleExternalKey);
    input.setProductName(productName);
    input.setProductCategory(productCategory);
    input.setBillingPeriod(billingPeriod);
    input.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    return killBillClient.createSubscription(input, null, waitCompletion ? DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC : -1, requestOptions);
}
Also used : Subscription(org.killbill.billing.client.model.Subscription)

Example 3 with Subscription

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

the class TestInvoiceNotification method createScenarioWithOneInvoice.

private Account createScenarioWithOneInvoice() 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();
    Assert.assertNotNull(accountJson);
    final Subscription subscriptionJson = createEntitlement(accountJson.getAccountId(), "76213", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, true);
    Assert.assertNotNull(subscriptionJson);
    return accountJson;
}
Also used : Account(org.killbill.billing.client.model.Account) Subscription(org.killbill.billing.client.model.Subscription) DateTime(org.joda.time.DateTime)

Example 4 with Subscription

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

the class TestEntitlement method testCreateEntitlementInTheFuture.

@Test(groups = "slow", description = "Can create an entitlement in the future")
public void testCreateEntitlementInTheFuture() 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);
    final Subscription entitlementJson = killBillClient.createSubscription(input, initialDate.toLocalDate().plusMonths(1), -1, requestOptions);
    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 = killBillClient.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
    Assert.assertTrue(subscription.equals(entitlementJson));
    Assert.assertEquals(subscription.getPriceOverrides().size(), 2);
    Assert.assertEquals(subscription.getPriceOverrides().get(0).getPhaseName(), "shotgun-monthly-trial");
    Assert.assertEquals(subscription.getPriceOverrides().get(0).getFixedPrice(), BigDecimal.ZERO);
    Assert.assertNull(subscription.getPriceOverrides().get(0).getRecurringPrice());
    Assert.assertEquals(subscription.getPriceOverrides().get(1).getPhaseName(), "shotgun-monthly-evergreen");
    Assert.assertNull(subscription.getPriceOverrides().get(1).getFixedPrice());
    Assert.assertEquals(subscription.getPriceOverrides().get(1).getRecurringPrice(), new BigDecimal("249.95"));
}
Also used : Account(org.killbill.billing.client.model.Account) Subscription(org.killbill.billing.client.model.Subscription) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 5 with Subscription

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

the class TestEntitlement method testCreateEntitlementsWithAddOns.

@Test(groups = "slow", description = "Create a bulk of base entitlement and addOns under the same transaction")
public void testCreateEntitlementsWithAddOns() 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 base = new Subscription();
    base.setAccountId(accountJson.getAccountId());
    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.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.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(base);
    subscriptions.add(addOn1);
    subscriptions.add(addOn2);
    final List<BulkBaseSubscriptionAndAddOns> bulkList = new ArrayList<BulkBaseSubscriptionAndAddOns>();
    bulkList.add(new BulkBaseSubscriptionAndAddOns(subscriptions));
    bulkList.add(new BulkBaseSubscriptionAndAddOns(subscriptions));
    final Bundles bundles = killBillClient.createSubscriptionsWithAddOns(bulkList, null, 10, requestOptions);
    assertNotNull(bundles);
    assertEquals(bundles.size(), 2);
    assertFalse(bundles.get(0).getExternalKey().equals(bundles.get(1).getExternalKey()));
    final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, false, false, requestOptions);
    assertEquals(invoices.size(), 1);
}
Also used : Account(org.killbill.billing.client.model.Account) BulkBaseSubscriptionAndAddOns(org.killbill.billing.client.model.BulkBaseSubscriptionAndAddOns) Invoice(org.killbill.billing.client.model.Invoice) ArrayList(java.util.ArrayList) Subscription(org.killbill.billing.client.model.Subscription) DateTime(org.joda.time.DateTime) Bundles(org.killbill.billing.client.model.Bundles) Test(org.testng.annotations.Test)

Aggregations

Subscription (org.killbill.billing.client.model.Subscription)9 Account (org.killbill.billing.client.model.Account)8 DateTime (org.joda.time.DateTime)5 Test (org.testng.annotations.Test)5 ArrayList (java.util.ArrayList)3 BulkBaseSubscriptionAndAddOns (org.killbill.billing.client.model.BulkBaseSubscriptionAndAddOns)2 Invoice (org.killbill.billing.client.model.Invoice)2 BigDecimal (java.math.BigDecimal)1 UUID (java.util.UUID)1 LocalDate (org.joda.time.LocalDate)1 Bundle (org.killbill.billing.client.model.Bundle)1 Bundles (org.killbill.billing.client.model.Bundles)1 PaymentMethod (org.killbill.billing.client.model.PaymentMethod)1 PaymentMethodPluginDetail (org.killbill.billing.client.model.PaymentMethodPluginDetail)1 Tags (org.killbill.billing.client.model.Tags)1