Search in sources :

Example 11 with Account

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

the class TestBundle method testBundlesPagination.

@Test(groups = "slow", description = "Can paginate and search through all bundles")
public void testBundlesPagination() throws Exception {
    final Account accountJson = createAccount();
    for (int i = 0; i < 5; i++) {
        createSubscription(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
    }
    final Bundles allBundles = bundleApi.getBundles(requestOptions);
    Assert.assertEquals(allBundles.size(), 5);
    for (final Bundle bundle : allBundles) {
        Assert.assertEquals(bundleApi.searchBundles(bundle.getBundleId().toString(), requestOptions).size(), 1);
        Assert.assertEquals(bundleApi.searchBundles(bundle.getAccountId().toString(), requestOptions).size(), 5);
        Assert.assertEquals(bundleApi.searchBundles(bundle.getExternalKey(), requestOptions).size(), 1);
    }
    Bundles page = bundleApi.getBundles(0L, 1L, AuditLevel.NONE, requestOptions);
    for (int i = 0; i < 5; i++) {
        Assert.assertNotNull(page);
        Assert.assertEquals(page.size(), 1);
        Assert.assertEquals(page.get(0), allBundles.get(i));
        page = page.getNext();
    }
    Assert.assertNull(page);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Bundle(org.killbill.billing.client.model.gen.Bundle) Bundles(org.killbill.billing.client.model.Bundles) Test(org.testng.annotations.Test)

Example 12 with Account

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

the class TestBundle method testBundleNonExistent.

@Test(groups = "slow", description = "Can handle non existent bundle")
public void testBundleNonExistent() throws Exception {
    final Account accountJson = createAccount();
    // ID
    Assert.assertNull(bundleApi.getBundle(UUID.randomUUID(), requestOptions));
    // External Key
    Assert.assertTrue(bundleApi.getBundleByKey(UUID.randomUUID().toString(), requestOptions).isEmpty());
    Assert.assertTrue(bundleApi.getBundleByKey(UUID.randomUUID().toString(), requestOptions).isEmpty());
    // Account Id
    Assert.assertTrue(accountApi.getAccountBundles(accountJson.getAccountId(), "98374982743892", null, requestOptions).isEmpty());
    Assert.assertTrue(accountApi.getAccountBundles(accountJson.getAccountId(), null, null, requestOptions).isEmpty());
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Test(org.testng.annotations.Test)

Example 13 with Account

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

the class TestBundle method testBlockBundle.

@Test(groups = "slow", description = "Block a bundle")
public void testBlockBundle() 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 entitlement = createSubscription(accountJson.getAccountId(), bundleExternalKey, productName, ProductCategory.BASE, term);
    Bundles existingBundles = bundleApi.getBundleByKey(bundleExternalKey, requestOptions);
    assertEquals(existingBundles.size(), 1);
    final Bundle bundle = existingBundles.get(0);
    assertEquals(bundle.getAccountId(), accountJson.getAccountId());
    assertEquals(bundle.getExternalKey(), bundleExternalKey);
    final BlockingState blockingState = new BlockingState(bundle.getBundleId(), "block", "service", false, true, true, null, BlockingStateType.SUBSCRIPTION_BUNDLE, null);
    bundleApi.addBundleBlockingState(bundle.getBundleId(), blockingState, clock.getToday(DateTimeZone.forID(accountJson.getTimeZone())), ImmutableMap.<String, String>of(), requestOptions);
    final Subscription subscription = subscriptionApi.getSubscription(entitlement.getSubscriptionId(), requestOptions);
    assertEquals(subscription.getState(), EntitlementState.BLOCKED);
    clock.addDays(1);
    final BlockingState unblockingState = new BlockingState(bundle.getBundleId(), "unblock", "service", false, false, false, null, BlockingStateType.SUBSCRIPTION_BUNDLE, null);
    bundleApi.addBundleBlockingState(bundle.getBundleId(), unblockingState, clock.getToday(DateTimeZone.forID(accountJson.getTimeZone())), ImmutableMap.<String, String>of(), requestOptions);
    final Subscription subscription2 = subscriptionApi.getSubscription(entitlement.getSubscriptionId(), requestOptions);
    assertEquals(subscription2.getState(), EntitlementState.ACTIVE);
    final BlockingStates blockingStates = accountApi.getBlockingStates(accountJson.getAccountId(), null, ImmutableList.<String>of("service"), AuditLevel.FULL, requestOptions);
    Assert.assertEquals(blockingStates.size(), 2);
    final BlockingStates blockingStates2 = accountApi.getBlockingStates(accountJson.getAccountId(), ImmutableList.<BlockingStateType>of(BlockingStateType.SUBSCRIPTION_BUNDLE), null, AuditLevel.FULL, requestOptions);
    Assert.assertEquals(blockingStates2.size(), 2);
    final BlockingStates blockingStates3 = accountApi.getBlockingStates(accountJson.getAccountId(), null, null, AuditLevel.FULL, requestOptions);
    Assert.assertEquals(blockingStates3.size(), 3);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) BlockingStates(org.killbill.billing.client.model.BlockingStates) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) Bundle(org.killbill.billing.client.model.gen.Bundle) BlockingState(org.killbill.billing.client.model.gen.BlockingState) Subscription(org.killbill.billing.client.model.gen.Subscription) DateTime(org.joda.time.DateTime) Bundles(org.killbill.billing.client.model.Bundles) Test(org.testng.annotations.Test)

Example 14 with Account

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

Example 15 with Account

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

the class TestExceptions method testExceptionMapping.

@Test(groups = "slow", enabled = false)
public void testExceptionMapping() throws Exception {
    final Account account = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    final List<InvoicePayment> payments = accountApi.getInvoicePayments(account.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final InvoicePaymentTransaction input = new InvoicePaymentTransaction();
    input.setPaymentId(payments.get(0).getPaymentId());
    input.setAmount(BigDecimal.TEN.negate());
    try {
        invoicePaymentApi.createChargeback(payments.get(0).getPaymentId(), input, NULL_PLUGIN_PROPERTIES, requestOptions);
        fail();
    } catch (final KillBillClientException e) {
        Assert.assertEquals(e.getBillingException().getClassName(), InvoiceApiException.class.getName());
        Assert.assertEquals(e.getBillingException().getCode(), (Integer) ErrorCode.CHARGE_BACK_AMOUNT_IS_NEGATIVE.getCode());
        Assert.assertFalse(e.getBillingException().getStackTrace().isEmpty());
    }
}
Also used : Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) KillBillClientException(org.killbill.billing.client.KillBillClientException) 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