Search in sources :

Example 51 with Account

use of org.killbill.billing.account.api.Account in project killbill by killbill.

the class TestPaymentDao method testPaymentAttemptsByStateAcrossTenants.

@Test(groups = "slow")
public void testPaymentAttemptsByStateAcrossTenants() throws Exception {
    final String externalKey1 = "gfhfg";
    final String transactionExternalKey1 = "sadas";
    final String externalKey2 = "asdwqeqw";
    final String transactionExternalKey2 = "fghfg";
    final DateTime createdAfterDate = clock.getUTCNow().minusDays(10);
    final DateTime createdBeforeDate = clock.getUTCNow().minusDays(1);
    final String stateName = "FOO";
    final String pluginName = "miraculous";
    clock.setTime(createdAfterDate);
    Account account = testHelper.createTestAccount(UUID.randomUUID().toString(), true);
    final PaymentAttemptModelDao attempt1 = new PaymentAttemptModelDao(account.getId(), account.getPaymentMethodId(), createdAfterDate, createdAfterDate, externalKey1, UUID.randomUUID(), transactionExternalKey1, TransactionType.AUTHORIZE, stateName, BigDecimal.ONE, Currency.USD, ImmutableList.<String>of(pluginName), null);
    paymentDao.insertPaymentAttemptWithProperties(attempt1, internalCallContext);
    account = testHelper.createTestAccount(UUID.randomUUID().toString(), true);
    final PaymentAttemptModelDao attempt2 = new PaymentAttemptModelDao(account.getId(), account.getPaymentMethodId(), createdAfterDate, createdAfterDate, externalKey2, UUID.randomUUID(), transactionExternalKey2, TransactionType.AUTHORIZE, stateName, BigDecimal.ONE, Currency.USD, ImmutableList.<String>of(pluginName), null);
    paymentDao.insertPaymentAttemptWithProperties(attempt2, internalCallContext);
    final Pagination<PaymentAttemptModelDao> result = paymentDao.getPaymentAttemptsByStateAcrossTenants(stateName, createdBeforeDate, 0L, 2L);
    Assert.assertEquals(result.getTotalNbRecords().longValue(), 2L);
}
Also used : Account(org.killbill.billing.account.api.Account) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 52 with Account

use of org.killbill.billing.account.api.Account in project killbill by killbill.

the class TestPaymentDao method testUpdatePaymentAttempt.

@Test(groups = "slow")
public void testUpdatePaymentAttempt() throws Exception {
    final DateTime createdAfterDate = clock.getUTCNow().minusDays(10);
    clock.setTime(createdAfterDate);
    final Account account = testHelper.createTestAccount(UUID.randomUUID().toString(), true);
    final String externalKey1 = "2354";
    final String transactionExternalKey1 = "jkjkjk";
    final String stateName = "RRRRR";
    final String pluginName = "elated";
    final PaymentAttemptModelDao attempt = new PaymentAttemptModelDao(account.getId(), account.getPaymentMethodId(), createdAfterDate, createdAfterDate, externalKey1, UUID.randomUUID(), transactionExternalKey1, TransactionType.AUTHORIZE, stateName, BigDecimal.ONE, Currency.USD, ImmutableList.<String>of(pluginName), null);
    final PaymentAttemptModelDao rehydratedAttempt = paymentDao.insertPaymentAttemptWithProperties(attempt, internalCallContext);
    final UUID transactionId = UUID.randomUUID();
    final String newStateName = "YYYYYYY";
    paymentDao.updatePaymentAttempt(rehydratedAttempt.getId(), transactionId, newStateName, internalCallContext);
    final PaymentAttemptModelDao attempt1 = paymentDao.getPaymentAttempt(rehydratedAttempt.getId(), internalCallContext);
    assertEquals(attempt1.getStateName(), newStateName);
    assertEquals(attempt1.getTransactionId(), transactionId);
    final List<PluginProperty> properties = new ArrayList<PluginProperty>();
    properties.add(new PluginProperty("prop1", "value1", false));
    properties.add(new PluginProperty("prop2", "value2", false));
    final byte[] serializedProperties = PluginPropertySerializer.serialize(properties);
    paymentDao.updatePaymentAttemptWithProperties(rehydratedAttempt.getId(), transactionId, newStateName, serializedProperties, internalCallContext);
    final PaymentAttemptModelDao attempt2 = paymentDao.getPaymentAttempt(rehydratedAttempt.getId(), internalCallContext);
    assertEquals(attempt2.getStateName(), newStateName);
    assertEquals(attempt2.getTransactionId(), transactionId);
    final Iterable<PluginProperty> properties2 = PluginPropertySerializer.deserialize(attempt2.getPluginProperties());
    checkProperty(properties2, new PluginProperty("prop1", "value1", false));
    checkProperty(properties2, new PluginProperty("prop2", "value2", false));
}
Also used : Account(org.killbill.billing.account.api.Account) PluginProperty(org.killbill.billing.payment.api.PluginProperty) ArrayList(java.util.ArrayList) UUID(java.util.UUID) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 53 with Account

use of org.killbill.billing.account.api.Account in project killbill by killbill.

the class TestPaymentAutomatonDAOHelper method createDAOHelper.

