Search in sources :

Example 96 with InternalCallContext

use of org.killbill.billing.callcontext.InternalCallContext in project killbill by killbill.

the class InvoicePaymentControlPluginApi method priorCall.

@Override
public PriorPaymentControlResult priorCall(final PaymentControlContext paymentControlContext, final Iterable<PluginProperty> pluginProperties) throws PaymentControlApiException {
    final TransactionType transactionType = paymentControlContext.getTransactionType();
    Preconditions.checkArgument(paymentControlContext.getPaymentApiType() == PaymentApiType.PAYMENT_TRANSACTION);
    Preconditions.checkArgument(transactionType == TransactionType.PURCHASE || transactionType == TransactionType.REFUND || transactionType == TransactionType.CHARGEBACK || transactionType == TransactionType.CREDIT);
    final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContext(paymentControlContext.getAccountId(), paymentControlContext);
    switch(transactionType) {
        case PURCHASE:
            return getPluginPurchaseResult(paymentControlContext, pluginProperties, internalContext);
        case REFUND:
            return getPluginRefundResult(paymentControlContext, pluginProperties, internalContext);
        case CHARGEBACK:
            return new DefaultPriorPaymentControlResult(false, paymentControlContext.getAmount());
        case CREDIT:
            return getPluginCreditResult(paymentControlContext, pluginProperties, internalContext);
        default:
            throw new IllegalStateException("Unexpected transactionType " + transactionType);
    }
}
Also used : TransactionType(org.killbill.billing.payment.api.TransactionType) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) DefaultPriorPaymentControlResult(org.killbill.billing.payment.retry.DefaultPriorPaymentControlResult)

Example 97 with InternalCallContext

use of org.killbill.billing.callcontext.InternalCallContext in project killbill by killbill.

the class DefaultTagUserApi method addTag.

@Override
public void addTag(final UUID objectId, final ObjectType objectType, final UUID tagDefinitionId, final CallContext context) throws TagApiException {
    if (SystemTags.isSystemTag(tagDefinitionId)) {
        // TODO Create a proper ErrorCode instaed
        throw new IllegalStateException(String.format("Failed to add tag for tagDefinitionId='%s': System tags are reserved for the system.", tagDefinitionId));
    }
    final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContext(objectId, objectType, context);
    final TagModelDao tag = new TagModelDao(context.getCreatedDate(), tagDefinitionId, objectId, objectType);
    try {
        tagDao.create(tag, internalContext);
    } catch (TagApiException e) {
        // Be lenient here and make the addTag method idempotent
        if (ErrorCode.TAG_ALREADY_EXISTS.getCode() != e.getCode()) {
            throw e;
        }
    }
}
Also used : TagApiException(org.killbill.billing.util.api.TagApiException) TagModelDao(org.killbill.billing.util.tag.dao.TagModelDao) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext)

Example 98 with InternalCallContext

use of org.killbill.billing.callcontext.InternalCallContext in project killbill by killbill.

the class TestInternalCallContextFactory method testCreateInternalCallContextWithAccountRecordIdFromAccountObjectType.

@Test(groups = "slow")
public void testCreateInternalCallContextWithAccountRecordIdFromAccountObjectType() throws Exception {
    final UUID accountId = UUID.randomUUID();
    final Long accountRecordId = 19384012L;
    dbi.withHandle(new HandleCallback<Void>() {

        @Override
        public Void withHandle(final Handle handle) throws Exception {
            // Note: we always create an accounts table, see MysqlTestingHelper
            handle.execute("insert into accounts (record_id, id, email, name, first_name_length, is_notified_for_invoices, created_date, created_by, updated_date, updated_by) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", accountRecordId, accountId.toString(), "yo@t.com", "toto", 4, false, new Date(), "i", new Date(), "j");
            return null;
        }
    });
    final InternalCallContext context = internalCallContextFactory.createInternalCallContext(accountId, ObjectType.ACCOUNT, callContext);
    // The account record id should have been looked up in the accounts table
    Assert.assertEquals(context.getAccountRecordId(), accountRecordId);
    verifyInternalCallContext(context);
}
Also used : InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) UUID(java.util.UUID) Date(java.util.Date) Handle(org.skife.jdbi.v2.Handle) Test(org.testng.annotations.Test)

