Search in sources :

Example 1 with PaymentAndTransactionModelDao

use of org.killbill.billing.payment.dao.PaymentAndTransactionModelDao in project killbill by killbill.

the class PaymentAutomatonDAOHelper method createNewPaymentTransaction.

public void createNewPaymentTransaction() throws PaymentApiException {
    final PaymentTransactionModelDao paymentTransactionModelDao;
    final List<PaymentTransactionModelDao> existingTransactions;
    if (paymentStateContext.getPaymentId() == null) {
        final PaymentModelDao newPaymentModelDao = buildNewPaymentModelDao();
        final PaymentTransactionModelDao newPaymentTransactionModelDao = buildNewPaymentTransactionModelDao(newPaymentModelDao.getId());
        existingTransactions = ImmutableList.of();
        final PaymentAndTransactionModelDao paymentAndTransactionModelDao = paymentDao.insertPaymentWithFirstTransaction(newPaymentModelDao, newPaymentTransactionModelDao, internalCallContext);
        paymentTransactionModelDao = paymentAndTransactionModelDao.getPaymentTransactionModelDao();
    } else {
        existingTransactions = paymentDao.getTransactionsForPayment(paymentStateContext.getPaymentId(), internalCallContext);
        if (existingTransactions.isEmpty()) {
            throw new PaymentApiException(ErrorCode.PAYMENT_NO_SUCH_SUCCESS_PAYMENT, paymentStateContext.getPaymentId());
        }
        if (paymentStateContext.getCurrency() != null && existingTransactions.get(0).getCurrency() != paymentStateContext.getCurrency() && !TransactionType.CHARGEBACK.equals(paymentStateContext.getTransactionType())) {
            // Note that we allow chargebacks in a different currency
            throw new PaymentApiException(ErrorCode.PAYMENT_INVALID_PARAMETER, "currency", " should be " + existingTransactions.get(0).getCurrency() + " to match other existing transactions");
        }
        final PaymentTransactionModelDao newPaymentTransactionModelDao = buildNewPaymentTransactionModelDao(paymentStateContext.getPaymentId());
        paymentTransactionModelDao = paymentDao.updatePaymentWithNewTransaction(paymentStateContext.getPaymentId(), newPaymentTransactionModelDao, internalCallContext);
    }
    // Update the context
    paymentStateContext.setPaymentTransactionModelDao(paymentTransactionModelDao);
    paymentStateContext.setOnLeavingStateExistingTransactions(existingTransactions);
}
Also used : PaymentTransactionModelDao(org.killbill.billing.payment.dao.PaymentTransactionModelDao) PaymentModelDao(org.killbill.billing.payment.dao.PaymentModelDao) PaymentAndTransactionModelDao(org.killbill.billing.payment.dao.PaymentAndTransactionModelDao) PaymentApiException(org.killbill.billing.payment.api.PaymentApiException)

Example 2 with PaymentAndTransactionModelDao

use of org.killbill.billing.payment.dao.PaymentAndTransactionModelDao in project killbill by killbill.

the class PaymentAutomatonDAOHelper method processPaymentInfoPlugin.

public void processPaymentInfoPlugin(final TransactionStatus transactionStatus, @Nullable final PaymentTransactionInfoPlugin paymentInfoPlugin, final String currentPaymentStateName) {
    final PaymentAndTransactionModelDao paymentAndTransactionModelDao = processPaymentInfoPlugin(transactionStatus, paymentInfoPlugin, currentPaymentStateName, paymentStateContext.getAmount(), paymentStateContext.getCurrency(), paymentStateContext.getAccount().getId(), paymentStateContext.getAttemptId(), paymentStateContext.getPaymentId(), paymentStateContext.getPaymentTransactionModelDao().getId(), paymentStateContext.getTransactionType(), paymentStateContext.isApiPayment());
    // Update the context
    paymentStateContext.setPaymentModelDao(paymentAndTransactionModelDao.getPaymentModelDao());
    paymentStateContext.setPaymentTransactionModelDao(paymentAndTransactionModelDao.getPaymentTransactionModelDao());
}
Also used : PaymentAndTransactionModelDao(org.killbill.billing.payment.dao.PaymentAndTransactionModelDao)

Example 3 with PaymentAndTransactionModelDao

use of org.killbill.billing.payment.dao.PaymentAndTransactionModelDao in project killbill by killbill.

the class PaymentAutomatonDAOHelper method processPaymentInfoPlugin.

public PaymentAndTransactionModelDao processPaymentInfoPlugin(final TransactionStatus transactionStatus, @Nullable final PaymentTransactionInfoPlugin paymentInfoPlugin, final String currentPaymentStateName, @Nullable final String lastSuccessPaymentState, final BigDecimal defaultSuccessfulProcessedAmount, final Currency defaultProcessedCurrency, final UUID accountId, final UUID attemptId, final UUID paymentId, final UUID transactionId, final TransactionType transactionType, final boolean isApiPayment, final boolean forceOverrideLastSuccessPaymentState) {
    final BigDecimal processedAmount;
    if (TransactionStatus.SUCCESS.equals(transactionStatus) || TransactionStatus.PENDING.equals(transactionStatus)) {
        if (paymentInfoPlugin == null || paymentInfoPlugin.getAmount() == null) {
            processedAmount = defaultSuccessfulProcessedAmount;
        } else {
            processedAmount = paymentInfoPlugin.getAmount();
        }
    } else {
        processedAmount = BigDecimal.ZERO;
    }
    final Currency processedCurrency;
    if (paymentInfoPlugin == null || paymentInfoPlugin.getCurrency() == null) {
        processedCurrency = defaultProcessedCurrency;
    } else {
        processedCurrency = paymentInfoPlugin.getCurrency();
    }
    final String gatewayErrorCode = paymentInfoPlugin == null ? null : paymentInfoPlugin.getGatewayErrorCode();
    final String gatewayErrorMsg = paymentInfoPlugin == null ? null : paymentInfoPlugin.getGatewayError();
    final PaymentAndTransactionModelDao paymentAndTransactionModelDao;
    if (lastSuccessPaymentState != null || forceOverrideLastSuccessPaymentState) {
        paymentAndTransactionModelDao = paymentDao.updatePaymentAndTransactionOnCompletion(accountId, attemptId, paymentId, transactionType, currentPaymentStateName, lastSuccessPaymentState, transactionId, transactionStatus, processedAmount, processedCurrency, gatewayErrorCode, gatewayErrorMsg, isApiPayment, internalCallContext);
    } else {
        paymentAndTransactionModelDao = paymentDao.updatePaymentAndTransactionOnCompletion(accountId, attemptId, paymentId, transactionType, currentPaymentStateName, transactionId, transactionStatus, processedAmount, processedCurrency, gatewayErrorCode, gatewayErrorMsg, isApiPayment, internalCallContext);
    }
    return paymentAndTransactionModelDao;
}
Also used : Currency(org.killbill.billing.catalog.api.Currency) PaymentAndTransactionModelDao(org.killbill.billing.payment.dao.PaymentAndTransactionModelDao) BigDecimal(java.math.BigDecimal)

Aggregations

PaymentAndTransactionModelDao (org.killbill.billing.payment.dao.PaymentAndTransactionModelDao)3 BigDecimal (java.math.BigDecimal)1 Currency (org.killbill.billing.catalog.api.Currency)1 PaymentApiException (org.killbill.billing.payment.api.PaymentApiException)1 PaymentModelDao (org.killbill.billing.payment.dao.PaymentModelDao)1 PaymentTransactionModelDao (org.killbill.billing.payment.dao.PaymentTransactionModelDao)1