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;
}
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;
}
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;
}
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());
}
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);
}
Aggregations