use of com.forgerock.openbanking.common.model.openbanking.persistence.account.Account in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptDomesticPaymentTask method moveDebitPayment.
private String moveDebitPayment(FRDomesticConsent payment) throws CurrencyConverterException {
Account accountFrom = accountStoreService.getAccount(payment.getAccountId());
log.info("We are going to pay from this account: {}", accountFrom);
moneyService.moveMoney(accountFrom, payment.getInitiation().getInstructedAmount(), FRCreditDebitIndicator.DEBIT, payment, this::createTransaction);
String identificationFrom = payment.getInitiation().getCreditorAccount().getIdentification();
log.debug("Find if the 'to' account '{}' is own by this ASPSP", identificationFrom);
return identificationFrom;
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.Account in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptDueScheduledPaymentTask method payDueScheduledPayments.
@Scheduled(fixedRate = 60 * 1000)
@SchedulerLock(name = "payDueScheduledPayments")
public void payDueScheduledPayments() {
log.info("Scheduled payments payment task waking up. The time is now {}.", format.print(DateTime.now()));
for (FRScheduledPayment scheduledPayment : scheduledPaymentService.getPendingAndDueScheduledPayments()) {
FRScheduledPaymentData payment = scheduledPayment.getScheduledPayment();
if (!payment.getScheduledPaymentDateTime().isBefore(DateTime.now())) {
log.warn("Scheduled payment: {} with scheduledPaymentDateTime: {} is not due yet and should not have been loaded", scheduledPayment.getId(), payment.getScheduledPaymentDateTime());
continue;
}
log.info("Processing scheduled payment {}", payment);
try {
String identificationFrom = moveDebitPayment(scheduledPayment);
Optional<Account> isAccountFromOurs = accountStoreService.findAccountByIdentification(identificationFrom);
if (isAccountFromOurs.isPresent()) {
moveCreditPayment(scheduledPayment, identificationFrom, isAccountFromOurs.get());
} else {
log.info("Account '{}' not ours", identificationFrom);
}
log.info("Update payment status to completed");
scheduledPayment.setStatus(ScheduledPaymentStatus.COMPLETED);
log.debug("Payment {}", payment);
} catch (CurrencyConverterException e) {
log.info("Can't convert amount in the right currency", e);
log.info("Update payment status to rejected");
scheduledPayment.setRejectionReason("Can't convert amount in the right currency: " + e.getMessage());
scheduledPayment.setStatus(ScheduledPaymentStatus.REJECTED);
log.info("Payment {}", payment);
} catch (Exception e) {
log.error("Couldn't pay scheduled payment.", e);
log.info("Update payment status to rejected");
scheduledPayment.setRejectionReason("Failed to execute payment: " + e.getMessage());
scheduledPayment.setStatus(ScheduledPaymentStatus.REJECTED);
log.info("Payment {}", payment);
} finally {
scheduledPaymentService.updateSchedulePayment(scheduledPayment);
paymentNotificationService.paymentStatusChanged(scheduledPayment);
}
}
log.info("All due scheduled payments are now completed. The time is now {}.", format.print(DateTime.now()));
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.Account in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptFilePaymentTask method autoAcceptPayment.
@Scheduled(fixedRate = 60 * 1000 * 5)
@SchedulerLock(name = "filePayment")
public void autoAcceptPayment() {
log.info("Auto-accept file payment task waking up. The time is now {}.", format.print(DateTime.now()));
final Collection<FRFileConsent> allPaymentsInProcess = filePaymentService.getAllPaymentFilesInProcess();
for (FRFileConsent consent : allPaymentsInProcess) {
log.info("Processing file consent {}", consent);
try {
int paymentNo = 0;
int success = 0;
int reject = 0;
if (consent.getPayments() == null) {
consent.setStatus(ConsentStatusCode.REJECTED);
continue;
}
for (FRFilePayment payment : consent.getPayments()) {
paymentNo++;
try {
if (payment.getStatus() != FRFilePayment.PaymentStatus.PENDING) {
log.debug("Payment '{}' from consent '{}' is not pending", payment, consent.getId());
continue;
}
log.info("Processing pending file payment [{}] : {}", paymentNo, payment);
String identificationTo = moveDebitPayment(payment, consent.getAccountId());
Optional<Account> isAccountToFromOurs = accountStoreService.findAccountByIdentification(identificationTo);
if (isAccountToFromOurs.isPresent()) {
moveCreditPayment(payment, identificationTo, isAccountToFromOurs.get());
} else {
log.info("Account '{}' not ours", identificationTo);
}
log.debug("File payment [{}] succeeded: {}", paymentNo, payment);
success++;
payment.setStatus(FRFilePayment.PaymentStatus.COMPLETED);
} catch (CurrencyConverterException e) {
log.info("Can't convert amount in the right currency for payment within a file. Payment: {}, ConsentId: {}", payment, consent.getId(), e);
log.info("Update individual payment status to rejected - other payments in file may still succeed");
reject++;
payment.setStatus(FRFilePayment.PaymentStatus.REJECTED);
} catch (Exception e) {
log.warn("An individual payment within a file failed. Payment: {}, ConsentId: {}", payment, consent.getId(), e);
log.info("Update individual payment status to rejected - other payments in file may still succeed");
reject++;
payment.setStatus(FRFilePayment.PaymentStatus.REJECTED);
}
}
log.info("Finished file payments for consent: '{}'. {} payments succeeded. {} payments were rejected. Update file consent status to completed", consent.getId(), success, reject);
consent.setStatus(ConsentStatusCode.ACCEPTEDSETTLEMENTCOMPLETED);
log.debug("Consent {}", consent);
} finally {
filePaymentService.updatePayment(consent);
paymentNotificationService.paymentStatusChanged(consent);
}
}
log.info("All file payments in process are now accepted. See you in 5 minutes! The time is now {}.", format.print(DateTime.now()));
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.Account in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptFilePaymentTask method moveDebitPayment.
private String moveDebitPayment(FRFilePayment payment, String accountId) throws CurrencyConverterException {
Account accountFrom = accountStoreService.getAccount(accountId);
log.info("We are going to pay from this account: {}", accountFrom);
moneyService.moveMoney(accountFrom, payment.getInstructedAmount(), FRCreditDebitIndicator.DEBIT, payment, this::createTransaction);
String identificationFrom = payment.getCreditorAccountIdentification();
log.debug("Find if the 'to' account '{}' is own by this ASPSP", identificationFrom);
return identificationFrom;
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.Account in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptSinglePaymentTask method autoAcceptPayment.
@Scheduled(fixedRate = 60 * 1000)
@SchedulerLock(name = "singlePayment")
public void autoAcceptPayment() {
log.info("Auto-accept payment task waking up. The time is now {}.", format.print(DateTime.now()));
Collection<FRPaymentSetup> allPaymentsInProcess = paymentsService.getAllPaymentsInProcess();
for (FRPaymentSetup payment : allPaymentsInProcess) {
log.info("Processing payment {}", payment);
try {
Account accountTo = accountStoreService.getAccount(payment.getAccountId());
String identificationFrom = moveDebitPayment(payment, accountTo);
Optional<Account> isAccountFromOurs = accountStoreService.findAccountByIdentification(identificationFrom);
if (isAccountFromOurs.isPresent()) {
moveCreditPayment(payment, identificationFrom, isAccountFromOurs.get());
} else {
log.info("Account '{}' not ours", identificationFrom);
}
log.info("Update payment status to completed");
payment.setStatus(ConsentStatusCode.ACCEPTEDSETTLEMENTCOMPLETED);
log.info("Payment {}", payment);
} catch (CurrencyConverterException e) {
log.info("Can't convert amount in the right currency", e);
log.info("Update payment status to rejected");
payment.setStatus(ConsentStatusCode.REJECTED);
log.info("Payment {}", payment);
} catch (Exception e) {
log.error("Couldn't auto-pay payment.", e);
log.info("Update payment status to rejected");
payment.setStatus(ConsentStatusCode.REJECTED);
log.info("Payment {}", payment);
} finally {
paymentsService.updatePayment(payment);
paymentNotificationService.paymentStatusChanged(payment);
}
}
log.info("All payments in process are now accepted. See you in a minutes! The time is now {}.", format.print(DateTime.now()));
}
Aggregations