use of org.killbill.billing.client.model.gen.Invoice 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);
}
use of org.killbill.billing.client.model.gen.Invoice in project killbill by killbill.
the class TestEntitlement method testEntitlementsWithAddOnsAndAlreadyExistingBP.
@Test(groups = "slow", description = "Create addOns in a bundle where BP subscription already exist")
public void testEntitlementsWithAddOnsAndAlreadyExistingBP() 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 Subscription input = new Subscription();
input.setAccountId(accountJson.getAccountId());
input.setBundleExternalKey("foobarxyz");
input.setProductName("Shotgun");
input.setProductCategory(ProductCategory.BASE);
input.setBillingPeriod(BillingPeriod.MONTHLY);
input.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
final Subscription subscription = subscriptionApi.createSubscription(input, null, null, null, null, null, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
final Subscription addOn1 = new Subscription();
addOn1.setAccountId(accountJson.getAccountId());
addOn1.setBundleId(subscription.getBundleId());
addOn1.setProductName("Telescopic-Scope");
addOn1.setProductCategory(ProductCategory.ADD_ON);
addOn1.setBillingPeriod(BillingPeriod.MONTHLY);
addOn1.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
final Subscription addOn2 = new Subscription();
addOn2.setAccountId(accountJson.getAccountId());
addOn2.setBundleId(subscription.getBundleId());
addOn2.setProductName("Laser-Scope");
addOn2.setProductCategory(ProductCategory.ADD_ON);
addOn2.setBillingPeriod(BillingPeriod.MONTHLY);
addOn2.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
final List<Subscription> subscriptions = new ArrayList<Subscription>();
subscriptions.add(addOn1);
subscriptions.add(addOn2);
final BulkSubscriptionsBundles bulkSubscriptionsBundles = new BulkSubscriptionsBundles();
final BulkSubscriptionsBundle bulkSubscriptionsBundle = new BulkSubscriptionsBundle();
bulkSubscriptionsBundle.setBaseEntitlementAndAddOns(subscriptions);
bulkSubscriptionsBundles.add(bulkSubscriptionsBundle);
final Bundles bundles = subscriptionApi.createSubscriptionsWithAddOns(bulkSubscriptionsBundles, null, null, false, false, null, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
assertNotNull(bundles);
assertEquals(bundles.size(), 1);
assertEquals(bundles.get(0).getSubscriptions().size(), 3);
final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
assertEquals(invoices.size(), 2);
}
use of org.killbill.billing.client.model.gen.Invoice in project killbill by killbill.
the class TestEntitlement method testCreateEntitlementsWithAddOnsThenCloseAccountWithItemAdjustment.
@Test(groups = "slow", description = "Create a bulk of base entitlement and addOns under the same transaction")
public void testCreateEntitlementsWithAddOnsThenCloseAccountWithItemAdjustment() throws Exception {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account accountJson = createAccount();
final Subscription base = new Subscription();
base.setAccountId(accountJson.getAccountId());
base.setProductName("Shotgun");
base.setProductCategory(ProductCategory.BASE);
base.setBillingPeriod(BillingPeriod.MONTHLY);
base.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
final Subscription addOn1 = new Subscription();
addOn1.setAccountId(accountJson.getAccountId());
addOn1.setProductName("Telescopic-Scope");
addOn1.setProductCategory(ProductCategory.ADD_ON);
addOn1.setBillingPeriod(BillingPeriod.MONTHLY);
addOn1.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
final Subscription addOn2 = new Subscription();
addOn2.setAccountId(accountJson.getAccountId());
addOn2.setProductName("Laser-Scope");
addOn2.setProductCategory(ProductCategory.ADD_ON);
addOn2.setBillingPeriod(BillingPeriod.MONTHLY);
addOn2.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
final List<Subscription> subscriptions = new ArrayList<Subscription>();
subscriptions.add(base);
subscriptions.add(addOn1);
subscriptions.add(addOn2);
final BulkSubscriptionsBundle bulkList = new BulkSubscriptionsBundle();
bulkList.setBaseEntitlementAndAddOns(subscriptions);
final BulkSubscriptionsBundles input = new BulkSubscriptionsBundles();
input.add(bulkList);
input.add(bulkList);
callbackServlet.pushExpectedEvents(ExtBusEventType.ACCOUNT_CHANGE, ExtBusEventType.ENTITLEMENT_CREATION, ExtBusEventType.ENTITLEMENT_CREATION, ExtBusEventType.ENTITLEMENT_CREATION, ExtBusEventType.ENTITLEMENT_CREATION, ExtBusEventType.ENTITLEMENT_CREATION, ExtBusEventType.ENTITLEMENT_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_FAILED);
final Bundles bundles = subscriptionApi.createSubscriptionsWithAddOns(input, null, null, false, false, null, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
callbackServlet.assertListenerStatus();
assertNotNull(bundles);
assertEquals(bundles.size(), 2);
assertFalse(bundles.get(0).getExternalKey().equals(bundles.get(1).getExternalKey()));
final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
assertEquals(invoices.size(), 1);
assertEquals(invoices.get(0).getBalance().compareTo(BigDecimal.ZERO), 1);
assertEquals(invoiceApi.getInvoiceTags(invoices.get(0).getInvoiceId(), requestOptions).size(), 0);
final Bundles accountBundles = accountApi.getAccountBundles(accountJson.getAccountId(), null, null, requestOptions);
assertEquals(accountBundles.size(), 2);
for (final Bundle bundle : accountBundles) {
for (final Subscription subscription : bundle.getSubscriptions()) {
assertEquals(subscription.getState(), EntitlementState.ACTIVE);
}
}
clock.addDays(1);
callbackServlet.assertListenerStatus();
callbackServlet.pushExpectedEvents(ExtBusEventType.TAG_CREATION, ExtBusEventType.ENTITLEMENT_CANCEL, ExtBusEventType.ENTITLEMENT_CANCEL, ExtBusEventType.ENTITLEMENT_CANCEL, ExtBusEventType.ENTITLEMENT_CANCEL, ExtBusEventType.ENTITLEMENT_CANCEL, ExtBusEventType.ENTITLEMENT_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.INVOICE_ADJUSTMENT, ExtBusEventType.INVOICE_ADJUSTMENT, ExtBusEventType.INVOICE_ADJUSTMENT, ExtBusEventType.INVOICE_ADJUSTMENT, ExtBusEventType.BLOCKING_STATE);
accountApi.closeAccount(accountJson.getAccountId(), true, false, true, true, requestOptions);
callbackServlet.assertListenerStatus();
final Bundles accountBundlesAfterClose = accountApi.getAccountBundles(accountJson.getAccountId(), null, null, requestOptions);
assertEquals(accountBundlesAfterClose.size(), 2);
for (final Bundle bundle : accountBundlesAfterClose) {
for (final Subscription subscription : bundle.getSubscriptions()) {
assertEquals(subscription.getState(), EntitlementState.CANCELLED);
}
}
final List<Invoice> invoicesAfterClose = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
assertEquals(invoicesAfterClose.size(), 1);
assertEquals(invoicesAfterClose.get(0).getBalance().compareTo(BigDecimal.ZERO), 0);
assertEquals(invoiceApi.getInvoiceTags(invoicesAfterClose.get(0).getInvoiceId(), requestOptions).size(), 0);
}
use of org.killbill.billing.client.model.gen.Invoice in project killbill by killbill.
the class TestEntitlement method testEntitlementWithAddOnsWithWRITTEN_OFF.
@Test(groups = "slow", description = "Create a base entitlement and also addOns entitlements under the same bundle")
public void testEntitlementWithAddOnsWithWRITTEN_OFF() throws Exception {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final String bundleExternalKey = "bundleKey12346542";
final Account accountJson = createAccount();
final Subscription base = new Subscription();
base.setAccountId(accountJson.getAccountId());
base.setBundleExternalKey(bundleExternalKey);
base.setExternalKey("Base");
base.setProductName("Shotgun");
base.setProductCategory(ProductCategory.BASE);
base.setBillingPeriod(BillingPeriod.MONTHLY);
base.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
final Subscription addOn1 = new Subscription();
addOn1.setAccountId(accountJson.getAccountId());
addOn1.setExternalKey("addOn1");
addOn1.setProductName("Telescopic-Scope");
addOn1.setProductCategory(ProductCategory.ADD_ON);
addOn1.setBillingPeriod(BillingPeriod.MONTHLY);
addOn1.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
final Subscription addOn2 = new Subscription();
addOn2.setAccountId(accountJson.getAccountId());
addOn2.setExternalKey("addOn2");
addOn2.setProductName("Laser-Scope");
addOn2.setProductCategory(ProductCategory.ADD_ON);
addOn2.setBillingPeriod(BillingPeriod.MONTHLY);
addOn2.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
final Subscriptions subscriptions = new Subscriptions();
subscriptions.add(base);
subscriptions.add(addOn1);
subscriptions.add(addOn2);
final Bundle bundle = subscriptionApi.createSubscriptionWithAddOns(subscriptions, null, null, null, null, null, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
assertNotNull(bundle);
assertEquals(bundle.getExternalKey(), bundleExternalKey);
assertEquals(bundle.getSubscriptions().size(), 3);
int found = 0;
for (int i = 0; i < 3; i++) {
final Subscription cur = bundle.getSubscriptions().get(i);
assertEquals(cur.getBundleExternalKey(), bundleExternalKey);
if ("Shotgun".equals(cur.getProductName())) {
assertEquals(cur.getExternalKey(), "Base");
found++;
} else if ("Telescopic-Scope".equals(cur.getProductName())) {
assertEquals(cur.getExternalKey(), "addOn1");
found++;
} else if ("Laser-Scope".equals(cur.getProductName())) {
assertEquals(cur.getExternalKey(), "addOn2");
found++;
}
}
assertEquals(found, 3);
final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
assertEquals(invoices.size(), 1);
assertEquals(invoices.get(0).getBalance().compareTo(BigDecimal.ZERO), 1);
assertEquals(invoiceApi.getInvoiceTags(invoices.get(0).getInvoiceId(), requestOptions).size(), 0);
final Bundles accountBundles = accountApi.getAccountBundles(accountJson.getAccountId(), null, null, requestOptions);
assertEquals(accountBundles.size(), 1);
for (final Subscription subscription : accountBundles.get(0).getSubscriptions()) {
assertEquals(subscription.getState(), EntitlementState.ACTIVE);
}
accountApi.closeAccount(accountJson.getAccountId(), true, true, false, true, requestOptions);
final Bundles accountBundlesAfterClose = accountApi.getAccountBundles(accountJson.getAccountId(), null, null, requestOptions);
assertEquals(accountBundlesAfterClose.size(), 1);
for (final Subscription subscription : accountBundlesAfterClose.get(0).getSubscriptions()) {
assertEquals(subscription.getState(), EntitlementState.CANCELLED);
}
final List<Invoice> invoicesAfterClose = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
assertEquals(invoicesAfterClose.size(), 1);
assertEquals(invoicesAfterClose.get(0).getBalance().compareTo(BigDecimal.ZERO), 0);
assertEquals(invoiceApi.getInvoiceTags(invoicesAfterClose.get(0).getInvoiceId(), requestOptions).size(), 1);
}
use of org.killbill.billing.client.model.gen.Invoice in project killbill by killbill.
the class TestInvoicePayment method testWithFailedInvoicePayment.
@Test(groups = "slow")
public void testWithFailedInvoicePayment() throws Exception {
mockPaymentProviderPlugin.makeNextPaymentFailWithError();
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(false);
InvoicePayments invoicePayments = accountApi.getInvoicePayments(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
assertEquals(invoicePayments.size(), 1);
final InvoicePayment invoicePayment = invoicePayments.get(0);
// Verify targetInvoiceId is not Null. See #593
assertNotNull(invoicePayment.getTargetInvoiceId());
// Verify targetInvoiceId is not null. See #1014
assertEquals(invoicePaymentApi.getInvoicePayment(invoicePayment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions).getTargetInvoiceId(), invoicePayment.getTargetInvoiceId());
final Invoices invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
assertEquals(invoices.size(), 2);
final Invoice invoice = invoices.get(1);
// Verify this is the correct value
assertEquals(invoicePayment.getTargetInvoiceId(), invoice.getInvoiceId());
// Make a payment and verify both invoice payment point to the same targetInvoiceId
final Invoices paidInvoices = accountApi.payAllInvoices(accountJson.getAccountId(), null, false, null, null, NULL_PLUGIN_PROPERTIES, requestOptions);
assertEquals(paidInvoices.size(), 1);
invoicePayments = accountApi.getInvoicePayments(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
assertEquals(invoicePayments.size(), 2);
for (final InvoicePayment cur : invoicePayments) {
assertEquals(cur.getTargetInvoiceId(), invoice.getInvoiceId());
}
}
Aggregations