Example 99 with InternalCallContext

use of org.killbill.billing.callcontext.InternalCallContext in project killbill by killbill.

the class DefaultAccountUserApi method createAccount.

@Override
public Account createAccount(final AccountData data, final CallContext context) throws AccountApiException {
    // Not transactional, but there is a db constraint on that column
    if (data.getExternalKey() != null && getIdFromKey(data.getExternalKey(), context) != null) {
        throw new AccountApiException(ErrorCode.ACCOUNT_ALREADY_EXISTS, data.getExternalKey());
    }
    final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context);
    if (data.getParentAccountId() != null) {
        // verify that parent account exists if parentAccountId is not null
        getAccountById(data.getParentAccountId(), internalContext);
    }
    final AccountModelDao account = new AccountModelDao(data);
    if (null != account.getExternalKey() && account.getExternalKey().length() > 255) {
        throw new AccountApiException(ErrorCode.EXTERNAL_KEY_LIMIT_EXCEEDED);
    }
    accountDao.create(account, internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context));
    return new DefaultAccount(account);
}
Also used : AccountModelDao(org.killbill.billing.account.dao.AccountModelDao) DefaultAccount(org.killbill.billing.account.api.DefaultAccount) AccountApiException(org.killbill.billing.account.api.AccountApiException) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext)

Example 100 with InternalCallContext

use of org.killbill.billing.callcontext.InternalCallContext in project killbill by killbill.

the class DefaultAccountDao method postBusEventFromTransaction.

@Override
protected void postBusEventFromTransaction(final AccountModelDao account, final AccountModelDao savedAccount, final ChangeType changeType, final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory, final InternalCallContext context) throws BillingExceptionBase {
    // This is only called for the create call (see update below)
    switch(changeType) {
        case INSERT:
            break;
        default:
            return;
    }
    final Long recordId = entitySqlDaoWrapperFactory.become(AccountSqlDao.class).getRecordId(savedAccount.getId().toString(), context);
    // We need to re-hydrate the callcontext with the account record id
    final InternalCallContext rehydratedContext = internalCallContextFactory.createInternalCallContext(recordId, context);
    final AccountCreationInternalEvent creationEvent = new DefaultAccountCreationEvent(new DefaultAccountData(savedAccount), savedAccount.getId(), rehydratedContext.getAccountRecordId(), rehydratedContext.getTenantRecordId(), rehydratedContext.getUserToken());
    try {
        eventBus.postFromTransaction(creationEvent, entitySqlDaoWrapperFactory.getHandle().getConnection());
    } catch (final EventBusException e) {
        log.warn("Failed to post account creation event for accountId='{}'", savedAccount.getId(), e);
    }
}
Also used : DefaultAccountCreationEvent(org.killbill.billing.account.api.user.DefaultAccountCreationEvent) EventBusException(org.killbill.bus.api.PersistentBus.EventBusException) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) DefaultAccountData(org.killbill.billing.account.api.user.DefaultAccountCreationEvent.DefaultAccountData) AccountCreationInternalEvent(org.killbill.billing.events.AccountCreationInternalEvent)

Aggregations

InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)110 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)26 DateTime (org.joda.time.DateTime)25 UUID (java.util.UUID)24 ArrayList (java.util.ArrayList)21 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)17 InvoiceApiException (org.killbill.billing.invoice.api.InvoiceApiException)14 CallContext (org.killbill.billing.util.callcontext.CallContext)14 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)13 WithEntitlementPlugin (org.killbill.billing.entitlement.api.EntitlementPluginExecution.WithEntitlementPlugin)13 EntitlementContext (org.killbill.billing.entitlement.plugin.api.EntitlementContext)13 AccountApiException (org.killbill.billing.account.api.AccountApiException)12 DefaultBlockingState (org.killbill.billing.junction.DefaultBlockingState)12 NotificationEvent (org.killbill.notificationq.api.NotificationEvent)9 BigDecimal (java.math.BigDecimal)8 LinkedList (java.util.LinkedList)8 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)8 Invoice (org.killbill.billing.invoice.api.Invoice)8 AllowConcurrentEvents (com.google.common.eventbus.AllowConcurrentEvents)7 Subscribe (com.google.common.eventbus.Subscribe)7