use of org.killbill.billing.account.api.Account in project killbill by killbill.
the class PluginControlPaymentProcessor method retryPaymentTransaction.
public void retryPaymentTransaction(final UUID attemptId, final List<String> paymentControlPluginNames, final InternalCallContext internalCallContext) {
final PaymentAttemptModelDao attempt = paymentDao.getPaymentAttempt(attemptId, internalCallContext);
log.info("Retrying attemptId='{}', paymentExternalKey='{}', transactionExternalKey='{}'. paymentControlPluginNames='{}'", attemptId, attempt.getPaymentExternalKey(), attempt.getTransactionExternalKey(), paymentControlPluginNames);
final PaymentModelDao paymentModelDao = paymentDao.getPaymentByExternalKey(attempt.getPaymentExternalKey(), internalCallContext);
final UUID paymentId = paymentModelDao != null ? paymentModelDao.getId() : null;
final CallContext callContext = buildCallContext(internalCallContext);
final String transactionType = TransactionType.PURCHASE.name();
Account account = null;
Payment payment = null;
PaymentTransaction paymentTransaction = null;
try {
account = accountInternalApi.getAccountById(attempt.getAccountId(), internalCallContext);
final State state = paymentControlStateMachineHelper.getState(attempt.getStateName());
final Iterable<PluginProperty> pluginProperties = PluginPropertySerializer.deserialize(attempt.getPluginProperties());
logEnterAPICall(log, transactionType, account, attempt.getPaymentMethodId(), paymentId, null, attempt.getAmount(), attempt.getCurrency(), attempt.getPaymentExternalKey(), attempt.getTransactionExternalKey(), null, paymentControlPluginNames);
payment = pluginControlledPaymentAutomatonRunner.run(state, false, attempt.getTransactionType(), ControlOperation.valueOf(attempt.getTransactionType().toString()), account, attempt.getPaymentMethodId(), paymentId, attempt.getPaymentExternalKey(), attempt.getTransactionExternalKey(), attempt.getAmount(), attempt.getCurrency(), pluginProperties, paymentControlPluginNames, callContext, internalCallContext);
paymentTransaction = Iterables.<PaymentTransaction>find(Lists.<PaymentTransaction>reverse(payment.getTransactions()), new Predicate<PaymentTransaction>() {
@Override
public boolean apply(final PaymentTransaction input) {
return attempt.getTransactionExternalKey().equals(input.getExternalKey());
}
});
} catch (final AccountApiException e) {
log.warn("Failed to retry attemptId='{}', paymentControlPlugins='{}'", attemptId, toPluginNamesOnError(paymentControlPluginNames), e);
} catch (final PaymentApiException e) {
// Log exception unless nothing left to be paid
if (e.getCode() == ErrorCode.PAYMENT_PLUGIN_API_ABORTED.getCode() && paymentControlPluginNames != null && paymentControlPluginNames.size() == 1 && InvoicePaymentControlPluginApi.PLUGIN_NAME.equals(paymentControlPluginNames.get(0))) {
log.warn("Failed to retry attemptId='{}', paymentControlPlugins='{}'. Invoice has already been paid", attemptId, toPluginNamesOnError(paymentControlPluginNames));
} else {
log.warn("Failed to retry attemptId='{}', paymentControlPlugins='{}'", attemptId, toPluginNamesOnError(paymentControlPluginNames), e);
}
} catch (final PluginPropertySerializerException e) {
log.warn("Failed to retry attemptId='{}', paymentControlPlugins='{}'", attemptId, toPluginNamesOnError(paymentControlPluginNames), e);
} catch (final MissingEntryException e) {
log.warn("Failed to retry attemptId='{}', paymentControlPlugins='{}'", attemptId, toPluginNamesOnError(paymentControlPluginNames), e);
} finally {
logExitAPICall(log, transactionType, account, payment != null ? payment.getPaymentMethodId() : null, payment != null ? payment.getId() : null, paymentTransaction != null ? paymentTransaction.getId() : null, paymentTransaction != null ? paymentTransaction.getProcessedAmount() : null, paymentTransaction != null ? paymentTransaction.getProcessedCurrency() : null, payment != null ? payment.getExternalKey() : null, paymentTransaction != null ? paymentTransaction.getExternalKey() : null, paymentTransaction != null ? paymentTransaction.getTransactionStatus() : null, paymentControlPluginNames, null);
}
}
use of org.killbill.billing.account.api.Account in project killbill by killbill.
the class TestOverdueHelper method createAccount.
public Account createAccount(final LocalDate dateOfLastUnPaidInvoice) throws SubscriptionBaseApiException, AccountApiException {
final UUID accountId = UUID.randomUUID();
final Account account = Mockito.mock(Account.class);
Mockito.when(account.getId()).thenReturn(accountId);
Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.UTC);
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);
Mockito.when(invoice.getBalance()).thenReturn(BigDecimal.TEN);
Mockito.when(invoice.getId()).thenReturn(UUID.randomUUID());
final InvoiceItem item = Mockito.mock(InvoiceItem.class);
final List<InvoiceItem> items = new ArrayList<InvoiceItem>();
items.add(item);
Mockito.when(invoice.getInvoiceItems()).thenReturn(items);
final List<Invoice> invoices = new ArrayList<Invoice>();
invoices.add(invoice);
Mockito.when(invoiceInternalApi.getUnpaidInvoicesByAccountId(Mockito.<UUID>any(), Mockito.<LocalDate>any(), Mockito.<InternalTenantContext>any())).thenReturn(invoices);
final Tag tag = Mockito.mock(Tag.class);
Mockito.when(tag.getObjectId()).thenReturn(accountId);
Mockito.when(tag.getObjectType()).thenReturn(ObjectType.ACCOUNT);
Mockito.when(tag.getTagDefinitionId()).thenReturn(new UUID(0, 6));
final List<Tag> tags = new ArrayList<Tag>();
tags.add(tag);
Mockito.when(tagInternalApi.getTags(Mockito.eq(account.getId()), Mockito.eq(ObjectType.ACCOUNT), Mockito.<InternalTenantContext>any())).thenReturn(tags);
return account;
}
use of org.killbill.billing.account.api.Account in project killbill by killbill.
the class TestBillingStateCalculator method beforeMethod.
@Override
@BeforeMethod(groups = "fast")
public void beforeMethod() throws Exception {
super.beforeMethod();
final Account account = Mockito.mock(Account.class);
Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.UTC);
Mockito.when(accountApi.getAccountById(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(account);
}
use of org.killbill.billing.account.api.Account in project killbill by killbill.
the class TestOverdueWrapper method testWrapperBasic.
@Test(groups = "slow")
public void testWrapperBasic() throws Exception {
final InputStream is = new ByteArrayInputStream(testOverdueHelper.getConfigXml().getBytes());
final DefaultOverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, DefaultOverdueConfig.class);
((MockOverdueConfigCache) overdueConfigCache).loadOverwriteDefaultOverdueConfig(config);
Account account;
OverdueWrapper wrapper;
OverdueState state;
state = config.getOverdueStatesAccount().findState("OD1");
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.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.createAccount(clock.getUTCToday().minusDays(51));
wrapper = overdueWrapperFactory.createOverdueWrapperFor(account, internalCallContext);
wrapper.refresh(clock.getUTCNow(), internalCallContext);
testOverdueHelper.checkStateApplied(state);
}
use of org.killbill.billing.account.api.Account in project killbill by killbill.
the class DefaultAccountApiBase method getAccountByKey.
protected Account getAccountByKey(final String key, final InternalTenantContext context) throws AccountApiException {
final AccountModelDao accountModelDao = accountDao.getAccountByKey(key, context);
if (accountModelDao == null) {
throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_KEY, key);
}
final Account account = new DefaultAccount(accountModelDao);
accountCacheController.putIfAbsent(account.getId(), new DefaultImmutableAccountData(account));
return account;
}
Aggregations