Search in sources :

Example 11 with Subscription

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

the class KillbillClient method createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice.

protected Account createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(final String productName, final boolean invoicePaymentSuccess, final boolean paymentSuccess) throws Exception {
    final Account accountJson = createAccountWithDefaultPaymentMethod();
    assertNotNull(accountJson);
    // Add a bundle, subscription and move the clock to get the first invoice
    final Subscription subscriptionJson = createSubscription(accountJson.getAccountId(), UUID.randomUUID().toString(), productName, ProductCategory.BASE, BillingPeriod.MONTHLY);
    assertNotNull(subscriptionJson);
    callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION);
    if (invoicePaymentSuccess) {
        callbackServlet.pushExpectedEvents(ExtBusEventType.INVOICE_PAYMENT_SUCCESS);
    } else {
        callbackServlet.pushExpectedEvents(ExtBusEventType.INVOICE_PAYMENT_FAILED);
    }
    if (paymentSuccess) {
        callbackServlet.pushExpectedEvents(ExtBusEventType.PAYMENT_SUCCESS);
    } else {
        callbackServlet.pushExpectedEvents(ExtBusEventType.PAYMENT_FAILED);
    }
    clock.addDays(32);
    callbackServlet.assertListenerStatus();
    return accountJson;
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Subscription(org.killbill.billing.client.model.gen.Subscription)

Example 12 with Subscription

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

the class KillbillClient method createAccountNoPMBundleAndSubscription.