private PaymentAutomatonDAOHelper createDAOHelper(@Nullable final UUID paymentId, final String paymentExternalKey, final String paymentTransactionExternalKey, final BigDecimal amount, final Currency currency) throws Exception {
    final Account account = Mockito.mock(Account.class);
    Mockito.when(account.getId()).thenReturn(UUID.randomUUID());
    // No default payment method
    paymentStateContext = new PaymentStateContext(true, paymentId, null, null, paymentExternalKey, paymentTransactionExternalKey, TransactionType.CAPTURE, account, UUID.randomUUID(), amount, currency, null, null, false, null, ImmutableList.<PluginProperty>of(), internalCallContext, callContext);
    return new PaymentAutomatonDAOHelper(paymentStateContext, clock.getUTCNow(), paymentDao, paymentPluginServiceRegistration, internalCallContext, eventBus, paymentSMHelper);
}
Also used : Account(org.killbill.billing.account.api.Account) PluginProperty(org.killbill.billing.payment.api.PluginProperty)

Example 54 with Account

use of org.killbill.billing.account.api.Account in project killbill by killbill.

the class TestPaymentLeavingStateCallback method setUp.

private void setUp(@Nullable final UUID paymentId) throws Exception {
    account = Mockito.mock(Account.class);
    Mockito.when(account.getId()).thenReturn(UUID.randomUUID());
    paymentStateContext = new PaymentStateContext(true, paymentId, null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), TransactionType.CAPTURE, account, UUID.randomUUID(), new BigDecimal("192.3920111"), Currency.BRL, null, null, false, null, ImmutableList.<PluginProperty>of(), internalCallContext, callContext);
    if (paymentId != null) {
        // Create the first payment manually
        final PaymentModelDao newPaymentModelDao = new PaymentModelDao(paymentId, clock.getUTCNow(), clock.getUTCNow(), paymentStateContext.getAccount().getId(), paymentStateContext.getPaymentMethodId(), 1, paymentStateContext.getPaymentExternalKey());
        final PaymentTransactionModelDao newPaymentTransactionModelDao = new PaymentTransactionModelDao(clock.getUTCNow(), clock.getUTCNow(), null, paymentStateContext.getPaymentTransactionExternalKey(), paymentId, paymentStateContext.getTransactionType(), clock.getUTCNow(), TransactionStatus.UNKNOWN, paymentStateContext.getAmount(), paymentStateContext.getCurrency(), null, null);
        paymentDao.insertPaymentWithFirstTransaction(newPaymentModelDao, newPaymentTransactionModelDao, internalCallContext);
    }
    final PaymentAutomatonDAOHelper daoHelper = new PaymentAutomatonDAOHelper(paymentStateContext, clock.getUTCNow(), paymentDao, paymentPluginServiceRegistration, internalCallContext, eventBus, paymentSMHelper);
    callback = new PaymentLeavingStateTestCallback(daoHelper, paymentStateContext);
    Mockito.when(state.getName()).thenReturn("NEW_STATE");
}
Also used : Account(org.killbill.billing.account.api.Account) PluginProperty(org.killbill.billing.payment.api.PluginProperty) PaymentTransactionModelDao(org.killbill.billing.payment.dao.PaymentTransactionModelDao) PaymentModelDao(org.killbill.billing.payment.dao.PaymentModelDao) BigDecimal(java.math.BigDecimal)

Example 55 with Account

use of org.killbill.billing.account.api.Account in project killbill by killbill.

the class TestPaymentMethodProcessorNoDB method testGetExternalPaymentProviderPlugin.

@Test(groups = "fast")
public void testGetExternalPaymentProviderPlugin() throws Exception {
    final Iterable<PluginProperty> properties = ImmutableList.<PluginProperty>of();
    final UUID accountId = UUID.randomUUID();
    final Account account = Mockito.mock(Account.class);
    Mockito.when(account.getId()).thenReturn(accountId);
    Mockito.when(account.getExternalKey()).thenReturn(accountId.toString());
    Assert.assertEquals(paymentMethodProcessor.getPaymentMethods(false, properties, internalCallContext).size(), 0);
    // The first call should create the payment method
    final ExternalPaymentProviderPlugin providerPlugin = paymentMethodProcessor.createPaymentMethodAndGetExternalPaymentProviderPlugin(UUID.randomUUID().toString(), account, properties, callContext, internalCallContext);
    final List<PaymentMethod> paymentMethods = paymentMethodProcessor.getPaymentMethods(false, properties, internalCallContext);
    Assert.assertEquals(paymentMethods.size(), 1);
    Assert.assertEquals(paymentMethods.get(0).getPluginName(), ExternalPaymentProviderPlugin.PLUGIN_NAME);
    Assert.assertEquals(paymentMethods.get(0).getAccountId(), account.getId());
    // The succeeding calls should not create any other payment method
    final UUID externalPaymentMethodId = paymentMethods.get(0).getId();
    for (int i = 0; i < 50; i++) {
        final ExternalPaymentProviderPlugin foundProviderPlugin = paymentMethodProcessor.createPaymentMethodAndGetExternalPaymentProviderPlugin(UUID.randomUUID().toString(), account, properties, callContext, internalCallContext);
        Assert.assertNotNull(foundProviderPlugin);
        final List<PaymentMethod> foundPaymentMethods = paymentMethodProcessor.getPaymentMethods(false, properties, internalCallContext);
        Assert.assertEquals(foundPaymentMethods.size(), 1);
        Assert.assertEquals(foundPaymentMethods.get(0).getPluginName(), ExternalPaymentProviderPlugin.PLUGIN_NAME);
        Assert.assertEquals(foundPaymentMethods.get(0).getAccountId(), account.getId());
        Assert.assertEquals(foundPaymentMethods.get(0).getId(), externalPaymentMethodId);
    }
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) Account(org.killbill.billing.account.api.Account) PaymentMethod(org.killbill.billing.payment.api.PaymentMethod) UUID(java.util.UUID) ExternalPaymentProviderPlugin(org.killbill.billing.payment.provider.ExternalPaymentProviderPlugin) Test(org.testng.annotations.Test)

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