Search in sources :

Example 1 with Account

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;
}
Also used : Account(org.killbill.billing.account.api.Account)

Example 2 with 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");
}
Also used : PaymentAttemptModelDao(org.killbill.billing.payment.dao.PaymentAttemptModelDao) Account(org.killbill.billing.account.api.Account) Invoice(org.killbill.billing.invoice.api.Invoice) PaymentApiException(org.killbill.billing.payment.api.PaymentApiException) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Payment(org.killbill.billing.payment.api.Payment) PaymentTransactionModelDao(org.killbill.billing.payment.dao.PaymentTransactionModelDao) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 3 with Account

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);
}
Also used : Account(org.killbill.billing.account.api.Account) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 4 with Account

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);
}
Also used : Account(org.killbill.billing.account.api.Account) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 5 with Account

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;
}
Also used : Account(org.killbill.billing.account.api.Account) DefaultNoOpPaymentMethodPlugin(org.killbill.billing.payment.provider.DefaultNoOpPaymentMethodPlugin) PaymentMethodPlugin(org.killbill.billing.payment.api.PaymentMethodPlugin) DefaultNoOpPaymentMethodPlugin(org.killbill.billing.payment.provider.DefaultNoOpPaymentMethodPlugin)

Aggregations

Account (org.killbill.billing.account.api.Account)305 Test (org.testng.annotations.Test)198 LocalDate (org.joda.time.LocalDate)139 BigDecimal (java.math.BigDecimal)90 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)87 Invoice (org.killbill.billing.invoice.api.Invoice)84 DateTime (org.joda.time.DateTime)71 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)63 UUID (java.util.UUID)62 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)59 ApiOperation (io.swagger.annotations.ApiOperation)48 ApiResponses (io.swagger.annotations.ApiResponses)48 ArrayList (java.util.ArrayList)48 Produces (javax.ws.rs.Produces)48 AccountData (org.killbill.billing.account.api.AccountData)47 TimedResource (org.killbill.commons.metrics.TimedResource)47 Path (javax.ws.rs.Path)42 PluginProperty (org.killbill.billing.payment.api.PluginProperty)42 DefaultAccount (org.killbill.billing.account.api.DefaultAccount)41 Payment (org.killbill.billing.payment.api.Payment)40