protected Account createAccountNoPMBundleAndSubscription() throws Exception {
    // Create an account with no payment method
    final Account accountJson = createAccount();
    assertNotNull(accountJson);
    // Add a bundle, subscription and move the clock to get the first invoice
    final Subscription subscriptionJson = createSubscription(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
    assertNotNull(subscriptionJson);
    return accountJson;
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Subscription(org.killbill.billing.client.model.gen.Subscription)

Example 13 with Subscription

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

the class KillbillClient method createSubscription.

protected Subscription createSubscription(final UUID accountId, final String bundleExternalKey, final String productName, final ProductCategory productCategory, final BillingPeriod billingPeriod) throws Exception {
    final Account account = accountApi.getAccount(accountId, requestOptions);
    // ANNUAL subscriptions are SUBSCRIPTION aligned
    if (billingPeriod == BillingPeriod.MONTHLY && (account.getBillCycleDayLocal() == null || account.getBillCycleDayLocal() == 0)) {
        callbackServlet.pushExpectedEvent(ExtBusEventType.ACCOUNT_CHANGE);
    }
    callbackServlet.pushExpectedEvents(ExtBusEventType.ENTITLEMENT_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.INVOICE_CREATION);
    final String externalKey = UUID.randomUUID().toString();
    final Subscription input = new Subscription();
    input.setAccountId(accountId);
    input.setBundleExternalKey(bundleExternalKey);
    input.setExternalKey(externalKey);
    input.setProductName(productName);
    input.setProductCategory(productCategory);
    input.setBillingPeriod(billingPeriod);
    input.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final Subscription subscription = subscriptionApi.createSubscription(input, null, null, true, false, false, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
    callbackServlet.assertListenerStatus();
    assertEquals(subscription.getExternalKey(), externalKey);
    if (bundleExternalKey != null) {
        assertEquals(subscription.getBundleExternalKey(), bundleExternalKey);
    }
    return subscription;
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Subscription(org.killbill.billing.client.model.gen.Subscription)

Example 14 with Subscription

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

the class TestBundle method testCreateBundleWithNoExternalKey.

@Test(groups = "slow", description = "Can create bundles without an external key")
public void testCreateBundleWithNoExternalKey() throws Exception {
    final Account accountJson;
    accountJson = createAccount();
    final Subscription subscription = createSubscription(accountJson.getAccountId(), null, "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
    Assert.assertNotNull(subscription.getBundleExternalKey());
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Subscription(org.killbill.billing.client.model.gen.Subscription) Test(org.testng.annotations.Test)

Example 15 with Subscription

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

the class TestInvoicePayment method testManualInvoicePayment.

@Test(groups = "slow")
public void testManualInvoicePayment() throws Exception {
    final Account accountJson = createAccountWithDefaultPaymentMethod();
    assertNotNull(accountJson);
    // Disable automatic payments
    callbackServlet.pushExpectedEvent(ExtBusEventType.TAG_CREATION);
    accountApi.createAccountTags(accountJson.getAccountId(), ImmutableList.<UUID>of(ControlTagType.AUTO_PAY_OFF.getId()), requestOptions);
    callbackServlet.assertListenerStatus();
    // Add a bundle, subscription and move the clock to get the first invoice
    final Subscription subscriptionJson = createSubscription(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
    assertNotNull(subscriptionJson);
    callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION);
    clock.addDays(32);
    callbackServlet.assertListenerStatus();
    final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
    assertEquals(invoices.size(), 2);
    final InvoicePayment invoicePayment1 = new InvoicePayment();
    invoicePayment1.setPurchasedAmount(invoices.get(1).getBalance().add(BigDecimal.TEN));
    invoicePayment1.setAccountId(accountJson.getAccountId());
    invoicePayment1.setTargetInvoiceId(invoices.get(1).getInvoiceId());
    // Pay too too much => 400
    try {
        invoiceApi.createInstantPayment(invoicePayment1.getTargetInvoiceId(), invoicePayment1, ImmutableList.of(), NULL_PLUGIN_PROPERTIES, requestOptions);
        Assert.fail("InvoicePayment call should fail with 400");
    } catch (final KillBillClientException e) {
        assertTrue(true);
    }
    final InvoicePayment invoicePayment2 = new InvoicePayment();
    invoicePayment2.setPurchasedAmount(invoices.get(1).getBalance());
    invoicePayment2.setAccountId(accountJson.getAccountId());
    invoicePayment2.setTargetInvoiceId(invoices.get(1).getInvoiceId());
    // Just right, Yah! => 201
    final InvoicePayment result2 = invoiceApi.createInstantPayment(invoicePayment2.getTargetInvoiceId(), invoicePayment2, ImmutableList.of(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(result2.getTransactions().size(), 1);
    assertTrue(result2.getTransactions().get(0).getAmount().compareTo(invoices.get(1).getBalance()) == 0);
    // Already paid -> 204
    final InvoicePayment result3 = invoiceApi.createInstantPayment(invoicePayment2.getTargetInvoiceId(), invoicePayment2, ImmutableList.of(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertNull(result3);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Invoice(org.killbill.billing.client.model.gen.Invoice) KillBillClientException(org.killbill.billing.client.KillBillClientException) Subscription(org.killbill.billing.client.model.gen.Subscription) Test(org.testng.annotations.Test)

Aggregations

Subscription (org.killbill.billing.client.model.gen.Subscription)35 Account (org.killbill.billing.client.model.gen.Account)34 Test (org.testng.annotations.Test)29 DateTime (org.joda.time.DateTime)21 BigDecimal (java.math.BigDecimal)8 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)8 Bundles (org.killbill.billing.client.model.Bundles)7 UUID (java.util.UUID)6 Bundle (org.killbill.billing.client.model.gen.Bundle)6 Invoice (org.killbill.billing.client.model.gen.Invoice)6 LocalDate (org.joda.time.LocalDate)5 BulkSubscriptionsBundles (org.killbill.billing.client.model.BulkSubscriptionsBundles)5 Tags (org.killbill.billing.client.model.Tags)5 ArrayList (java.util.ArrayList)4 BulkSubscriptionsBundle (org.killbill.billing.client.model.gen.BulkSubscriptionsBundle)4 KillBillClientException (org.killbill.billing.client.KillBillClientException)3 Subscriptions (org.killbill.billing.client.model.Subscriptions)3 Predicate (com.google.common.base.Predicate)2 Invoices (org.killbill.billing.client.model.Invoices)2 SubscriptionUsageRecord (org.killbill.billing.client.model.gen.SubscriptionUsageRecord)2