killbill-memoizeit
Changes
account/src/test/java/org/killbill/billing/account/api/user/TestDefaultAccountUserApi.java 73(+68 -5)
beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationParentInvoice.java 252(+247 -5)
Details
diff --git a/account/src/main/java/org/killbill/billing/account/api/DefaultAccount.java b/account/src/main/java/org/killbill/billing/account/api/DefaultAccount.java
index 8c452f1..ca107c9 100644
--- a/account/src/main/java/org/killbill/billing/account/api/DefaultAccount.java
+++ b/account/src/main/java/org/killbill/billing/account/api/DefaultAccount.java
@@ -1,7 +1,7 @@
/*
* Copyright 2010-2013 Ning, Inc.
- * Copyright 2014-2016 Groupon, Inc
- * Copyright 2014-2016 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -359,10 +359,6 @@ public class DefaultAccount extends EntityBase implements Account {
return new DefaultAccount(currentAccount.getId(), accountData);
}
- public ImmutableAccountData toImmutableAccountData() {
- return new DefaultImmutableAccountData(this);
- }
-
@Override
public DateTimeZone getFixedOffsetTimeZone() {
return AccountDateTimeUtils.getFixedOffsetTimeZone(this);
diff --git a/account/src/main/java/org/killbill/billing/account/api/DefaultImmutableAccountData.java b/account/src/main/java/org/killbill/billing/account/api/DefaultImmutableAccountData.java
index 4090248..3bd4afc 100644
--- a/account/src/main/java/org/killbill/billing/account/api/DefaultImmutableAccountData.java
+++ b/account/src/main/java/org/killbill/billing/account/api/DefaultImmutableAccountData.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2014-2016 Groupon, Inc
- * Copyright 2014-2016 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -30,26 +30,25 @@ public class DefaultImmutableAccountData implements ImmutableAccountData {
private final String externalKey;
private final Currency currency;
private final DateTimeZone dateTimeZone;
- private final UUID parentAccountId;
- private final boolean isPaymentDelegatedToParent;
private final DateTimeZone fixedOffsetDateTimeZone;
private final DateTime referenceTime;
- public DefaultImmutableAccountData(final UUID id, final String externalKey, final Currency currency, final DateTimeZone dateTimeZone, final DateTimeZone fixedOffsetDateTimeZone, final DateTime referenceTime, final UUID parentAccountId, final boolean isPaymentDelegatedToParent) {
+ public DefaultImmutableAccountData(final UUID id, final String externalKey, final Currency currency, final DateTimeZone dateTimeZone, final DateTimeZone fixedOffsetDateTimeZone, final DateTime referenceTime) {
this.id = id;
this.externalKey = externalKey;
this.currency = currency;
this.dateTimeZone = dateTimeZone;
this.fixedOffsetDateTimeZone = fixedOffsetDateTimeZone;
this.referenceTime = referenceTime;
- this.parentAccountId = parentAccountId;
- this.isPaymentDelegatedToParent = isPaymentDelegatedToParent;
}
public DefaultImmutableAccountData(final Account account) {
- this(account.getId(), account.getExternalKey(), account.getCurrency(), account.getTimeZone(),
- AccountDateTimeUtils.getFixedOffsetTimeZone(account), AccountDateTimeUtils.getReferenceDateTime(account),
- account.getParentAccountId(), account.isPaymentDelegatedToParent());
+ this(account.getId(),
+ account.getExternalKey(),
+ account.getCurrency(),
+ account.getTimeZone(),
+ AccountDateTimeUtils.getFixedOffsetTimeZone(account),
+ AccountDateTimeUtils.getReferenceDateTime(account));
}
@Override
@@ -73,13 +72,17 @@ public class DefaultImmutableAccountData implements ImmutableAccountData {
}
@Override
+ @Deprecated
public UUID getParentAccountId() {
- return parentAccountId;
+ // Should only be used internally by ImmutableAccountInternalApi
+ throw new UnsupportedOperationException("WILL BE REMOVED IN 0.20.0");
}
@Override
+ @Deprecated
public Boolean isPaymentDelegatedToParent() {
- return isPaymentDelegatedToParent;
+ // Should only be used internally by ImmutableAccountInternalApi
+ throw new UnsupportedOperationException("WILL BE REMOVED IN 0.20.0");
}
public DateTimeZone getFixedOffsetTimeZone() {
diff --git a/account/src/main/resources/org/killbill/billing/account/dao/AccountSqlDao.sql.stg b/account/src/main/resources/org/killbill/billing/account/dao/AccountSqlDao.sql.stg
index f9ddfa5..937b12f 100644
--- a/account/src/main/resources/org/killbill/billing/account/dao/AccountSqlDao.sql.stg
+++ b/account/src/main/resources/org/killbill/billing/account/dao/AccountSqlDao.sql.stg
@@ -67,14 +67,32 @@ accountRecordIdFieldWithComma(prefix) ::= ""
accountRecordIdValueWithComma(prefix) ::= ""
update() ::= <<
- UPDATE accounts
- SET email = :email, name = :name, first_name_length = :firstNameLength,
- currency = :currency, billing_cycle_day_local = :billingCycleDayLocal,
- payment_method_id = :paymentMethodId, time_zone = :timeZone, locale = :locale,
- address1 = :address1, address2 = :address2, company_name = :companyName, city = :city, state_or_province = :stateOrProvince,
- country = :country, postal_code = :postalCode, phone = :phone, notes = :notes,
- is_notified_for_invoices = :isNotifiedForInvoices, updated_date = :updatedDate, updated_by = :updatedBy
- WHERE id = :id <AND_CHECK_TENANT()>;
+update accounts set
+ email = :email
+, name = :name
+, first_name_length = :firstNameLength
+, currency = :currency
+, billing_cycle_day_local = :billingCycleDayLocal
+, parent_account_id = :parentAccountId
+, is_payment_delegated_to_parent = :isPaymentDelegatedToParent
+, payment_method_id = :paymentMethodId
+, time_zone = :timeZone
+, locale = :locale
+, address1 = :address1
+, address2 = :address2
+, company_name = :companyName
+, city = :city
+, state_or_province = :stateOrProvince
+, country = :country
+, postal_code = :postalCode
+, phone = :phone
+, notes = :notes
+, is_notified_for_invoices = :isNotifiedForInvoices
+, updated_date = :updatedDate
+, updated_by = :updatedBy
+where id = :id
+<AND_CHECK_TENANT()>
+;
>>
diff --git a/account/src/test/java/org/killbill/billing/account/api/user/TestDefaultAccountUserApi.java b/account/src/test/java/org/killbill/billing/account/api/user/TestDefaultAccountUserApi.java
index 3fa19fc..0a0d2ac 100644
--- a/account/src/test/java/org/killbill/billing/account/api/user/TestDefaultAccountUserApi.java
+++ b/account/src/test/java/org/killbill/billing/account/api/user/TestDefaultAccountUserApi.java
@@ -1,7 +1,7 @@
/*
* Copyright 2010-2013 Ning, Inc.
- * Copyright 2014-2015 Groupon, Inc
- * Copyright 2014-2015 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -20,10 +20,8 @@ package org.killbill.billing.account.api.user;
import java.util.LinkedList;
import java.util.List;
-import java.util.TimeZone;
import java.util.UUID;
import java.util.concurrent.Callable;
-import java.util.spi.TimeZoneNameProvider;
import org.joda.time.DateTimeZone;
import org.killbill.billing.ErrorCode;
@@ -356,8 +354,73 @@ public class TestDefaultAccountUserApi extends AccountTestSuiteWithEmbeddedDB {
}
+ @Test(groups = "slow", description = "Test un- and re-parenting")
+ public void testUnAndReParenting() throws Exception {
+ // Create child1
+ final AccountModelDao childAccountModelDao1 = createTestAccount();
+ Account childAccount1 = accountUserApi.createAccount(new DefaultAccount(childAccountModelDao1), callContext);
+ Assert.assertNull(childAccount1.getParentAccountId());
+ Assert.assertFalse(childAccount1.isPaymentDelegatedToParent());
+
+ // Create parent
+ final Account parentAccount = accountUserApi.createAccount(new DefaultAccount(createTestAccount()), callContext);
+ Assert.assertNull(parentAccount.getParentAccountId());
+ Assert.assertFalse(parentAccount.isPaymentDelegatedToParent());
+ List<Account> childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext);
+ Assert.assertEquals(childrenAccounts.size(), 0);
+
+ // Associate child1 to parent
+ childAccountModelDao1.setId(childAccount1.getId());
+ childAccountModelDao1.setParentAccountId(parentAccount.getId());
+ childAccountModelDao1.setIsPaymentDelegatedToParent(true);
+ accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao1), callContext);
+
+ // Verify mapping
+ childAccount1 = accountUserApi.getAccountById(childAccount1.getId(), callContext);
+ Assert.assertEquals(childAccount1.getParentAccountId(), parentAccount.getId());
+ Assert.assertTrue(childAccount1.isPaymentDelegatedToParent());
+ childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext);
+ Assert.assertEquals(childrenAccounts.size(), 1);
+ Assert.assertEquals(childrenAccounts.get(0).getId(), childAccount1.getId());
+
+ // Un-parent child1 from parent
+ childAccountModelDao1.setParentAccountId(null);
+ childAccountModelDao1.setIsPaymentDelegatedToParent(false);
+ accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao1), callContext);
+
+ // Verify mapping
+ childAccount1 = accountUserApi.getAccountById(childAccount1.getId(), callContext);
+ Assert.assertNull(childAccount1.getParentAccountId());
+ Assert.assertFalse(childAccount1.isPaymentDelegatedToParent());
+ childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext);
+ Assert.assertEquals(childrenAccounts.size(), 0);
+
+ // Create child2
+ final AccountModelDao childAccountModelDao2 = createTestAccount();
+ Account childAccount2 = accountUserApi.createAccount(new DefaultAccount(childAccountModelDao2), callContext);
+ Assert.assertNull(childAccount2.getParentAccountId());
+ Assert.assertFalse(childAccount2.isPaymentDelegatedToParent());
+
+ // Associate child2 to parent
+ childAccountModelDao2.setId(childAccount2.getId());
+ childAccountModelDao2.setParentAccountId(parentAccount.getId());
+ childAccountModelDao2.setIsPaymentDelegatedToParent(true);
+ accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao2), callContext);
+
+ // Verify mapping
+ childAccount1 = accountUserApi.getAccountById(childAccount1.getId(), callContext);
+ Assert.assertNull(childAccount1.getParentAccountId());
+ Assert.assertFalse(childAccount1.isPaymentDelegatedToParent());
+ childAccount2 = accountUserApi.getAccountById(childAccount2.getId(), callContext);
+ Assert.assertEquals(childAccount2.getParentAccountId(), parentAccount.getId());
+ Assert.assertTrue(childAccount2.isPaymentDelegatedToParent());
+ childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext);
+ Assert.assertEquals(childrenAccounts.size(), 1);
+ Assert.assertEquals(childrenAccounts.get(0).getId(), childAccount2.getId());
+ }
+
@Test(groups = "slow", description = "Test Account creation with External Key over limit")
- public void testCreateAccountWithExternalKeyOverLimit() throws Exception {
+ public void testCreateAccountWithExternalKeyOverLimit() throws Exception {
AccountModelDao accountModelDao = createTestAccount();
// Set an externalKey of 256 characters (over limit)
accountModelDao.setExternalKey("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis,.");
diff --git a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationBase.java b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationBase.java
index 5ed3690..f32d4bf 100644
--- a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationBase.java
+++ b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationBase.java
@@ -1,7 +1,7 @@
/*
* Copyright 2010-2013 Ning, Inc.
- * Copyright 2014-2016 Groupon, Inc
- * Copyright 2014-2016 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -114,6 +114,7 @@ import org.killbill.billing.util.api.TagDefinitionApiException;
import org.killbill.billing.util.api.TagUserApi;
import org.killbill.billing.util.cache.CacheControllerDispatcher;
import org.killbill.billing.util.config.definition.InvoiceConfig;
+import org.killbill.billing.util.config.definition.PaymentConfig;
import org.killbill.billing.util.dao.NonEntityDao;
import org.killbill.billing.util.nodes.KillbillNodesApi;
import org.killbill.billing.util.tag.ControlTagType;
@@ -291,6 +292,9 @@ public class TestIntegrationBase extends BeatrixTestSuiteWithEmbeddedDB {
@Inject
protected ParkedAccountsManager parkedAccountsManager;
+ @Inject
+ protected PaymentConfig paymentConfig;
+
protected ConfigurableInvoiceConfig invoiceConfig;
protected void assertListenerStatus() {
diff --git a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationParentInvoice.java b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationParentInvoice.java
index e759270..1cf0586 100644
--- a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationParentInvoice.java
+++ b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationParentInvoice.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2014-2016 Groupon, Inc
- * Copyright 2014-2016 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -23,6 +23,8 @@ import java.util.List;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.killbill.billing.account.api.Account;
+import org.killbill.billing.account.api.DefaultAccount;
+import org.killbill.billing.account.dao.AccountModelDao;
import org.killbill.billing.api.TestApiListener.NextEvent;
import org.killbill.billing.catalog.api.BillingActionPolicy;
import org.killbill.billing.catalog.api.BillingPeriod;
@@ -36,15 +38,18 @@ import org.killbill.billing.invoice.api.InvoiceItem;
import org.killbill.billing.invoice.api.InvoiceItemType;
import org.killbill.billing.invoice.api.InvoiceStatus;
import org.killbill.billing.payment.api.Payment;
+import org.killbill.billing.payment.api.PluginProperty;
import org.testng.annotations.Test;
+import com.google.common.collect.ImmutableList;
+
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
public class TestIntegrationParentInvoice extends TestIntegrationBase {
-
-
@Test(groups = "slow")
public void testParentInvoiceGeneration() throws Exception {
@@ -584,7 +589,7 @@ public class TestIntegrationParentInvoice extends TestIntegrationBase {
final List<Invoice> parentInvoices = invoiceUserApi.getInvoicesByAccount(parentAccount.getId(), false, callContext);
final List<Invoice> childInvoices = invoiceUserApi.getInvoicesByAccount(childAccount.getId(), false, callContext);
-
+
// get last child invoice
Invoice childInvoice = childInvoices.get(1);
assertEquals(childInvoice.getNumberOfItems(), 1);
@@ -1032,4 +1037,241 @@ public class TestIntegrationParentInvoice extends TestIntegrationBase {
}
+ @Test(groups = "slow")
+ public void testUnParentingWithUnpaidInvoice() throws Exception {
+ final int billingDay = 14;
+ final DateTime initialCreationDate = new DateTime(2015, 5, 15, 0, 0, 0, 0, testTimeZone);
+ // set clock to the initial start date
+ clock.setTime(initialCreationDate);
+
+ final Account parentAccount = createAccountWithNonOsgiPaymentMethod(getAccountData(billingDay));
+ Account childAccount = createAccountWithNonOsgiPaymentMethod(getChildAccountData(billingDay, parentAccount.getId(), true));
+
+ // Verify mapping
+ childAccount = accountUserApi.getAccountById(childAccount.getId(), callContext);
+ assertEquals(childAccount.getParentAccountId(), parentAccount.getId());
+ assertTrue(childAccount.isPaymentDelegatedToParent());
+ List<Account> childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext);
+ assertEquals(childrenAccounts.size(), 1);
+ assertEquals(childrenAccounts.get(0).getId(), childAccount.getId());
+
+ // Create subscription
+ createBaseEntitlementAndCheckForCompletion(childAccount.getId(), "bundleKey1", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
+
+ // Moving a day the NotificationQ calls the commitInvoice. No payment is expected
+ busHandler.pushExpectedEvents(NextEvent.INVOICE);
+ clock.addDays(1);
+ assertListenerStatus();
+
+ // First Parent invoice over TRIAL period
+ List<Invoice> parentInvoices = invoiceUserApi.getInvoicesByAccount(parentAccount.getId(), false, callContext);
+ assertEquals(parentInvoices.size(), 1);
+ Invoice parentInvoice = parentInvoices.get(0);
+ assertEquals(parentInvoice.getNumberOfItems(), 1);
+ assertEquals(parentInvoice.getStatus(), InvoiceStatus.COMMITTED);
+ assertTrue(parentInvoice.isParentInvoice());
+ assertEquals(parentInvoice.getBalance().compareTo(BigDecimal.ZERO), 0);
+
+ // First child invoice over TRIAL period
+ List<Invoice> childInvoices = invoiceUserApi.getInvoicesByAccount(childAccount.getId(), false, callContext);
+ assertEquals(childInvoices.size(), 1);
+ assertEquals(childInvoices.get(0).getBalance().compareTo(BigDecimal.ZERO), 0);
+
+ busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE);
+ clock.addDays(29);
+ assertListenerStatus();
+
+ paymentPlugin.makeNextPaymentFailWithError();
+
+ busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT_ERROR, NextEvent.INVOICE_PAYMENT_ERROR);
+ clock.addDays(1);
+ assertListenerStatus();
+
+ // Second Parent invoice over Recurring period
+ parentInvoices = invoiceUserApi.getInvoicesByAccount(parentAccount.getId(), false, callContext);
+ assertEquals(parentInvoices.size(), 2);
+ parentInvoice = parentInvoices.get(1);
+ assertEquals(parentInvoice.getNumberOfItems(), 1);
+ assertEquals(parentInvoice.getStatus(), InvoiceStatus.COMMITTED);
+ assertTrue(parentInvoice.isParentInvoice());
+ assertEquals(parentInvoice.getBalance().compareTo(new BigDecimal("249.95")), 0);
+ // The parent has attempted to pay the child invoice
+ assertEquals(parentInvoice.getPayments().size(), 1);
+ assertEquals(paymentApi.getPayment(parentInvoice.getPayments().get(0).getPaymentId(), false, false, ImmutableList.<PluginProperty>of(), callContext).getPaymentMethodId(),
+ parentAccount.getPaymentMethodId());
+
+ // Second child invoice over Recurring period
+ childInvoices = invoiceUserApi.getInvoicesByAccount(childAccount.getId(), false, callContext);
+ assertEquals(childInvoices.size(), 2);
+ assertEquals(childInvoices.get(1).getBalance().compareTo(new BigDecimal("249.95")), 0);
+
+ // Verify balances
+ assertEquals(invoiceUserApi.getAccountBalance(parentAccount.getId(), callContext).compareTo(new BigDecimal("249.95")), 0);
+ assertEquals(invoiceUserApi.getAccountBalance(childAccount.getId(), callContext).compareTo(new BigDecimal("249.95")), 0);
+
+ // Un-parent the child
+ final AccountModelDao childAccountModelDao = new AccountModelDao(childAccount.getId(), childAccount);
+ childAccountModelDao.setParentAccountId(null);
+ childAccountModelDao.setIsPaymentDelegatedToParent(false);
+ accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao), callContext);
+
+ // Verify mapping
+ childAccount = accountUserApi.getAccountById(childAccount.getId(), callContext);
+ assertNull(childAccount.getParentAccountId());
+ assertFalse(childAccount.isPaymentDelegatedToParent());
+ childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext);
+ assertEquals(childrenAccounts.size(), 0);
+
+ // Verify balances
+ // TODO Should we automatically adjust the invoice at the parent level or should it be the responsibility of the user?
+ assertEquals(invoiceUserApi.getAccountBalance(parentAccount.getId(), callContext).compareTo(new BigDecimal("249.95")), 0);
+ assertEquals(invoiceUserApi.getAccountBalance(childAccount.getId(), callContext).compareTo(new BigDecimal("249.95")), 0);
+
+ final int nbDaysBeforeRetry = paymentConfig.getPaymentFailureRetryDays(internalCallContext).get(0);
+
+ // Move time for retry to happen
+ busHandler.pushExpectedEvents(NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
+ clock.addDays(nbDaysBeforeRetry + 1);
+ assertListenerStatus();
+
+ // Second Parent invoice over Recurring period
+ parentInvoices = invoiceUserApi.getInvoicesByAccount(parentAccount.getId(), false, callContext);
+ // Note that the parent still owns both invoices
+ assertEquals(parentInvoices.size(), 2);
+ parentInvoice = parentInvoices.get(1);
+ assertEquals(parentInvoice.getNumberOfItems(), 1);
+ assertEquals(parentInvoice.getStatus(), InvoiceStatus.COMMITTED);
+ assertTrue(parentInvoice.isParentInvoice());
+ assertEquals(parentInvoice.getBalance().compareTo(BigDecimal.ZERO), 0);
+ // Even if the child-parent mapping has been removed, the parent has retried and successfully paid the summary invoice
+ // TODO Should we automatically disable payment retries when un-parenting?
+ assertEquals(parentInvoice.getPayments().size(), 1);
+ assertEquals(paymentApi.getPayment(parentInvoice.getPayments().get(0).getPaymentId(), false, false, ImmutableList.<PluginProperty>of(), callContext).getPaymentMethodId(),
+ parentAccount.getPaymentMethodId());
+
+ // Second child invoice over Recurring period
+ childInvoices = invoiceUserApi.getInvoicesByAccount(childAccount.getId(), false, callContext);
+ assertEquals(childInvoices.size(), 2);
+ assertEquals(childInvoices.get(1).getBalance().compareTo(BigDecimal.ZERO), 0);
+
+ // Verify balances (the parent has paid the summary invoice, so the child invoice is automatically paid)
+ assertEquals(invoiceUserApi.getAccountBalance(parentAccount.getId(), callContext).compareTo(BigDecimal.ZERO), 0);
+ assertEquals(invoiceUserApi.getAccountBalance(childAccount.getId(), callContext).compareTo(BigDecimal.ZERO), 0);
+
+ busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
+ clock.addDays(29 - nbDaysBeforeRetry - 1);
+ assertListenerStatus();
+
+ // No new invoice for the parent
+ parentInvoices = invoiceUserApi.getInvoicesByAccount(parentAccount.getId(), false, callContext);
+ assertEquals(parentInvoices.size(), 2);
+
+ // Third child invoice over second Recurring period
+ childInvoices = invoiceUserApi.getInvoicesByAccount(childAccount.getId(), false, callContext);
+ assertEquals(childInvoices.size(), 3);
+ assertEquals(childInvoices.get(2).getBalance().compareTo(BigDecimal.ZERO), 0);
+ // Verify the child paid the invoice this time
+ assertEquals(childInvoices.get(2).getPayments().size(), 1);
+ assertEquals(paymentApi.getPayment(childInvoices.get(2).getPayments().get(0).getPaymentId(), false, false, ImmutableList.<PluginProperty>of(), callContext).getPaymentMethodId(),
+ childAccount.getPaymentMethodId());
+
+ // Verify balances
+ assertEquals(invoiceUserApi.getAccountBalance(parentAccount.getId(), callContext).compareTo(BigDecimal.ZERO), 0);
+ assertEquals(invoiceUserApi.getAccountBalance(childAccount.getId(), callContext).compareTo(BigDecimal.ZERO), 0);
+ }
+
+ @Test(groups = "slow")
+ public void testParentingWithFuturePhaseEvent() throws Exception {
+ final int billingDay = 14;
+ final DateTime initialCreationDate = new DateTime(2015, 5, 15, 0, 0, 0, 0, testTimeZone);
+ // set clock to the initial start date
+ clock.setTime(initialCreationDate);
+
+ final Account parentAccount = createAccountWithNonOsgiPaymentMethod(getAccountData(billingDay));
+ Account childAccount = createAccountWithNonOsgiPaymentMethod(getAccountData(billingDay));
+
+ // Verify mapping
+ childAccount = accountUserApi.getAccountById(childAccount.getId(), callContext);
+ assertNull(childAccount.getParentAccountId());
+ assertFalse(childAccount.isPaymentDelegatedToParent());
+ List<Account> childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext);
+ assertEquals(childrenAccounts.size(), 0);
+
+ // Create subscription
+ createBaseEntitlementAndCheckForCompletion(childAccount.getId(), "bundleKey1", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
+
+ // First child invoice over TRIAL period
+ List<Invoice> childInvoices = invoiceUserApi.getInvoicesByAccount(childAccount.getId(), false, callContext);
+ assertEquals(childInvoices.size(), 1);
+ assertEquals(childInvoices.get(0).getBalance().compareTo(BigDecimal.ZERO), 0);
+
+ // Add parent to the child -- the child still pays its invoices though
+ AccountModelDao childAccountModelDao = new AccountModelDao(childAccount.getId(), childAccount);
+ childAccountModelDao.setParentAccountId(parentAccount.getId());
+ childAccountModelDao.setIsPaymentDelegatedToParent(false);
+ accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao), callContext);
+
+ // Verify mapping
+ childAccount = accountUserApi.getAccountById(childAccount.getId(), callContext);
+ assertEquals(childAccount.getParentAccountId(), parentAccount.getId());
+ assertFalse(childAccount.isPaymentDelegatedToParent());
+ childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext);
+ assertEquals(childrenAccounts.size(), 1);
+ assertEquals(childrenAccounts.get(0).getId(), childAccount.getId());
+
+ busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
+ clock.addDays(30);
+ assertListenerStatus();
+
+ // The parent still has no invoice
+ List<Invoice> parentInvoices = invoiceUserApi.getInvoicesByAccount(parentAccount.getId(), false, callContext);
+ assertEquals(parentInvoices.size(), 0);
+
+ // Second child invoice over Recurring period
+ childInvoices = invoiceUserApi.getInvoicesByAccount(childAccount.getId(), false, callContext);
+ assertEquals(childInvoices.size(), 2);
+ assertEquals(childInvoices.get(1).getBalance().compareTo(BigDecimal.ZERO), 0);
+ assertEquals(childInvoices.get(1).getPayments().size(), 1);
+ assertEquals(paymentApi.getPayment(childInvoices.get(1).getPayments().get(0).getPaymentId(), false, false, ImmutableList.<PluginProperty>of(), callContext).getPaymentMethodId(),
+ childAccount.getPaymentMethodId());
+
+ // The child now delegates its payments
+ childAccountModelDao = new AccountModelDao(childAccount.getId(), childAccount);
+ childAccountModelDao.setIsPaymentDelegatedToParent(true);
+ accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao), callContext);
+
+ // Verify mapping
+ childAccount = accountUserApi.getAccountById(childAccount.getId(), callContext);
+ assertEquals(childAccount.getParentAccountId(), parentAccount.getId());
+ assertTrue(childAccount.isPaymentDelegatedToParent());
+ childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext);
+ assertEquals(childrenAccounts.size(), 1);
+ assertEquals(childrenAccounts.get(0).getId(), childAccount.getId());
+
+ busHandler.pushExpectedEvents(NextEvent.INVOICE);
+ clock.addDays(30);
+ assertListenerStatus();
+
+ // Moving a day the NotificationQ calls the commitInvoice. No payment is expected
+ busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
+ clock.addDays(1);
+ assertListenerStatus();
+
+ // The parent now owns the invoice
+ parentInvoices = invoiceUserApi.getInvoicesByAccount(parentAccount.getId(), false, callContext);
+ assertEquals(parentInvoices.size(), 1);
+ final Invoice parentInvoice = parentInvoices.get(0);
+ assertEquals(parentInvoice.getNumberOfItems(), 1);
+ assertEquals(parentInvoice.getStatus(), InvoiceStatus.COMMITTED);
+ assertTrue(parentInvoice.isParentInvoice());
+ assertEquals(parentInvoice.getBalance().compareTo(BigDecimal.ZERO), 0);
+ assertEquals(parentInvoice.getPayments().size(), 1);
+ assertEquals(paymentApi.getPayment(parentInvoice.getPayments().get(0).getPaymentId(), false, false, ImmutableList.<PluginProperty>of(), callContext).getPaymentMethodId(),
+ parentAccount.getPaymentMethodId());
+
+ // Third child invoice over Recurring period
+ childInvoices = invoiceUserApi.getInvoicesByAccount(childAccount.getId(), false, callContext);
+ assertEquals(childInvoices.size(), 3);
+ assertEquals(childInvoices.get(2).getBalance().compareTo(BigDecimal.ZERO), 0);
+ }
}
diff --git a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationWithAutoPayOff.java b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationWithAutoPayOff.java
index 4d911f6..afad9a3 100644
--- a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationWithAutoPayOff.java
+++ b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationWithAutoPayOff.java
@@ -1,7 +1,7 @@
/*
* Copyright 2010-2013 Ning, Inc.
- * Copyright 2014-2016 Groupon, Inc
- * Copyright 2014-2016 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -44,9 +44,6 @@ import static org.testng.Assert.assertTrue;
public class TestIntegrationWithAutoPayOff extends TestIntegrationBase {
- @Inject
- private PaymentConfig paymentConfig;
-
private Account account;
private SubscriptionBaseBundle bundle;
private String productName;
diff --git a/invoice/src/main/java/org/killbill/billing/invoice/InvoiceDispatcher.java b/invoice/src/main/java/org/killbill/billing/invoice/InvoiceDispatcher.java
index a338da9..2d28f08 100644
--- a/invoice/src/main/java/org/killbill/billing/invoice/InvoiceDispatcher.java
+++ b/invoice/src/main/java/org/killbill/billing/invoice/InvoiceDispatcher.java
@@ -1,7 +1,7 @@
/*
* Copyright 2010-2013 Ning, Inc.
- * Copyright 2014-2016 Groupon, Inc
- * Copyright 2014-2016 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -39,6 +39,7 @@ import org.killbill.billing.ErrorCode;
import org.killbill.billing.ObjectType;
import org.killbill.billing.account.api.Account;
import org.killbill.billing.account.api.AccountApiException;
+import org.killbill.billing.account.api.AccountData;
import org.killbill.billing.account.api.AccountInternalApi;
import org.killbill.billing.account.api.ImmutableAccountData;
import org.killbill.billing.callcontext.InternalCallContext;
@@ -770,7 +771,7 @@ public class InvoiceDispatcher {
}
}
- public void processParentInvoiceForInvoiceGeneration(final ImmutableAccountData account, final UUID childInvoiceId, final InternalCallContext context) throws InvoiceApiException {
+ public void processParentInvoiceForInvoiceGeneration(final Account account, final UUID childInvoiceId, final InternalCallContext context) throws InvoiceApiException {
final InvoiceModelDao childInvoiceModelDao = invoiceDao.getById(childInvoiceId, context);
final Invoice childInvoice = new DefaultInvoice(childInvoiceModelDao);
@@ -839,7 +840,7 @@ public class InvoiceDispatcher {
return true;
}
- public void processParentInvoiceForAdjustments(final ImmutableAccountData account, final UUID childInvoiceId, final InternalCallContext context) throws InvoiceApiException {
+ public void processParentInvoiceForAdjustments(final AccountData account, final UUID childInvoiceId, final InternalCallContext context) throws InvoiceApiException {
final InvoiceModelDao childInvoiceModelDao = invoiceDao.getById(childInvoiceId, context);
final InvoiceModelDao parentInvoiceModelDao = childInvoiceModelDao.getParentInvoice();
diff --git a/invoice/src/main/java/org/killbill/billing/invoice/InvoiceListener.java b/invoice/src/main/java/org/killbill/billing/invoice/InvoiceListener.java
index 4f20b6d..49824f4 100644
--- a/invoice/src/main/java/org/killbill/billing/invoice/InvoiceListener.java
+++ b/invoice/src/main/java/org/killbill/billing/invoice/InvoiceListener.java
@@ -1,7 +1,7 @@
/*
* Copyright 2010-2013 Ning, Inc.
- * Copyright 2014-2016 Groupon, Inc
- * Copyright 2014-2016 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -21,9 +21,9 @@ package org.killbill.billing.invoice;
import java.util.UUID;
import org.joda.time.DateTime;
+import org.killbill.billing.account.api.Account;
import org.killbill.billing.account.api.AccountApiException;
import org.killbill.billing.account.api.AccountInternalApi;
-import org.killbill.billing.account.api.ImmutableAccountData;
import org.killbill.billing.callcontext.InternalCallContext;
import org.killbill.billing.events.BlockingTransitionInternalEvent;
import org.killbill.billing.events.EffectiveSubscriptionInternalEvent;
@@ -127,8 +127,7 @@ public class InvoiceListener {
try {
final InternalCallContext context = internalCallContextFactory.createInternalCallContext(event.getSearchKey2(), event.getSearchKey1(), "CreateParentInvoice", CallOrigin.INTERNAL, UserType.SYSTEM, event.getUserToken());
- // TODO it may change to Account - #459
- final ImmutableAccountData account = accountApi.getImmutableAccountDataById(event.getAccountId(), context);
+ final Account account = accountApi.getAccountById(event.getAccountId(), context);
// catch children invoices and populate the parent summary invoice
if (isChildrenAccountAndPaymentDelegated(account)) {
@@ -142,7 +141,7 @@ public class InvoiceListener {
}
}
- private boolean isChildrenAccountAndPaymentDelegated(final ImmutableAccountData account) {
+ private boolean isChildrenAccountAndPaymentDelegated(final Account account) {
return account.getParentAccountId() != null && account.isPaymentDelegatedToParent();
}
@@ -161,8 +160,7 @@ public class InvoiceListener {
try {
final InternalCallContext context = internalCallContextFactory.createInternalCallContext(event.getSearchKey2(), event.getSearchKey1(), "AdjustParentInvoice", CallOrigin.INTERNAL, UserType.SYSTEM, event.getUserToken());
- // TODO it may change to Account - #459
- final ImmutableAccountData account = accountApi.getImmutableAccountDataById(event.getAccountId(), context);
+ final Account account = accountApi.getAccountById(event.getAccountId(), context);
// catch children invoices and populate the parent summary invoice
if (isChildrenAccountAndPaymentDelegated(account)) {
diff --git a/overdue/src/main/java/org/killbill/billing/overdue/wrapper/OverdueWrapper.java b/overdue/src/main/java/org/killbill/billing/overdue/wrapper/OverdueWrapper.java
index 0c1e151..56db945 100644
--- a/overdue/src/main/java/org/killbill/billing/overdue/wrapper/OverdueWrapper.java
+++ b/overdue/src/main/java/org/killbill/billing/overdue/wrapper/OverdueWrapper.java
@@ -1,7 +1,7 @@
/*
* Copyright 2010-2013 Ning, Inc.
- * Copyright 2014-2016 Groupon, Inc
- * Copyright 2014-2016 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -19,7 +19,7 @@
package org.killbill.billing.overdue.wrapper;
import org.joda.time.DateTime;
-import org.killbill.billing.account.api.ImmutableAccountData;
+import org.killbill.billing.account.api.Account;
import org.killbill.billing.callcontext.InternalCallContext;
import org.killbill.billing.callcontext.InternalTenantContext;
import org.killbill.billing.entitlement.api.BlockingState;
@@ -52,7 +52,7 @@ public class OverdueWrapper {
// Should we introduce a config?
private static final int MAX_LOCK_RETRIES = 50;
- private final ImmutableAccountData overdueable;
+ private final Account overdueable;
private final BlockingInternalApi api;
private final GlobalLocker locker;
private final Clock clock;
@@ -61,7 +61,7 @@ public class OverdueWrapper {
private final OverdueStateApplicator overdueStateApplicator;
private final InternalCallContextFactory internalCallContextFactory;
- public OverdueWrapper(final ImmutableAccountData overdueable,
+ public OverdueWrapper(final Account overdueable,
final BlockingInternalApi api,
final OverdueStateSet overdueStateSet,
final GlobalLocker locker,
diff --git a/overdue/src/main/java/org/killbill/billing/overdue/wrapper/OverdueWrapperFactory.java b/overdue/src/main/java/org/killbill/billing/overdue/wrapper/OverdueWrapperFactory.java
index aa43f69..eb21b00 100644
--- a/overdue/src/main/java/org/killbill/billing/overdue/wrapper/OverdueWrapperFactory.java
+++ b/overdue/src/main/java/org/killbill/billing/overdue/wrapper/OverdueWrapperFactory.java
@@ -1,7 +1,7 @@
/*
* Copyright 2010-2013 Ning, Inc.
- * Copyright 2014-2016 Groupon, Inc
- * Copyright 2014-2016 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -21,9 +21,9 @@ package org.killbill.billing.overdue.wrapper;
import java.util.UUID;
import org.joda.time.Period;
+import org.killbill.billing.account.api.Account;
import org.killbill.billing.account.api.AccountApiException;
import org.killbill.billing.account.api.AccountInternalApi;
-import org.killbill.billing.account.api.ImmutableAccountData;
import org.killbill.billing.callcontext.InternalTenantContext;
import org.killbill.billing.junction.BlockingInternalApi;
import org.killbill.billing.overdue.api.OverdueApiException;
@@ -76,13 +76,13 @@ public class OverdueWrapperFactory {
this.internalCallContextFactory = internalCallContextFactory;
}
- public OverdueWrapper createOverdueWrapperFor(final ImmutableAccountData blockable, final InternalTenantContext context) throws OverdueException {
+ public OverdueWrapper createOverdueWrapperFor(final Account blockable, final InternalTenantContext context) throws OverdueException {
return new OverdueWrapper(blockable, api, getOverdueStateSet(context), locker, clock, billingStateCalculator, overdueStateApplicator, internalCallContextFactory);
}
public OverdueWrapper createOverdueWrapperFor(final UUID id, final InternalTenantContext context) throws OverdueException {
try {
- final ImmutableAccountData account = accountApi.getImmutableAccountDataById(id, context);
+ final Account account = accountApi.getAccountById(id, context);
return new OverdueWrapper(account, api, getOverdueStateSet(context), locker, clock, billingStateCalculator, overdueStateApplicator, internalCallContextFactory);
} catch (final AccountApiException e) {
throw new OverdueException(e);
diff --git a/overdue/src/test/java/org/killbill/billing/overdue/TestOverdueHelper.java b/overdue/src/test/java/org/killbill/billing/overdue/TestOverdueHelper.java
index f805d5d..135e86f 100644
--- a/overdue/src/test/java/org/killbill/billing/overdue/TestOverdueHelper.java
+++ b/overdue/src/test/java/org/killbill/billing/overdue/TestOverdueHelper.java
@@ -1,7 +1,7 @@
/*
* Copyright 2010-2013 Ning, Inc.
- * Copyright 2014-2016 Groupon, Inc
- * Copyright 2014-2016 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -26,9 +26,9 @@ import java.util.UUID;
import org.joda.time.DateTimeZone;
import org.joda.time.LocalDate;
import org.killbill.billing.ObjectType;
+import org.killbill.billing.account.api.Account;
import org.killbill.billing.account.api.AccountApiException;
import org.killbill.billing.account.api.AccountInternalApi;
-import org.killbill.billing.account.api.ImmutableAccountData;
import org.killbill.billing.callcontext.InternalTenantContext;
import org.killbill.billing.entitlement.api.BlockingState;
import org.killbill.billing.invoice.api.Invoice;
@@ -121,13 +121,12 @@ public class TestOverdueHelper {
Assert.assertEquals(result.isBlockBilling(), state.isDisableEntitlementAndChangesBlocked());
}
- public ImmutableAccountData createImmutableAccountData(final LocalDate dateOfLastUnPaidInvoice) throws SubscriptionBaseApiException, AccountApiException {
-
+ public Account createAccount(final LocalDate dateOfLastUnPaidInvoice) throws SubscriptionBaseApiException, AccountApiException {
final UUID accountId = UUID.randomUUID();
- final ImmutableAccountData account = Mockito.mock(ImmutableAccountData.class);
+ final Account account = Mockito.mock(Account.class);
Mockito.when(account.getId()).thenReturn(accountId);
Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.UTC);
- Mockito.when(accountInternalApi.getImmutableAccountDataById(Mockito.eq(account.getId()), Mockito.<InternalTenantContext>any())).thenReturn(account);
+ Mockito.when(accountInternalApi.getAccountById(Mockito.eq(account.getId()), Mockito.<InternalTenantContext>any())).thenReturn(account);
final Invoice invoice = Mockito.mock(Invoice.class);
Mockito.when(invoice.getInvoiceDate()).thenReturn(dateOfLastUnPaidInvoice);
diff --git a/overdue/src/test/java/org/killbill/billing/overdue/wrapper/TestOverdueWrapper.java b/overdue/src/test/java/org/killbill/billing/overdue/wrapper/TestOverdueWrapper.java
index f495016..7b5c9a3 100644
--- a/overdue/src/test/java/org/killbill/billing/overdue/wrapper/TestOverdueWrapper.java
+++ b/overdue/src/test/java/org/killbill/billing/overdue/wrapper/TestOverdueWrapper.java
@@ -1,7 +1,9 @@
/*
* Copyright 2010-2013 Ning, Inc.
+ * Copyright 2014-2016 Groupon, Inc
+ * Copyright 2014-2016 The Billing Project, LLC
*
- * Ning licenses this file to you under the Apache License, version 2.0
+ * The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
@@ -19,8 +21,7 @@ package org.killbill.billing.overdue.wrapper;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
-import org.killbill.billing.account.api.ImmutableAccountData;
-import org.killbill.billing.junction.DefaultBlockingState;
+import org.killbill.billing.account.api.Account;
import org.killbill.billing.overdue.OverdueTestSuiteWithEmbeddedDB;
import org.killbill.billing.overdue.api.OverdueState;
import org.killbill.billing.overdue.caching.MockOverdueConfigCache;
@@ -44,24 +45,24 @@ public class TestOverdueWrapper extends OverdueTestSuiteWithEmbeddedDB {
final DefaultOverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, DefaultOverdueConfig.class);
((MockOverdueConfigCache) overdueConfigCache).loadOverwriteDefaultOverdueConfig(config);
- ImmutableAccountData account;
+ Account account;
OverdueWrapper wrapper;
OverdueState state;
state = config.getOverdueStatesAccount().findState("OD1");
- account = testOverdueHelper.createImmutableAccountData(clock.getUTCToday().minusDays(31));
+ account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(31));
wrapper = overdueWrapperFactory.createOverdueWrapperFor(account, internalCallContext);
wrapper.refresh(clock.getUTCNow(), internalCallContext);
testOverdueHelper.checkStateApplied(state);
state = config.getOverdueStatesAccount().findState("OD2");
- account = testOverdueHelper.createImmutableAccountData(clock.getUTCToday().minusDays(41));
+ account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(41));
wrapper = overdueWrapperFactory.createOverdueWrapperFor(account, internalCallContext);
wrapper.refresh(clock.getUTCNow(), internalCallContext);
testOverdueHelper.checkStateApplied(state);
state = config.getOverdueStatesAccount().findState("OD3");
- account = testOverdueHelper.createImmutableAccountData(clock.getUTCToday().minusDays(51));
+ account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(51));
wrapper = overdueWrapperFactory.createOverdueWrapperFor(account, internalCallContext);
wrapper.refresh(clock.getUTCNow(), internalCallContext);
testOverdueHelper.checkStateApplied(state);
@@ -70,14 +71,14 @@ public class TestOverdueWrapper extends OverdueTestSuiteWithEmbeddedDB {
@Test(groups = "slow")
public void testWrapperNoConfig() throws Exception {
- final ImmutableAccountData account;
+ final Account account;
final OverdueWrapper wrapper;
final OverdueState state;
final InputStream is = new ByteArrayInputStream(testOverdueHelper.getConfigXml().getBytes());
final DefaultOverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, DefaultOverdueConfig.class);
state = config.getOverdueStatesAccount().findState(OverdueWrapper.CLEAR_STATE_NAME);
- account = testOverdueHelper.createImmutableAccountData(clock.getUTCToday().minusDays(31));
+ account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(31));
wrapper = overdueWrapperFactory.createOverdueWrapperFor(account, internalCallContext);
final OverdueState result = wrapper.refresh(clock.getUTCNow(), internalCallContext);
diff --git a/payment/src/main/java/org/killbill/billing/payment/invoice/InvoicePaymentControlPluginApi.java b/payment/src/main/java/org/killbill/billing/payment/invoice/InvoicePaymentControlPluginApi.java
index 81185d4..d027222 100644
--- a/payment/src/main/java/org/killbill/billing/payment/invoice/InvoicePaymentControlPluginApi.java
+++ b/payment/src/main/java/org/killbill/billing/payment/invoice/InvoicePaymentControlPluginApi.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2014-2016 Groupon, Inc
- * Copyright 2014-2016 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -32,8 +32,8 @@ import org.joda.time.DateTime;
import org.killbill.billing.ErrorCode;
import org.killbill.billing.ObjectType;
import org.killbill.billing.account.api.AccountApiException;
+import org.killbill.billing.account.api.AccountData;
import org.killbill.billing.account.api.AccountInternalApi;
-import org.killbill.billing.account.api.ImmutableAccountData;
import org.killbill.billing.callcontext.InternalCallContext;
import org.killbill.billing.callcontext.InternalTenantContext;
import org.killbill.billing.catalog.api.Currency;
@@ -322,8 +322,8 @@ public final class InvoicePaymentControlPluginApi implements PaymentControlPlugi
return new DefaultPriorPaymentControlResult(true);
}
- // get immutable account and check if it is child and payment is delegated to parent => abort
- final ImmutableAccountData accountData = accountApi.getImmutableAccountDataById(invoice.getAccountId(), internalContext);
+ // Get account and check if it is child and payment is delegated to parent => abort
+ final AccountData accountData = accountApi.getAccountById(invoice.getAccountId(), internalContext);
if ((accountData != null) && (accountData.getParentAccountId() != null) && accountData.isPaymentDelegatedToParent()) {
return new DefaultPriorPaymentControlResult(true);
}