Search in sources :

Example 6 with Subscription

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

the class TestEntitlement method testCreateEntitlementWithAutoPayOff.

@Test(groups = "slow", description = "Can create an entitlement with an account with autoPayOff")
public void testCreateEntitlementWithAutoPayOff() throws Exception {
    final Account accountJson = createAccount();
    assertNotNull(accountJson);
    // assign autoPaymentOff tag to account
    Tags tags = killBillClient.createAccountTag(accountJson.getAccountId(), new UUID(0L, 1L), requestOptions);
    assertEquals(tags.get(0).getTagDefinitionName(), "AUTO_PAY_OFF");
    // verify that number of invoices and payments for account is still 0
    assertEquals(killBillClient.getInvoicesForAccount(accountJson.getAccountId(), requestOptions).size(), 0);
    assertEquals(killBillClient.getPaymentsForAccount(accountJson.getAccountId(), 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");
    final Subscription subscriptionJson = killBillClient.createSubscription(input, null, 10, requestOptions);
    assertNotNull(subscriptionJson);
    // verify that number of invoices is now 1
    assertEquals(killBillClient.getInvoicesForAccount(accountJson.getAccountId(), requestOptions).size(), 1);
    // verify that number of payments is still 0 (no attempts)
    assertEquals(killBillClient.getPaymentsForAccount(accountJson.getAccountId(), requestOptions).size(), 0);
}
Also used : Account(org.killbill.billing.client.model.Account) UUID(java.util.UUID) Subscription(org.killbill.billing.client.model.Subscription) Tags(org.killbill.billing.client.model.Tags) Test(org.testng.annotations.Test)

Example 7 with Subscription

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

the class TestEntitlement method testCreateEntitlementsWithoutBase.

@Test(groups = "slow", description = "Create a bulk of base entitlements and addOns under the same transaction", expectedExceptions = KillBillClientException.class, expectedExceptionsMessageRegExp = "SubscriptionJson Base Entitlement needs to be provided")
public void testCreateEntitlementsWithoutBase() 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 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> subscriptions = new ArrayList<Subscription>();
    subscriptions.add(addOn1);
    final List<BulkBaseSubscriptionAndAddOns> bulkList = new ArrayList<BulkBaseSubscriptionAndAddOns>();
    bulkList.add(new BulkBaseSubscriptionAndAddOns(subscriptions));
    bulkList.add(new BulkBaseSubscriptionAndAddOns(subscriptions));
    killBillClient.createSubscriptionsWithAddOns(bulkList, null, 10, requestOptions);
}
Also used : Account(org.killbill.billing.client.model.Account) BulkBaseSubscriptionAndAddOns(org.killbill.billing.client.model.BulkBaseSubscriptionAndAddOns) ArrayList(java.util.ArrayList) Subscription(org.killbill.billing.client.model.Subscription) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 8 with Subscription

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

the class TestEntitlement method testEntitlementWithAddOns.

@Test(groups = "slow", description = "Create a base entitlement and also addOns entitlements under the same bundle")
public void testEntitlementWithAddOns() 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.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.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.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 Bundle bundle = killBillClient.createSubscriptionWithAddOns(subscriptions, null, 10, "createdBy", "", "");
    assertNotNull(bundle);
    assertEquals(bundle.getExternalKey(), "base");
    assertEquals(bundle.getSubscriptions().size(), 3);
    final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, false, false, AuditLevel.FULL);
    assertEquals(invoices.size(), 1);
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) Bundle(org.killbill.billing.client.model.Bundle) ArrayList(java.util.ArrayList) Subscription(org.killbill.billing.client.model.Subscription) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 9 with Subscription

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

the class TestCache method createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoiceWithInputOptions.

private void createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoiceWithInputOptions(final RequestOptions inputOptions) throws Exception {
    Account account = killBillClient.createAccount(getAccount(), inputOptions);
    final PaymentMethodPluginDetail info = new PaymentMethodPluginDetail();
    info.setProperties(null);
    final PaymentMethod paymentMethodJson = new PaymentMethod(null, UUID.randomUUID().toString(), account.getAccountId(), true, PLUGIN_NAME, info);
    killBillClient.createPaymentMethod(paymentMethodJson, inputOptions);
    final Subscription subscription = new Subscription();
    subscription.setAccountId(account.getAccountId());
    subscription.setExternalKey(UUID.randomUUID().toString());
    subscription.setProductName("Sports");
    subscription.setProductCategory(ProductCategory.BASE);
    subscription.setBillingPeriod(BillingPeriod.MONTHLY);
    subscription.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    clock.resetDeltaFromReality();
    clock.setDay(new LocalDate(2013, 3, 1));
    final Subscription subscriptionJson = killBillClient.createSubscription(subscription, clock.getUTCToday(), DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, inputOptions);
    assertNotNull(subscriptionJson);
    clock.addDays(32);
    crappyWaitForLackOfProperSynchonization();
}
Also used : Account(org.killbill.billing.client.model.Account) PaymentMethodPluginDetail(org.killbill.billing.client.model.PaymentMethodPluginDetail) PaymentMethod(org.killbill.billing.client.model.PaymentMethod) Subscription(org.killbill.billing.client.model.Subscription) LocalDate(org.joda.time.LocalDate)

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