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);
}
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));
}
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);
}
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");
}
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);
}
}
Aggregations