Search in sources :

Example 1 with PhasePriceOverride

use of org.killbill.billing.client.model.PhasePriceOverride 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.setExternalKey("identical");
    input.setProductName(productName);
    input.setProductCategory(ProductCategory.BASE);
    input.setBillingPeriod(BillingPeriod.MONTHLY);
    input.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final List<PhasePriceOverride> overrides = new ArrayList<PhasePriceOverride>();
    overrides.add(new PhasePriceOverride(null, null, PhaseType.TRIAL.toString(), BigDecimal.TEN, null));
    input.setPriceOverrides(overrides);
    final Subscription subscription = killBillClient.createSubscription(input, null, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, requestOptions);
    Assert.assertEquals(subscription.getPriceOverrides().size(), 2);
    Assert.assertEquals(subscription.getEvents().size(), 3);
    Assert.assertEquals(subscription.getEvents().get(0).getEventType(), SubscriptionEventType.START_ENTITLEMENT.name());
    Assert.assertEquals(subscription.getEvents().get(0).getPlan(), "shotgun-monthly-1");
    Assert.assertEquals(subscription.getEvents().get(0).getPhase(), "shotgun-monthly-1-trial");
    Assert.assertEquals(subscription.getEvents().get(0).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
    Assert.assertEquals(subscription.getEvents().get(0).getProduct(), "Shotgun");
    Assert.assertEquals(subscription.getEvents().get(1).getEventType(), SubscriptionEventType.START_BILLING.name());
    Assert.assertEquals(subscription.getEvents().get(1).getPlan(), "shotgun-monthly-1");
    Assert.assertEquals(subscription.getEvents().get(1).getPhase(), "shotgun-monthly-1-trial");
    Assert.assertEquals(subscription.getEvents().get(1).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
    Assert.assertEquals(subscription.getEvents().get(1).getProduct(), "Shotgun");
    Assert.assertEquals(subscription.getEvents().get(2).getEventType(), SubscriptionEventType.PHASE.name());
    Assert.assertEquals(subscription.getEvents().get(2).getPlan(), "shotgun-monthly-1");
    Assert.assertEquals(subscription.getEvents().get(2).getPhase(), "shotgun-monthly-1-evergreen");
    Assert.assertEquals(subscription.getEvents().get(2).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
    Assert.assertEquals(subscription.getEvents().get(2).getProduct(), "Shotgun");
    final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, false, false, AuditLevel.FULL, requestOptions);
    assertEquals(invoices.size(), 1);
    assertEquals(invoices.get(0).getAmount().compareTo(BigDecimal.TEN), 0);
    // Move clock after phase
    clock.addDays(30);
    crappyWaitForLackOfProperSynchonization();
    final Subscription subscription2 = killBillClient.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");
    final Subscription subscription3 = killBillClient.updateSubscription(newInput, null, BillingActionPolicy.IMMEDIATE, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, requestOptions);
    Assert.assertEquals(subscription3.getEvents().size(), 4);
    Assert.assertEquals(subscription3.getEvents().get(0).getEventType(), SubscriptionEventType.START_ENTITLEMENT.name());
    Assert.assertEquals(subscription3.getEvents().get(0).getPlan(), "shotgun-monthly-1");
    Assert.assertEquals(subscription3.getEvents().get(0).getPhase(), "shotgun-monthly-1-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.name());
    Assert.assertEquals(subscription3.getEvents().get(1).getPlan(), "shotgun-monthly-1");
    Assert.assertEquals(subscription3.getEvents().get(1).getPhase(), "shotgun-monthly-1-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.name());
    Assert.assertEquals(subscription3.getEvents().get(2).getPlan(), "shotgun-monthly-1");
    Assert.assertEquals(subscription3.getEvents().get(2).getPhase(), "shotgun-monthly-1-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.name());
    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.Account) Invoice(org.killbill.billing.client.model.Invoice) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) ArrayList(java.util.ArrayList) PhasePriceOverride(org.killbill.billing.client.model.PhasePriceOverride) Subscription(org.killbill.billing.client.model.Subscription) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

ArrayList (java.util.ArrayList)1 DateTime (org.joda.time.DateTime)1 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)1 Account (org.killbill.billing.client.model.Account)1 Invoice (org.killbill.billing.client.model.Invoice)1 PhasePriceOverride (org.killbill.billing.client.model.PhasePriceOverride)1 Subscription (org.killbill.billing.client.model.Subscription)1 Test (org.testng.annotations.Test)1