Search in sources :

Example 16 with InternalCallContext

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

the class DefaultPaymentApi method createRefund.

@Override
public Payment createRefund(final Account account, @Nullable final UUID paymentId, final BigDecimal amount, final Currency currency, @Nullable final String paymentTransactionExternalKey, final Iterable<PluginProperty> properties, final CallContext callContext) throws PaymentApiException {
    checkNotNullParameter(account, "account");
    if (paymentId == null) {
        checkNotNullParameter(currency, "currency");
    }
    checkNotNullParameter(paymentId, "paymentId");
    checkNotNullParameter(properties, "plugin properties");
    checkExternalKeyLength(paymentTransactionExternalKey);
    final String transactionType = TransactionType.REFUND.name();
    Payment payment = null;
    PaymentTransaction paymentTransaction = null;
    PaymentApiException exception = null;
    try {
        logEnterAPICall(log, transactionType, account, null, paymentId, null, amount, currency, null, paymentTransactionExternalKey, null, null);
        final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(account.getId(), callContext);
        payment = paymentProcessor.createRefund(IS_API_PAYMENT, NULL_ATTEMPT_ID, account, paymentId, amount, currency, paymentTransactionExternalKey, null, SHOULD_LOCK_ACCOUNT, properties, callContext, internalCallContext);
        paymentTransaction = findPaymentTransaction(payment, paymentTransactionExternalKey);
        return payment;
    } catch (PaymentApiException e) {
        exception = e;
        throw 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, null, exception);
    }
}
Also used : InternalCallContext(org.killbill.billing.callcontext.InternalCallContext)

Example 17 with InternalCallContext

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

the class DefaultPaymentApi method createVoidWithPaymentControl.

@Override
public Payment createVoidWithPaymentControl(final Account account, final UUID paymentId, final String paymentTransactionExternalKey, final Iterable<PluginProperty> properties, final PaymentOptions paymentOptions, final CallContext callContext) throws PaymentApiException {
    final List<String> paymentControlPluginNames = toPaymentControlPluginNames(paymentOptions, callContext);
    if (paymentControlPluginNames.isEmpty()) {
        return createVoid(account, paymentId, paymentTransactionExternalKey, properties, callContext);
    }
    checkNotNullParameter(account, "account");
    checkNotNullParameter(paymentId, "paymentId");
    checkNotNullParameter(properties, "plugin properties");
    checkExternalKeyLength(paymentTransactionExternalKey);
    final String transactionType = TransactionType.VOID.name();
    Payment payment = null;
    PaymentTransaction paymentTransaction = null;
    PaymentApiException exception = null;
    try {
        logEnterAPICall(log, transactionType, account, null, paymentId, null, null, null, null, paymentTransactionExternalKey, null, paymentControlPluginNames);
        final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(account.getId(), callContext);
        payment = pluginControlPaymentProcessor.createVoid(IS_API_PAYMENT, account, paymentId, paymentTransactionExternalKey, properties, paymentControlPluginNames, callContext, internalCallContext);
        paymentTransaction = findPaymentTransaction(payment, paymentTransactionExternalKey);
        return payment;
    } catch (PaymentApiException e) {
        exception = e;
        throw 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, exception);
    }
}
Also used : InternalCallContext(org.killbill.billing.callcontext.InternalCallContext)

Example 18 with InternalCallContext

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

the class DefaultPaymentApi method createChargebackReversal.

@Override
public Payment createChargebackReversal(final Account account, final UUID paymentId, final String paymentTransactionExternalKey, final CallContext callContext) throws PaymentApiException {
    checkNotNullParameter(account, "account");
    checkNotNullParameter(paymentId, "paymentId");
    checkExternalKeyLength(paymentTransactionExternalKey);
    final String transactionType = TransactionType.CHARGEBACK.name();
    Payment payment = null;
    PaymentTransaction paymentTransaction = null;
    PaymentApiException exception = null;
    try {
        logEnterAPICall(log, transactionType, account, null, paymentId, null, null, null, null, paymentTransactionExternalKey, null, null);
        final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(account.getId(), callContext);
        payment = paymentProcessor.createChargebackReversal(IS_API_PAYMENT, NULL_ATTEMPT_ID, account, paymentId, paymentTransactionExternalKey, null, null, null, true, callContext, internalCallContext);
        paymentTransaction = findPaymentTransaction(payment, paymentTransactionExternalKey);
        return payment;
    } catch (PaymentApiException e) {
        exception = e;
        throw 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, null, exception);
    }
}
Also used : InternalCallContext(org.killbill.billing.callcontext.InternalCallContext)

