Search in sources :

Example 1 with Account

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.Account in project openbanking-aspsp by OpenBankingToolkit.

the class AcceptDueScheduledPaymentTask method moveDebitPayment.

private String moveDebitPayment(FRScheduledPayment payment) throws CurrencyConverterException {
    Account accountFrom = accountStoreService.getAccount(payment.getAccountId());
    log.info("We are going to pay from this account: {}", accountFrom);
    moneyService.moveMoney(accountFrom, payment.getScheduledPayment().getInstructedAmount(), FRCreditDebitIndicator.DEBIT, payment, this::createTransaction);
    String identificationFrom = payment.getScheduledPayment().getCreditorAccount().getIdentification();
    log.debug("Find if the 'to' account '{}' is own by this ASPSP", identificationFrom);
    return identificationFrom;
}
Also used : Account(com.forgerock.openbanking.common.model.openbanking.persistence.account.Account)

Example 2 with Account

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.Account in project openbanking-aspsp by OpenBankingToolkit.

the class AcceptDueStandingOrderTask method moveDebitPayment.

private void moveDebitPayment(FRStandingOrder payment, FRAmount amount) throws CurrencyConverterException {
    Account accountTo = accountStoreService.getAccount(payment.getAccountId());
    log.info("We are going to pay from this account: {}", accountTo);
    moneyService.moveMoney(accountTo, amount, FRCreditDebitIndicator.DEBIT, payment, this::createTransaction);
}
Also used : Account(com.forgerock.openbanking.common.model.openbanking.persistence.account.Account)

Example 3 with Account

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.Account in project openbanking-aspsp by OpenBankingToolkit.

the class AcceptInternationalPaymentTask method moveDebitPayment.

private String moveDebitPayment(FRInternationalConsent 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;
}
Also used : Account(com.forgerock.openbanking.common.model.openbanking.persistence.account.Account)

Example 4 with Account

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.Account in project openbanking-aspsp by OpenBankingToolkit.

the class AcceptInternationalPaymentTask method autoAcceptPayment.

@Scheduled(fixedRate = 60 * 1000)
@SchedulerLock(name = "internationalPayment")
public void autoAcceptPayment() {
    log.info("Auto-accept payment task waking up. The time is now {}.", format.print(DateTime.now()));
    Collection<FRInternationalConsent> allPaymentsInProcess = internationalPaymentService.getAllPaymentsInProcess();
    for (FRInternationalConsent payment : allPaymentsInProcess) {
        log.info("Processing payment {}", payment);
        try {
            String identificationTo = moveDebitPayment(payment);
            Optional<Account> isAccountToFromOurs = accountStoreService.findAccountByIdentification(identificationTo);
            if (isAccountToFromOurs.isPresent()) {
                moveCreditPayment(payment, identificationTo, isAccountToFromOurs.get());
            } else {
                log.info("Account '{}' not ours", identificationTo);
            }
            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 {
            internationalPaymentService.updatePayment(payment);
            paymentNotificationService.paymentStatusChanged(payment);
        }
    }
    log.info("All payments in process are now accepted. See you in 1 minute! The time is now {}.", format.print(DateTime.now()));
}
Also used : Account(com.forgerock.openbanking.common.model.openbanking.persistence.account.Account) CurrencyConverterException(com.tunyk.currencyconverter.api.CurrencyConverterException) FRInternationalConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent) CurrencyConverterException(com.tunyk.currencyconverter.api.CurrencyConverterException) Scheduled(org.springframework.scheduling.annotation.Scheduled) SchedulerLock(net.javacrumbs.shedlock.core.SchedulerLock)

Example 5 with Account

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.Account in project openbanking-aspsp by OpenBankingToolkit.

the class AcceptDomesticPaymentTask method autoAcceptPayment.

@Scheduled(fixedRate = 60 * 1000)
@SchedulerLock(name = "domesticPayment")
public void autoAcceptPayment() {
    log.info("Auto-accept payment task waking up. The time is now {}.", format.print(DateTime.now()));
    Collection<FRDomesticConsent> allPaymentsInProcess = domesticPaymentsService.getAllPaymentsInProcess();
    for (FRDomesticConsent payment : allPaymentsInProcess) {
        log.info("Processing payment {}", payment);
        try {
            String identificationTo = moveDebitPayment(payment);
            Optional<Account> isAccountToFromOurs = accountStoreService.findAccountByIdentification(identificationTo);
            if (isAccountToFromOurs.isPresent()) {
                moveCreditPayment(payment, identificationTo, isAccountToFromOurs.get());
            } else {
                log.info("Account '{}' not ours", identificationTo);
            }
            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 {
            domesticPaymentsService.updatePayment(payment);
            paymentNotificationService.paymentStatusChanged(payment);
        }
    }
    log.info("All payments in process are now accepted. See you in 1 minute! The time is now {}.", format.print(DateTime.now()));
}
Also used : Account(com.forgerock.openbanking.common.model.openbanking.persistence.account.Account) CurrencyConverterException(com.tunyk.currencyconverter.api.CurrencyConverterException) FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) CurrencyConverterException(com.tunyk.currencyconverter.api.CurrencyConverterException) Scheduled(org.springframework.scheduling.annotation.Scheduled) SchedulerLock(net.javacrumbs.shedlock.core.SchedulerLock)

Aggregations

Account (com.forgerock.openbanking.common.model.openbanking.persistence.account.Account)10 CurrencyConverterException (com.tunyk.currencyconverter.api.CurrencyConverterException)5 SchedulerLock (net.javacrumbs.shedlock.core.SchedulerLock)5 Scheduled (org.springframework.scheduling.annotation.Scheduled)5 FRScheduledPaymentData (com.forgerock.openbanking.common.model.openbanking.domain.account.FRScheduledPaymentData)1 FRFilePayment (com.forgerock.openbanking.common.model.openbanking.forgerock.filepayment.v3_0.FRFilePayment)1 FRScheduledPayment (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRScheduledPayment)1 FRDomesticConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent)1 FRFileConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent)1 FRInternationalConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent)1 FRPaymentSetup (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup)1