Search in sources :

Example 36 with Account

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

the class TestInvoiceVoid method testChildVoidInvoice.

@Test(groups = "slow", description = "Void a child invoice")
public void testChildVoidInvoice() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    final LocalDate triggeredDate = new LocalDate(2012, 5, 26);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account parentAccount = createAccount();
    final Account childAccount1 = createAccount(parentAccount.getAccountId());
    // Add a bundle and subscription
    createSubscription(childAccount1.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
    // trigger an invoice generation
    callbackServlet.pushExpectedEvent(ExtBusEventType.INVOICE_CREATION);
    invoiceApi.createFutureInvoice(childAccount1.getAccountId(), triggeredDate, requestOptions);
    callbackServlet.assertListenerStatus();
    List<Invoice> child1Invoices = accountApi.getInvoicesForAccount(childAccount1.getAccountId(), null, null, false, false, true, null, AuditLevel.NONE, requestOptions);
    assertEquals(child1Invoices.size(), 2);
    // move one day so that the parent invoice is committed
    callbackServlet.pushExpectedEvents(ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_FAILED);
    clock.addDays(1);
    callbackServlet.assertListenerStatus();
    List<Invoice> parentInvoices = accountApi.getInvoicesForAccount(parentAccount.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
    assertEquals(parentInvoices.size(), 1);
    // try to void child invoice
    callbackServlet.pushExpectedEvent(ExtBusEventType.INVOICE_ADJUSTMENT);
    invoiceApi.voidInvoice(child1Invoices.get(1).getInvoiceId(), requestOptions);
    callbackServlet.assertListenerStatus();
    // move the clock 1 month to check if invoices change
    callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION, // Overdue state is computed from the parent state
    ExtBusEventType.OVERDUE_CHANGE, ExtBusEventType.BLOCKING_STATE, ExtBusEventType.OVERDUE_CHANGE, ExtBusEventType.BLOCKING_STATE);
    clock.addDays(31);
    callbackServlet.assertListenerStatus();
    // The parent added another invoice, now it has two (duplicate)
    parentInvoices = accountApi.getInvoicesForAccount(parentAccount.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
    assertEquals(parentInvoices.size(), 2);
    // the child added one invoice as expected
    child1Invoices = accountApi.getInvoicesForAccount(childAccount1.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
    assertEquals(child1Invoices.size(), 2);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Invoice(org.killbill.billing.client.model.gen.Invoice) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 37 with Account

use of org.killbill.billing.client.model.gen.Account 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)

Example 38 with Account

use of org.killbill.billing.client.model.gen.Account 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);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) Subscription(org.killbill.billing.client.model.gen.Subscription) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) BulkSubscriptionsBundles(org.killbill.billing.client.model.BulkSubscriptionsBundles) Bundles(org.killbill.billing.client.model.Bundles) Test(org.testng.annotations.Test)

Example 39 with Account

use of org.killbill.billing.client.model.gen.Account 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));
}
Also used : Account(org.killbill.billing.client.model.gen.Account) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) Subscription(org.killbill.billing.client.model.gen.Subscription) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 40 with Account

use of org.killbill.billing.client.model.gen.Account 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"));
}
Also used : Account(org.killbill.billing.client.model.gen.Account) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) Subscription(org.killbill.billing.client.model.gen.Subscription) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Interval(org.joda.time.Interval) Test(org.testng.annotations.Test)

Aggregations

Account (org.killbill.billing.client.model.gen.Account)153 Test (org.testng.annotations.Test)139 DateTime (org.joda.time.DateTime)43 UUID (java.util.UUID)38 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)37 Subscription (org.killbill.billing.client.model.gen.Subscription)34 Invoice (org.killbill.billing.client.model.gen.Invoice)33 BigDecimal (java.math.BigDecimal)29 Payment (org.killbill.billing.client.model.gen.Payment)28 PaymentTransaction (org.killbill.billing.client.model.gen.PaymentTransaction)21 KillBillClientException (org.killbill.billing.client.KillBillClientException)19 Invoices (org.killbill.billing.client.model.Invoices)19 ComboPaymentTransaction (org.killbill.billing.client.model.gen.ComboPaymentTransaction)19 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)19 LocalDate (org.joda.time.LocalDate)13 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)13 Tags (org.killbill.billing.client.model.Tags)13 PaymentMethod (org.killbill.billing.client.model.gen.PaymentMethod)12 InvoicePaymentTransaction (org.killbill.billing.client.model.gen.InvoicePaymentTransaction)11 Payments (org.killbill.billing.client.model.Payments)10