Search in sources :

Example 1 with DefaultPaymentTransaction

use of org.killbill.billing.payment.api.DefaultPaymentTransaction in project killbill by killbill.

the class MockRetryAuthorizeOperationCallback method doCallSpecificOperationCallback.

@Override
protected Payment doCallSpecificOperationCallback() throws PaymentApiException {
    if (exception != null) {
        if (exception instanceof PaymentApiException) {
            throw (PaymentApiException) exception;
        } else if (exception instanceof RuntimeException) {
            throw (RuntimeException) exception;
        } else {
            throw new RuntimeException(exception);
        }
    }
    final PaymentModelDao payment = new PaymentModelDao(clock.getUTCNow(), clock.getUTCNow(), paymentStateContext.getAccount().getId(), paymentStateContext.getPaymentMethodId(), paymentStateContext.getPaymentExternalKey());
    final PaymentTransactionModelDao transaction = new PaymentTransactionModelDao(clock.getUTCNow(), clock.getUTCNow(), paymentStateContext.getAttemptId(), paymentStateContext.getPaymentTransactionExternalKey(), paymentStateContext.getPaymentId(), paymentStateContext.getTransactionType(), clock.getUTCNow(), TransactionStatus.SUCCESS, paymentStateContext.getAmount(), paymentStateContext.getCurrency(), "", "");
    final PaymentModelDao paymentModelDao = paymentDao.insertPaymentWithFirstTransaction(payment, transaction, paymentStateContext.getInternalCallContext());
    final PaymentTransaction convertedTransaction = new DefaultPaymentTransaction(transaction.getId(), paymentStateContext.getAttemptId(), transaction.getTransactionExternalKey(), transaction.getCreatedDate(), transaction.getUpdatedDate(), transaction.getPaymentId(), transaction.getTransactionType(), transaction.getEffectiveDate(), transaction.getTransactionStatus(), transaction.getAmount(), transaction.getCurrency(), transaction.getProcessedAmount(), transaction.getProcessedCurrency(), transaction.getGatewayErrorCode(), transaction.getGatewayErrorMsg(), null);
    return new DefaultPayment(paymentModelDao.getId(), paymentModelDao.getCreatedDate(), paymentModelDao.getUpdatedDate(), paymentModelDao.getAccountId(), paymentModelDao.getPaymentMethodId(), paymentModelDao.getPaymentNumber(), paymentModelDao.getExternalKey(), Collections.singletonList(convertedTransaction), null);
}
Also used : DefaultPaymentTransaction(org.killbill.billing.payment.api.DefaultPaymentTransaction) PaymentTransaction(org.killbill.billing.payment.api.PaymentTransaction) DefaultPayment(org.killbill.billing.payment.api.DefaultPayment) PaymentTransactionModelDao(org.killbill.billing.payment.dao.PaymentTransactionModelDao) PaymentModelDao(org.killbill.billing.payment.dao.PaymentModelDao) DefaultPaymentTransaction(org.killbill.billing.payment.api.DefaultPaymentTransaction) PaymentApiException(org.killbill.billing.payment.api.PaymentApiException)

Example 2 with DefaultPaymentTransaction

use of org.killbill.billing.payment.api.DefaultPaymentTransaction in project killbill by killbill.

the class PaymentProcessor method toPayment.

// Used in bulk get API (getAccountPayments)
private Payment toPayment(final PaymentModelDao curPaymentModelDao, final Collection<PaymentTransactionModelDao> curTransactionsModelDao, @Nullable final Iterable<PaymentTransactionInfoPlugin> pluginTransactions, final boolean withAttempts, final InternalTenantContext internalTenantContext) {
    final Collection<PaymentTransactionModelDao> transactionsModelDao = new LinkedList<PaymentTransactionModelDao>(curTransactionsModelDao);
    invokeJanitor(curPaymentModelDao, transactionsModelDao, pluginTransactions, internalTenantContext);
    final Collection<PaymentTransaction> transactions = new LinkedList<PaymentTransaction>();
    for (final PaymentTransactionModelDao newPaymentTransactionModelDao : transactionsModelDao) {
        final PaymentTransactionInfoPlugin paymentTransactionInfoPlugin = findPaymentTransactionInfoPlugin(newPaymentTransactionModelDao, pluginTransactions);
        final PaymentTransaction transaction = new DefaultPaymentTransaction(newPaymentTransactionModelDao.getId(), newPaymentTransactionModelDao.getAttemptId(), newPaymentTransactionModelDao.getTransactionExternalKey(), newPaymentTransactionModelDao.getCreatedDate(), newPaymentTransactionModelDao.getUpdatedDate(), newPaymentTransactionModelDao.getPaymentId(), newPaymentTransactionModelDao.getTransactionType(), newPaymentTransactionModelDao.getEffectiveDate(), newPaymentTransactionModelDao.getTransactionStatus(), newPaymentTransactionModelDao.getAmount(), newPaymentTransactionModelDao.getCurrency(), newPaymentTransactionModelDao.getProcessedAmount(), newPaymentTransactionModelDao.getProcessedCurrency(), newPaymentTransactionModelDao.getGatewayErrorCode(), newPaymentTransactionModelDao.getGatewayErrorMsg(), paymentTransactionInfoPlugin);
        transactions.add(transaction);
    }
    final Ordering<PaymentTransaction> perPaymentTransactionOrdering = Ordering.<PaymentTransaction>from(new Comparator<PaymentTransaction>() {

        @Override
        public int compare(final PaymentTransaction o1, final PaymentTransaction o2) {
            return o1.getEffectiveDate().compareTo(o2.getEffectiveDate());
        }
    });
    final List<PaymentTransaction> sortedTransactions = perPaymentTransactionOrdering.immutableSortedCopy(transactions);
    return new DefaultPayment(curPaymentModelDao.getId(), curPaymentModelDao.getCreatedDate(), curPaymentModelDao.getUpdatedDate(), curPaymentModelDao.getAccountId(), curPaymentModelDao.getPaymentMethodId(), curPaymentModelDao.getPaymentNumber(), curPaymentModelDao.getExternalKey(), sortedTransactions, (withAttempts && !sortedTransactions.isEmpty()) ? getPaymentAttempts(paymentDao.getPaymentAttempts(curPaymentModelDao.getExternalKey(), internalTenantContext), internalTenantContext) : null);
}
Also used : DefaultPaymentTransaction(org.killbill.billing.payment.api.DefaultPaymentTransaction) PaymentTransaction(org.killbill.billing.payment.api.PaymentTransaction) DefaultPayment(org.killbill.billing.payment.api.DefaultPayment) PaymentTransactionModelDao(org.killbill.billing.payment.dao.PaymentTransactionModelDao) DefaultPaymentTransaction(org.killbill.billing.payment.api.DefaultPaymentTransaction) PaymentTransactionInfoPlugin(org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin) LinkedList(java.util.LinkedList)

Aggregations

DefaultPayment (org.killbill.billing.payment.api.DefaultPayment)2 DefaultPaymentTransaction (org.killbill.billing.payment.api.DefaultPaymentTransaction)2 PaymentTransaction (org.killbill.billing.payment.api.PaymentTransaction)2 PaymentTransactionModelDao (org.killbill.billing.payment.dao.PaymentTransactionModelDao)2 LinkedList (java.util.LinkedList)1 PaymentApiException (org.killbill.billing.payment.api.PaymentApiException)1 PaymentModelDao (org.killbill.billing.payment.dao.PaymentModelDao)1 PaymentTransactionInfoPlugin (org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin)1