use of org.killbill.billing.payment.retry.PaymentRetryNotificationKey in project killbill by killbill.
the class PaymentProcessor method getPaymentAttempts.
private List<PaymentAttempt> getPaymentAttempts(final List<PaymentAttemptModelDao> pastPaymentAttempts, final InternalTenantContext internalTenantContext) {
List<PaymentAttempt> paymentAttempts = new ArrayList<PaymentAttempt>();
// Add Past Payment Attempts
for (PaymentAttemptModelDao pastPaymentAttempt : pastPaymentAttempts) {
DefaultPaymentAttempt paymentAttempt = new DefaultPaymentAttempt(pastPaymentAttempt.getAccountId(), pastPaymentAttempt.getPaymentMethodId(), pastPaymentAttempt.getId(), pastPaymentAttempt.getCreatedDate(), pastPaymentAttempt.getUpdatedDate(), pastPaymentAttempt.getCreatedDate(), pastPaymentAttempt.getPaymentExternalKey(), pastPaymentAttempt.getTransactionId(), pastPaymentAttempt.getTransactionExternalKey(), pastPaymentAttempt.getTransactionType(), pastPaymentAttempt.getStateName(), pastPaymentAttempt.getAmount(), pastPaymentAttempt.getCurrency(), pastPaymentAttempt.getPluginName(), buildPluginProperties(pastPaymentAttempt));
paymentAttempts.add(paymentAttempt);
}
// Get Future Payment Attempts from Notification Queue and add them to the list
try {
final NotificationQueue retryQueue = notificationQueueService.getNotificationQueue(DefaultPaymentService.SERVICE_NAME, DefaultRetryService.QUEUE_NAME);
final Iterable<NotificationEventWithMetadata<NotificationEvent>> notificationEventWithMetadatas = retryQueue.getFutureNotificationForSearchKeys(internalTenantContext.getAccountRecordId(), internalTenantContext.getTenantRecordId());
for (final NotificationEventWithMetadata<NotificationEvent> notificationEvent : notificationEventWithMetadatas) {
// Last Attempt
PaymentAttemptModelDao lastPaymentAttempt = getLastPaymentAttempt(pastPaymentAttempts, ((PaymentRetryNotificationKey) notificationEvent.getEvent()).getAttemptId());
if (lastPaymentAttempt != null) {
DefaultPaymentAttempt futurePaymentAttempt = new DefaultPaymentAttempt(// accountId
lastPaymentAttempt.getAccountId(), // paymentMethodId
lastPaymentAttempt.getPaymentMethodId(), // id
((PaymentRetryNotificationKey) notificationEvent.getEvent()).getAttemptId(), // createdDate
null, // updatedDate
null, // effectiveDate
notificationEvent.getEffectiveDate(), // paymentExternalKey
lastPaymentAttempt.getPaymentExternalKey(), // transactionId
null, // transactionExternalKey
lastPaymentAttempt.getTransactionExternalKey(), // transactionType
lastPaymentAttempt.getTransactionType(), // stateName
SCHEDULED, // amount
lastPaymentAttempt.getAmount(), // currency
lastPaymentAttempt.getCurrency(), // pluginName,
((PaymentRetryNotificationKey) notificationEvent.getEvent()).getPaymentControlPluginNames().get(0), // pluginProperties
buildPluginProperties(lastPaymentAttempt));
paymentAttempts.add(futurePaymentAttempt);
}
}
} catch (NoSuchNotificationQueue noSuchNotificationQueue) {
log.error("ERROR Loading Notification Queue - " + noSuchNotificationQueue.getMessage());
}
return paymentAttempts;
}
Aggregations