use of org.killbill.billing.invoice.dao.InvoicePaymentModelDao in project killbill by killbill.
the class DefaultInvoiceInternalApi method recordPaymentAttemptCompletion.
@Override
public void recordPaymentAttemptCompletion(final UUID invoiceId, final BigDecimal amount, final Currency currency, final Currency processedCurrency, final UUID paymentId, final String transactionExternalKey, final DateTime paymentDate, final boolean success, final InternalCallContext context) throws InvoiceApiException {
final InvoicePayment invoicePayment = new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, paymentId, invoiceId, paymentDate, amount, currency, processedCurrency, transactionExternalKey, success);
dao.notifyOfPaymentCompletion(new InvoicePaymentModelDao(invoicePayment), context);
}
use of org.killbill.billing.invoice.dao.InvoicePaymentModelDao in project killbill by killbill.
the class DefaultInvoiceInternalApi method recordPaymentAttemptInit.
@Override
public void recordPaymentAttemptInit(final UUID invoiceId, final BigDecimal amount, final Currency currency, final Currency processedCurrency, final UUID paymentId, final String transactionExternalKey, final DateTime paymentDate, final InternalCallContext context) throws InvoiceApiException {
final InvoicePayment invoicePayment = new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, paymentId, invoiceId, paymentDate, amount, currency, processedCurrency, transactionExternalKey, false);
dao.notifyOfPaymentInit(new InvoicePaymentModelDao(invoicePayment), context);
}
use of org.killbill.billing.invoice.dao.InvoicePaymentModelDao in project killbill by killbill.
the class DefaultInvoiceInternalApi method recordRefund.
@Override
public InvoicePayment recordRefund(final UUID paymentId, final BigDecimal amount, final boolean isInvoiceAdjusted, final Map<UUID, BigDecimal> invoiceItemIdsWithAmounts, final String transactionExternalKey, final InternalCallContext context) throws InvoiceApiException {
if (amount.compareTo(BigDecimal.ZERO) <= 0) {
throw new InvoiceApiException(ErrorCode.PAYMENT_REFUND_AMOUNT_NEGATIVE_OR_NULL, paymentId, amount);
}
final InvoicePaymentModelDao refund = dao.createRefund(paymentId, amount, isInvoiceAdjusted, invoiceItemIdsWithAmounts, transactionExternalKey, context);
// See https://github.com/killbill/killbill/issues/265
final CallContext callContext = internalCallContextFactory.createCallContext(context);
final Invoice invoice = getInvoiceById(refund.getInvoiceId(), context);
final UUID accountId = invoice.getAccountId();
final WithAccountLock withAccountLock = new WithAccountLock() {
@Override
public Iterable<Invoice> prepareInvoices() throws InvoiceApiException {
return ImmutableList.<Invoice>of(invoice);
}
};
final List<InvoiceItem> createdInvoiceItems = invoiceApiHelper.dispatchToInvoicePluginsAndInsertItems(accountId, false, withAccountLock, callContext);
return new DefaultInvoicePayment(refund);
}
use of org.killbill.billing.invoice.dao.InvoicePaymentModelDao in project killbill by killbill.
the class DefaultInvoiceInternalApi method getInvoicePayment.
private InvoicePayment getInvoicePayment(final UUID paymentId, final InvoicePaymentType type, final InternalTenantContext context) throws InvoiceApiException {
final List<InvoicePaymentModelDao> invoicePayments = dao.getInvoicePaymentsByPaymentId(paymentId, context);
final InvoicePaymentModelDao resultOrNull = Iterables.tryFind(invoicePayments, new Predicate<InvoicePaymentModelDao>() {
@Override
public boolean apply(final InvoicePaymentModelDao input) {
return input.getType() == type && input.getSuccess();
}
}).orNull();
return resultOrNull != null ? new DefaultInvoicePayment(resultOrNull) : null;
}
Aggregations