Example 19 with InternalCallContext

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

the class DefaultPaymentApi method createCredit.

@Override
public Payment createCredit(final Account account, final UUID paymentMethodId, @Nullable final UUID paymentId, final BigDecimal amount, final Currency currency, @Nullable final String paymentExternalKey, @Nullable final String paymentTransactionExternalKey, final Iterable<PluginProperty> properties, final CallContext callContext) throws PaymentApiException {
    checkNotNullParameter(account, "account");
    if (paymentId == null) {
        checkNotNullParameter(amount, "amount");
        checkNotNullParameter(currency, "currency");
    }
    checkNotNullParameter(paymentMethodId, "paymentMethodId");
    checkNotNullParameter(properties, "plugin properties");
    checkExternalKeyLength(paymentTransactionExternalKey);
    final String transactionType = TransactionType.CREDIT.name();
    Payment payment = null;
    PaymentTransaction paymentTransaction = null;
    PaymentApiException exception = null;
    try {
        logEnterAPICall(log, transactionType, account, paymentMethodId, paymentId, null, amount, currency, paymentExternalKey, paymentTransactionExternalKey, null, null);
        final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(account.getId(), callContext);
        final UUID nonNullPaymentMethodId = (paymentMethodId != null) ? paymentMethodId : paymentMethodProcessor.createOrGetExternalPaymentMethod(UUIDs.randomUUID().toString(), account, properties, callContext, internalCallContext);
        payment = paymentProcessor.createCredit(IS_API_PAYMENT, NULL_ATTEMPT_ID, account, nonNullPaymentMethodId, paymentId, amount, currency, paymentExternalKey, paymentTransactionExternalKey, null, null, SHOULD_LOCK_ACCOUNT, properties, callContext, internalCallContext);
        paymentTransaction = findPaymentTransaction(payment, paymentTransactionExternalKey);
        return payment;
    } catch (PaymentApiException e) {
        exception = e;
        throw 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, null, exception);
    }
}
Also used : InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) UUID(java.util.UUID)

Example 20 with InternalCallContext

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

the class DefaultPaymentApi method createVoid.

@Override
public Payment createVoid(final Account account, final UUID paymentId, @Nullable final String paymentTransactionExternalKey, final Iterable<PluginProperty> properties, final CallContext callContext) throws PaymentApiException {
    checkNotNullParameter(account, "account");
    checkNotNullParameter(paymentId, "paymentId");
    checkNotNullParameter(properties, "plugin properties");
    checkExternalKeyLength(paymentTransactionExternalKey);
    final String transactionType = TransactionType.VOID.name();
    Payment payment = null;
    PaymentTransaction paymentTransaction = null;
    PaymentApiException exception = null;
    try {
        logEnterAPICall(log, transactionType, account, null, paymentId, null, null, null, null, paymentTransactionExternalKey, null, null);
        final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(account.getId(), callContext);
        payment = paymentProcessor.createVoid(IS_API_PAYMENT, NULL_ATTEMPT_ID, account, paymentId, paymentTransactionExternalKey, null, SHOULD_LOCK_ACCOUNT, properties, callContext, internalCallContext);
        paymentTransaction = findPaymentTransaction(payment, paymentTransactionExternalKey);
        return payment;
    } catch (PaymentApiException e) {
        exception = e;
        throw 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, null, exception);
    }
}
Also used : InternalCallContext(org.killbill.billing.callcontext.InternalCallContext)

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