use of org.killbill.billing.account.api.Account in project killbill by killbill.
the class SubscriptionTestSuiteWithEmbeddedDB method createAccount.
protected Account createAccount(final AccountData accountData) throws AccountApiException {
final Account account = accountUserApi.createAccount(accountData, callContext);
refreshCallContext(account.getId());
return account;
}
use of org.killbill.billing.account.api.Account in project killbill by killbill.
the class TestRetryService method testAbortedPlugin.
// PLUGIN_EXCEPTION will lead to UNKNOWN row that will not be retried by the plugin
@Test(groups = "fast")
public void testAbortedPlugin() throws Exception {
final Account account = testHelper.createTestAccount("yiyi.gmail.com", true);
final Invoice invoice = testHelper.createTestInvoice(account, clock.getUTCToday(), Currency.USD);
final BigDecimal amount = new BigDecimal("10.00");
final UUID subscriptionId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
final LocalDate startDate = clock.getUTCToday();
final LocalDate endDate = startDate.plusMonths(1);
invoice.addInvoiceItem(new MockRecurringInvoiceItem(invoice.getId(), account.getId(), subscriptionId, bundleId, "test plan", "test phase", null, startDate, endDate, amount, new BigDecimal("1.0"), Currency.USD));
setPaymentFailure(FailureType.PLUGIN_EXCEPTION);
boolean failed = false;
final String paymentExternalKey = UUID.randomUUID().toString();
final String transactionExternalKey = UUID.randomUUID().toString();
try {
pluginControlPaymentProcessor.createPurchase(false, account, account.getPaymentMethodId(), null, amount, Currency.USD, paymentExternalKey, transactionExternalKey, createPropertiesForInvoice(invoice), ImmutableList.<String>of(InvoicePaymentControlPluginApi.PLUGIN_NAME), callContext, internalCallContext);
} catch (final PaymentApiException e) {
failed = true;
}
assertTrue(failed);
Payment payment = getPaymentForExternalKey(paymentExternalKey);
List<PaymentAttemptModelDao> attempts = paymentDao.getPaymentAttempts(paymentExternalKey, internalCallContext);
assertEquals(attempts.size(), 1);
final List<PaymentTransactionModelDao> transactions = paymentDao.getTransactionsForPayment(payment.getId(), internalCallContext);
assertEquals(transactions.size(), 1);
attempts = paymentDao.getPaymentAttempts(payment.getExternalKey(), internalCallContext);
final int expectedAttempts = 1;
assertEquals(attempts.size(), expectedAttempts);
assertEquals(attempts.get(0).getStateName(), "ABORTED");
}
use of org.killbill.billing.account.api.Account in project killbill by killbill.
the class TestPaymentApi method testAddRemovePaymentMethod.
@Test(groups = "slow")
public void testAddRemovePaymentMethod() throws Exception {
final Long baseNbRecords = paymentApi.getPaymentMethods(0L, 1000L, false, ImmutableList.<PluginProperty>of(), callContext).getMaxNbRecords();
Assert.assertEquals(baseNbRecords, (Long) 1L);
final Account account = testHelper.createTestAccount(UUID.randomUUID().toString(), true);
final UUID paymentMethodId = account.getPaymentMethodId();
checkPaymentMethodPagination(paymentMethodId, baseNbRecords + 1, false);
paymentApi.deletePaymentMethod(account, paymentMethodId, true, false, ImmutableList.<PluginProperty>of(), callContext);
checkPaymentMethodPagination(paymentMethodId, baseNbRecords, true);
}
use of org.killbill.billing.account.api.Account in project killbill by killbill.
the class TestPaymentApi method testAddRemovePaymentMethodWithForcedDeletion.
@Test(groups = "slow")
public void testAddRemovePaymentMethodWithForcedDeletion() throws Exception {
final Long baseNbRecords = paymentApi.getPaymentMethods(0L, 1000L, false, ImmutableList.<PluginProperty>of(), callContext).getMaxNbRecords();
Assert.assertEquals(baseNbRecords, (Long) 1L);
final Account account = testHelper.createTestAccount(UUID.randomUUID().toString(), true);
final UUID paymentMethodId = account.getPaymentMethodId();
checkPaymentMethodPagination(paymentMethodId, baseNbRecords + 1, false);
paymentApi.deletePaymentMethod(account, paymentMethodId, false, true, ImmutableList.<PluginProperty>of(), callContext);
checkPaymentMethodPagination(paymentMethodId, baseNbRecords, true);
}
use of org.killbill.billing.account.api.Account in project killbill by killbill.
the class TestPaymentHelper method createTestAccount.
public Account createTestAccount(final String email, final boolean addPaymentMethod) throws Exception {
final String name = "First" + UUID.randomUUID().toString() + " " + "Last" + UUID.randomUUID().toString();
final String externalKey = UUID.randomUUID().toString();
final Account accountData = Mockito.mock(Account.class);
Mockito.when(accountData.getId()).thenReturn(UUID.randomUUID());
Mockito.when(accountData.getExternalKey()).thenReturn(externalKey);
Mockito.when(accountData.getName()).thenReturn(name);
Mockito.when(accountData.getFirstNameLength()).thenReturn(10);
Mockito.when(accountData.getPhone()).thenReturn("123-456-7890");
Mockito.when(accountData.getEmail()).thenReturn(email);
Mockito.when(accountData.getCurrency()).thenReturn(Currency.USD);
Mockito.when(accountData.getBillCycleDayLocal()).thenReturn(1);
Mockito.when(accountData.isMigrated()).thenReturn(false);
Mockito.when(accountData.isNotifiedForInvoices()).thenReturn(false);
Mockito.when(accountData.getTimeZone()).thenReturn(DateTimeZone.UTC);
Mockito.when(accountData.getCreatedDate()).thenReturn(clock.getUTCNow());
Account account;
if (isFastTest()) {
account = GuicyKillbillTestSuiteNoDB.createMockAccount(accountData, accountApi, accountInternalApi, immutableAccountInternalApi, nonEntityDao, clock, internalCallContextFactory, context, internalCallContext);
} else {
account = accountApi.createAccount(accountData, context);
}
GuicyKillbillTestSuite.refreshCallContext(account.getId(), clock, internalCallContextFactory, context, internalCallContext);
if (addPaymentMethod) {
final PaymentMethodPlugin pm = new DefaultNoOpPaymentMethodPlugin(UUID.randomUUID().toString(), true, null);
account = addTestPaymentMethod(account, pm);
}
return account;
}
Aggregations