use of org.killbill.billing.payment.dao.PaymentTransactionModelDao in project killbill by killbill.
the class PluginControlPaymentProcessor method notifyPendingPaymentOfStateChanged.
public Payment notifyPendingPaymentOfStateChanged(final boolean isApiPayment, final Account account, final UUID paymentTransactionId, final boolean isSuccess, final List<String> paymentControlPluginNames, final CallContext callContext, final InternalCallContext internalCallContext) throws PaymentApiException {
final PaymentTransactionModelDao paymentTransactionModelDao = paymentDao.getPaymentTransaction(paymentTransactionId, internalCallContext);
final List<PaymentAttemptModelDao> attempts = paymentDao.getPaymentAttemptByTransactionExternalKey(paymentTransactionModelDao.getTransactionExternalKey(), internalCallContext);
final PaymentAttemptModelDao attempt = Iterables.find(attempts, new Predicate<PaymentAttemptModelDao>() {
@Override
public boolean apply(final PaymentAttemptModelDao input) {
return input.getTransactionId().equals(paymentTransactionId);
}
});
final Iterable<PluginProperty> pluginProperties;
try {
pluginProperties = PluginPropertySerializer.deserialize(attempt.getPluginProperties());
} catch (final PluginPropertySerializerException e) {
throw new PaymentApiException(e, ErrorCode.PAYMENT_INTERNAL_ERROR, String.format("Unable to deserialize payment attemptId='%s' properties", attempt.getId()));
}
return pluginControlledPaymentAutomatonRunner.run(isApiPayment, isSuccess, paymentTransactionModelDao.getTransactionType(), ControlOperation.NOTIFICATION_OF_STATE_CHANGE, account, attempt.getPaymentMethodId(), paymentTransactionModelDao.getPaymentId(), attempt.getPaymentExternalKey(), paymentTransactionId, paymentTransactionModelDao.getTransactionExternalKey(), paymentTransactionModelDao.getAmount(), paymentTransactionModelDao.getCurrency(), pluginProperties, paymentControlPluginNames, callContext, internalCallContext);
}
use of org.killbill.billing.payment.dao.PaymentTransactionModelDao in project killbill by killbill.
the class PaymentAutomatonDAOHelper method buildNewPaymentTransactionModelDao.
private PaymentTransactionModelDao buildNewPaymentTransactionModelDao(final UUID paymentId) {
final DateTime createdDate = utcNow;
final DateTime updatedDate = utcNow;
final DateTime effectiveDate = utcNow;
final String gatewayErrorCode = null;
final String gatewayErrorMsg = null;
if (paymentStateContext.getPaymentTransactionIdForNewPaymentTransaction() != null) {
return new PaymentTransactionModelDao(paymentStateContext.getPaymentTransactionIdForNewPaymentTransaction(), createdDate, updatedDate, paymentStateContext.getAttemptId(), paymentStateContext.getPaymentTransactionExternalKey(), paymentId, paymentStateContext.getTransactionType(), effectiveDate, TransactionStatus.UNKNOWN, paymentStateContext.getAmount(), paymentStateContext.getCurrency(), gatewayErrorCode, gatewayErrorMsg);
} else {
return new PaymentTransactionModelDao(createdDate, updatedDate, paymentStateContext.getAttemptId(), paymentStateContext.getPaymentTransactionExternalKey(), paymentId, paymentStateContext.getTransactionType(), effectiveDate, TransactionStatus.UNKNOWN, paymentStateContext.getAmount(), paymentStateContext.getCurrency(), gatewayErrorCode, gatewayErrorMsg);
}
}
use of org.killbill.billing.payment.dao.PaymentTransactionModelDao in project killbill by killbill.
the class PaymentOperation method getSumAmount.
protected BigDecimal getSumAmount(final Iterable<PaymentTransactionModelDao> transactions) {
BigDecimal result = BigDecimal.ZERO;
final Iterator<PaymentTransactionModelDao> iterator = transactions.iterator();
while (iterator.hasNext()) {
result = result.add(iterator.next().getAmount());
}
return result;
}
use of org.killbill.billing.payment.dao.PaymentTransactionModelDao in project killbill by killbill.
the class PaymentAutomatonRunner method retrievePaymentId.
// TODO Could we cache these to avoid extra queries in PaymentAutomatonDAOHelper?
private UUID retrievePaymentId(@Nullable final String paymentExternalKey, @Nullable final String paymentTransactionExternalKey, final InternalCallContext internalCallContext) throws PaymentApiException {
if (paymentExternalKey != null) {
final PaymentModelDao payment = paymentDao.getPaymentByExternalKey(paymentExternalKey, internalCallContext);
if (payment != null) {
return payment.getId();
}
}
if (paymentTransactionExternalKey == null) {
return null;
}
final List<PaymentTransactionModelDao> paymentTransactionModelDaos = paymentDao.getPaymentTransactionsByExternalKey(paymentTransactionExternalKey, internalCallContext);
for (final PaymentTransactionModelDao paymentTransactionModelDao : paymentTransactionModelDaos) {
if (paymentTransactionModelDao.getTransactionStatus() == TransactionStatus.SUCCESS || paymentTransactionModelDao.getTransactionStatus() == TransactionStatus.PENDING || paymentTransactionModelDao.getTransactionStatus() == TransactionStatus.UNKNOWN) {
return paymentTransactionModelDao.getPaymentId();
}
}
UUID paymentIdCandidate = null;
for (final PaymentTransactionModelDao paymentTransactionModelDao : paymentTransactionModelDaos) {
if (paymentTransactionModelDao.getTransactionStatus() == TransactionStatus.PAYMENT_FAILURE || paymentTransactionModelDao.getTransactionStatus() == TransactionStatus.PLUGIN_FAILURE) {
if (paymentIdCandidate == null) {
paymentIdCandidate = paymentTransactionModelDao.getPaymentId();
} else if (!paymentIdCandidate.equals(paymentTransactionModelDao.getPaymentId())) {
throw new PaymentApiException(ErrorCode.PAYMENT_INTERNAL_ERROR, "Multiple failed payments sharing the same transaction external key - this should never happen");
}
}
}
return paymentIdCandidate;
}
use of org.killbill.billing.payment.dao.PaymentTransactionModelDao in project killbill by killbill.
the class TestRetryablePayment method testRetryLogicFromRetriedStateWithSuccess.
@Test(groups = "fast")
public void testRetryLogicFromRetriedStateWithSuccess() throws PaymentApiException {
mockRetryProviderPlugin.setAborted(false).setNextRetryDate(null);
mockRetryAuthorizeOperationCallback.setResult(OperationResult.SUCCESS).setException(null);
runner.setOperationCallback(mockRetryAuthorizeOperationCallback).setContext(paymentStateContext);
final State state = retrySMHelper.getRetriedState();
final UUID transactionId = UUID.randomUUID();
final UUID paymentId = UUID.randomUUID();
final PaymentAttemptModelDao attempt = new PaymentAttemptModelDao(account.getId(), paymentMethodId, utcNow, utcNow, paymentExternalKey, transactionId, paymentTransactionExternalKey, TransactionType.AUTHORIZE, state.getName(), amount, currency, null, EMPTY_PROPERTIES);
paymentDao.insertPaymentAttemptWithProperties(attempt, internalCallContext);
paymentDao.insertPaymentWithFirstTransaction(new PaymentModelDao(paymentId, utcNow, utcNow, account.getId(), paymentMethodId, -1, paymentExternalKey), new PaymentTransactionModelDao(transactionId, attempt.getId(), paymentTransactionExternalKey, utcNow, utcNow, paymentId, TransactionType.AUTHORIZE, utcNow, TransactionStatus.PAYMENT_FAILURE, amount, currency, "bla", "foo"), internalCallContext);
processor.retryPaymentTransaction(attempt.getId(), ImmutableList.<String>of(MockPaymentControlProviderPlugin.PLUGIN_NAME), internalCallContext);
final List<PaymentAttemptModelDao> pas = paymentDao.getPaymentAttemptByTransactionExternalKey(paymentTransactionExternalKey, internalCallContext);
assertEquals(pas.size(), 2);
final PaymentAttemptModelDao successfulAttempt = Iterables.tryFind(pas, new Predicate<PaymentAttemptModelDao>() {
@Override
public boolean apply(final PaymentAttemptModelDao input) {
return input.getTransactionType() == TransactionType.AUTHORIZE && input.getStateName().equals("SUCCESS");
}
}).orNull();
assertNotNull(successfulAttempt);
}
Aggregations