use of org.killbill.billing.catalog.api.BillingPeriod 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);
}
use of org.killbill.billing.catalog.api.BillingPeriod 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");
}
use of org.killbill.billing.catalog.api.BillingPeriod in project killbill by killbill.
the class TestEntitlement method testEntitlementInTrialOk.
@Test(groups = "slow", description = "Can change plan and cancel a subscription")
public void testEntitlementInTrialOk() 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 Subscription entitlementJson = createSubscription(accountJson.getAccountId(), "99999", productName, ProductCategory.BASE, term);
// Retrieves with GET
Subscription subscription = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
Assert.assertEquals(subscription.getPrices().size(), 2);
Assert.assertEquals(subscription.getPrices().get(0).getFixedPrice(), BigDecimal.ZERO);
Assert.assertNull(subscription.getPrices().get(0).getRecurringPrice());
Assert.assertNull(subscription.getPrices().get(1).getFixedPrice());
Assert.assertEquals(subscription.getPrices().get(1).getRecurringPrice(), new BigDecimal("249.95"));
Assert.assertEquals(subscription, entitlementJson);
final Subscription subscription2 = subscriptionApi.getSubscriptionByKey(subscription.getExternalKey(), requestOptions);
assertEquals(subscription2.getBundleExternalKey(), "99999");
assertEquals(subscription2.getExternalKey(), subscription.getExternalKey());
// Change the clock otherwise the CREATE event might be replaced (instead of having a CHANGE event)
clock.addDays(1);
callbackServlet.assertListenerStatus();
// Change plan IMM
final String newProductName = "Assault-Rifle";
final Subscription newInput = new Subscription();
newInput.setAccountId(entitlementJson.getAccountId());
newInput.setSubscriptionId(entitlementJson.getSubscriptionId());
newInput.setProductName(newProductName);
newInput.setProductCategory(ProductCategory.BASE);
newInput.setBillingPeriod(entitlementJson.getBillingPeriod());
newInput.setPriceList(entitlementJson.getPriceList());
callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_CHANGE, ExtBusEventType.SUBSCRIPTION_CHANGE, ExtBusEventType.INVOICE_CREATION);
subscriptionApi.changeSubscriptionPlan(entitlementJson.getSubscriptionId(), newInput, null, null, NULL_PLUGIN_PROPERTIES, requestOptions);
callbackServlet.assertListenerStatus();
Assert.assertNotNull(subscription);
// MOVE AFTER TRIAL
callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_SUCCESS, ExtBusEventType.PAYMENT_SUCCESS);
clock.addDays(30);
callbackServlet.assertListenerStatus();
// Cancel IMM (Billing EOT)
subscriptionApi.cancelSubscriptionPlan(newInput.getSubscriptionId(), null, null, null, NULL_PLUGIN_PROPERTIES, requestOptions);
// Retrieves to check EndDate
subscription = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
assertNotNull(subscription.getCancelledDate());
assertTrue(subscription.getCancelledDate().compareTo(new LocalDate(clock.getUTCNow())) == 0);
final Bundles accountBundles = accountApi.getAccountBundles(accountJson.getAccountId(), null, null, requestOptions);
assertEquals(accountBundles.size(), 1);
assertEquals(accountBundles.get(0).getSubscriptions().size(), 1);
assertEquals(accountBundles.get(0).getSubscriptions().get(0).getState(), EntitlementState.CANCELLED);
final Bundles bundlesByKey1 = bundleApi.getBundleByKey(entitlementJson.getBundleExternalKey(), true, AuditLevel.NONE, requestOptions);
assertEquals(bundlesByKey1.size(), 1);
assertEquals(bundlesByKey1.get(0).getSubscriptions().size(), 1);
assertEquals(bundlesByKey1.get(0).getSubscriptions().get(0).getState(), EntitlementState.CANCELLED);
final Bundles bundlesByKey2 = bundleApi.getBundleByKey(entitlementJson.getBundleExternalKey(), requestOptions);
assertNotNull(bundlesByKey2);
assertEquals(bundlesByKey2.size(), 0);
}
use of org.killbill.billing.catalog.api.BillingPeriod in project killbill by killbill.
the class TestEntitlement method testMoveEntitlementBCD.
@Test(groups = "slow", description = "Verify we can move the BCD associated with the subscription")
public void testMoveEntitlementBCD() 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 Subscription entitlementJson = createSubscription(accountJson.getAccountId(), "99999", productName, ProductCategory.BASE, term);
Assert.assertEquals(entitlementJson.getBillCycleDayLocal(), new Integer(25));
final Subscription updatedSubscription = new Subscription();
updatedSubscription.setSubscriptionId(entitlementJson.getSubscriptionId());
updatedSubscription.setBillCycleDayLocal(9);
callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_BCD_CHANGE);
subscriptionApi.updateSubscriptionBCD(entitlementJson.getSubscriptionId(), updatedSubscription, null, requestOptions);
callbackServlet.assertListenerStatus();
final Subscription result = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
// Still shows as the 4 (BCD did not take effect)
Assert.assertEquals(result.getBillCycleDayLocal(), new Integer(25));
// 2012, 5, 9
callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_BCD_CHANGE);
clock.addDays(14);
callbackServlet.assertListenerStatus();
final Subscription result2 = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
// Still shows as the 4 (BCD did not take effect)
Assert.assertEquals(result2.getBillCycleDayLocal(), new Integer(9));
}
use of org.killbill.billing.catalog.api.BillingPeriod in project killbill by killbill.
the class TestEntitlement method testEntitlementUndoChangePlan.
@Test(groups = "slow", description = "Can changePlan and undo changePlan on a subscription")
public void testEntitlementUndoChangePlan() 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 Subscription entitlementJson = createSubscription(accountJson.getAccountId(), "99999", productName, ProductCategory.BASE, term);
// Change plan in the future
final String newProductName = "Assault-Rifle";
final Subscription newInput = new Subscription();
newInput.setAccountId(entitlementJson.getAccountId());
newInput.setSubscriptionId(entitlementJson.getSubscriptionId());
newInput.setProductName(newProductName);
newInput.setProductCategory(ProductCategory.BASE);
newInput.setBillingPeriod(entitlementJson.getBillingPeriod());
newInput.setPriceList(entitlementJson.getPriceList());
callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_CHANGE);
subscriptionApi.changeSubscriptionPlan(entitlementJson.getSubscriptionId(), newInput, new LocalDate(2012, 4, 28), null, NULL_PLUGIN_PROPERTIES, requestOptions);
Subscription refreshedSubscription = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
callbackServlet.assertListenerStatus();
Assert.assertNotNull(refreshedSubscription);
final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(1));
clock.addDeltaFromReality(it.toDurationMillis());
// We get 2 SUBSCRIPTION_CHANGE events, one for requested and one or effective, which are the same.
callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_CHANGE, ExtBusEventType.SUBSCRIPTION_CHANGE);
subscriptionApi.undoChangeSubscriptionPlan(refreshedSubscription.getSubscriptionId(), NULL_PLUGIN_PROPERTIES, requestOptions);
callbackServlet.assertListenerStatus();
// MOVE AFTER TRIAL
callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_SUCCESS, ExtBusEventType.PAYMENT_SUCCESS);
clock.addDays(30);
callbackServlet.assertListenerStatus();
// Retrieves to check EndDate
refreshedSubscription = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
Assert.assertEquals(refreshedSubscription.getPrices().size(), 2);
Assert.assertEquals(refreshedSubscription.getPrices().get(0).getPhaseName(), "shotgun-monthly-trial");
Assert.assertEquals(refreshedSubscription.getPrices().get(0).getFixedPrice(), BigDecimal.ZERO);
Assert.assertNull(refreshedSubscription.getPrices().get(0).getRecurringPrice());
Assert.assertEquals(refreshedSubscription.getPrices().get(1).getPhaseName(), "shotgun-monthly-evergreen");
Assert.assertNull(refreshedSubscription.getPrices().get(1).getFixedPrice());
Assert.assertEquals(refreshedSubscription.getPrices().get(1).getRecurringPrice(), new BigDecimal("249.95"));
}
Aggregations