Search in sources :

Example 71 with FRDomesticConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticPaymentConsentsApiController method getDomesticPaymentConsentsConsentId.

@Override
public ResponseEntity getDomesticPaymentConsentsConsentId(@ApiParam(value = "ConsentId", required = true) @PathVariable("ConsentId") String consentId, @ApiParam(value = "The unique id of the ASPSP to which the request is issued. The unique id will be issued by OB.", required = true) @RequestHeader(value = "x-fapi-financial-id", required = true) String xFapiFinancialId, @ApiParam(value = "An Authorisation Token as per https://tools.ietf.org/html/rfc6750", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, @ApiParam(value = "The time when the PSU last logged in with the TPP.  All dates in the HTTP headers are represented as RFC 7231 Full Dates. An example is below:  Sun, 10 Sep 2017 19:43:31 UTC") @RequestHeader(value = "x-fapi-customer-last-logged-time", required = false) @DateTimeFormat(pattern = HTTP_DATE_FORMAT) DateTime xFapiCustomerLastLoggedTime, @ApiParam(value = "The PSU's IP address if the PSU is currently logged in with the TPP.") @RequestHeader(value = "x-fapi-customer-ip-address", required = false) String xFapiCustomerIpAddress, @ApiParam(value = "An RFC4122 UID used as a correlation id.") @RequestHeader(value = "x-fapi-interaction-id", required = false) String xFapiInteractionId, @ApiParam(value = "Indicates the user-agent that the PSU is using.") @RequestHeader(value = "x-customer-user-agent", required = false) String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    Optional<FRDomesticConsent> isDomesticConsent = domesticConsentRepository.findById(consentId);
    if (!isDomesticConsent.isPresent()) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Domestic consent '" + consentId + "' can't be found");
    }
    FRDomesticConsent domesticConsent = isDomesticConsent.get();
    return ResponseEntity.ok(packageResponse(domesticConsent));
}
Also used : FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent)

Example 72 with FRDomesticConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticPaymentsApiController method createDomesticPayments.

@Override
public ResponseEntity createDomesticPayments(@ApiParam(value = "Default", required = true) @Valid @RequestBody OBWriteDomestic2 obWriteDomestic2, @ApiParam(value = "The unique id of the ASPSP to which the request is issued. The unique id will be issued by OB.", required = true) @RequestHeader(value = "x-fapi-financial-id", required = true) String xFapiFinancialId, @ApiParam(value = "An Authorisation Token as per https://tools.ietf.org/html/rfc6750", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, @ApiParam(value = "Every request will be processed only once per x-idempotency-key.  The Idempotency Key will be valid for 24 hours.", required = true) @RequestHeader(value = "x-idempotency-key", required = true) String xIdempotencyKey, @ApiParam(value = "A detached JWS signature of the body of the payload.", required = true) @RequestHeader(value = "x-jws-signature", required = true) String xJwsSignature, @ApiParam(value = "The time when the PSU last logged in with the TPP.  All dates in the HTTP headers are represented as RFC 7231 Full Dates. An example is below:  Sun, 10 Sep 2017 19:43:31 UTC") @RequestHeader(value = "x-fapi-customer-last-logged-time", required = false) @DateTimeFormat(pattern = HTTP_DATE_FORMAT) DateTime xFapiCustomerLastLoggedTime, @ApiParam(value = "The PSU's IP address if the PSU is currently logged in with the TPP.") @RequestHeader(value = "x-fapi-customer-ip-address", required = false) String xFapiCustomerIpAddress, @ApiParam(value = "An RFC4122 UID used as a correlation id.") @RequestHeader(value = "x-fapi-interaction-id", required = false) String xFapiInteractionId, @ApiParam(value = "Indicates the user-agent that the PSU is using.") @RequestHeader(value = "x-customer-user-agent", required = false) String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    log.debug("Received payment submission: '{}'", obWriteDomestic2);
    FRWriteDomestic frWriteDomestic = toFRWriteDomestic(obWriteDomestic2);
    log.trace("Converted to: '{}'", frWriteDomestic);
    String paymentId = obWriteDomestic2.getData().getConsentId();
    FRDomesticConsent paymentConsent = domesticConsentRepository.findById(paymentId).orElseThrow(() -> new OBErrorResponseException(HttpStatus.BAD_REQUEST, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.PAYMENT_CONSENT_BEHIND_SUBMISSION_NOT_FOUND.toOBError1(paymentId)));
    log.debug("Found consent '{}' to match this payment id: {} ", paymentConsent, paymentId);
    FRDomesticPaymentSubmission frPaymentSubmission = FRDomesticPaymentSubmission.builder().id(obWriteDomestic2.getData().getConsentId()).domesticPayment(frWriteDomestic).created(new Date()).updated(new Date()).idempotencyKey(xIdempotencyKey).obVersion(VersionPathExtractor.getVersionFromPath(request)).build();
    frPaymentSubmission = new IdempotentRepositoryAdapter<>(domesticPaymentSubmissionRepository).idempotentSave(frPaymentSubmission);
    return ResponseEntity.status(HttpStatus.CREATED).body(responseEntity(frPaymentSubmission, paymentConsent));
}
Also used : IdempotentRepositoryAdapter(com.forgerock.openbanking.aspsp.rs.store.repository.IdempotentRepositoryAdapter) FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) FRDomesticPaymentSubmission(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticPaymentSubmission) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) FRWriteDomestic(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomestic) FRWriteDomesticConverter.toFRWriteDomestic(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteDomesticConverter.toFRWriteDomestic) Date(java.util.Date)

Example 73 with FRDomesticConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticPaymentsApiController method getDomesticPaymentsDomesticPaymentId.

@Override
public ResponseEntity getDomesticPaymentsDomesticPaymentId(@ApiParam(value = "DomesticPaymentId", required = true) @PathVariable("DomesticPaymentId") String domesticPaymentId, @ApiParam(value = "The unique id of the ASPSP to which the request is issued. The unique id will be issued by OB.", required = true) @RequestHeader(value = "x-fapi-financial-id", required = true) String xFapiFinancialId, @ApiParam(value = "An Authorisation Token as per https://tools.ietf.org/html/rfc6750", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, @ApiParam(value = "The time when the PSU last logged in with the TPP.  All dates in the HTTP headers are represented as RFC 7231 Full Dates. An example is below:  Sun, 10 Sep 2017 19:43:31 UTC") @RequestHeader(value = "x-fapi-customer-last-logged-time", required = false) @DateTimeFormat(pattern = HTTP_DATE_FORMAT) DateTime xFapiCustomerLastLoggedTime, @ApiParam(value = "The PSU's IP address if the PSU is currently logged in with the TPP.") @RequestHeader(value = "x-fapi-customer-ip-address", required = false) String xFapiCustomerIpAddress, @ApiParam(value = "An RFC4122 UID used as a correlation id.") @RequestHeader(value = "x-fapi-interaction-id", required = false) String xFapiInteractionId, @ApiParam(value = "Indicates the user-agent that the PSU is using.") @RequestHeader(value = "x-customer-user-agent", required = false) String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    Optional<FRDomesticPaymentSubmission> isPaymentSubmission = domesticPaymentSubmissionRepository.findById(domesticPaymentId);
    if (!isPaymentSubmission.isPresent()) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Payment submission '" + domesticPaymentId + "' can't be found");
    }
    FRDomesticPaymentSubmission frPaymentSubmission = isPaymentSubmission.get();
    Optional<FRDomesticConsent> isPaymentSetup = domesticConsentRepository.findById(domesticPaymentId);
    if (!isPaymentSetup.isPresent()) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Payment setup behind payment submission '" + domesticPaymentId + "' can't be found");
    }
    FRDomesticConsent frPaymentSetup = isPaymentSetup.get();
    return ResponseEntity.ok(responseEntity(frPaymentSubmission, frPaymentSetup));
}
Also used : FRDomesticPaymentSubmission(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticPaymentSubmission) FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent)

Example 74 with FRDomesticConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent 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)

Example 75 with FRDomesticConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticPaymentConsentsApiController method createDomesticPaymentConsents.

@Override
public ResponseEntity<OBWriteDomesticConsentResponse3> createDomesticPaymentConsents(OBWriteDomesticConsent3 obWriteDomesticConsent3, String authorization, String xIdempotencyKey, String xJwsSignature, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, String clientId, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    log.debug("Received: '{}'", obWriteDomesticConsent3);
    FRWriteDomesticConsent frWriteDomesticConsent = toFRWriteDomesticConsent(obWriteDomesticConsent3);
    log.trace("Converted to: '{}'", frWriteDomesticConsent);
    Tpp tpp = tppRepository.findByClientId(clientId);
    log.debug("Got TPP '{}' for client Id '{}'", tpp, clientId);
    Optional<FRDomesticConsent> consentByIdempotencyKey = domesticConsentRepository.findByIdempotencyKeyAndPispId(xIdempotencyKey, tpp.getId());
    if (consentByIdempotencyKey.isPresent()) {
        validateIdempotencyRequest(xIdempotencyKey, frWriteDomesticConsent, consentByIdempotencyKey.get(), () -> consentByIdempotencyKey.get().getDomesticConsent());
        log.info("Idempotent request is valid. Returning [201 CREATED] but take no further action.");
        return ResponseEntity.status(HttpStatus.CREATED).body(packageResponse(consentByIdempotencyKey.get()));
    }
    log.debug("No consent with matching idempotency key has been found. Creating new consent.");
    FRDomesticConsent domesticConsent = FRDomesticConsent.builder().id(IntentType.PAYMENT_DOMESTIC_CONSENT.generateIntentId()).status(ConsentStatusCode.AWAITINGAUTHORISATION).domesticConsent(frWriteDomesticConsent).pispId(tpp.getId()).pispName(tpp.getOfficialName()).statusUpdate(DateTime.now()).idempotencyKey(xIdempotencyKey).obVersion(VersionPathExtractor.getVersionFromPath(request)).build();
    log.debug("Saving consent: '{}'", domesticConsent);
    consentMetricService.sendConsentActivity(new ConsentStatusEntry(domesticConsent.getId(), domesticConsent.getStatus().name()));
    domesticConsent = domesticConsentRepository.save(domesticConsent);
    log.info("Created consent id: '{}'", domesticConsent.getId());
    return ResponseEntity.status(HttpStatus.CREATED).body(packageResponse(domesticConsent));
}
Also used : Tpp(com.forgerock.openbanking.model.Tpp) FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) FRWriteDomesticConsent(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticConsent) FRWriteDomesticConsentConverter.toFRWriteDomesticConsent(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteDomesticConsentConverter.toFRWriteDomesticConsent) ConsentStatusEntry(com.forgerock.openbanking.analytics.model.entries.ConsentStatusEntry)

Aggregations

FRDomesticConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent)105 Test (org.junit.Test)62 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)50 SpringSecForTest (com.forgerock.openbanking.integration.test.support.SpringSecForTest)49 FRDomesticPaymentSubmission (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticPaymentSubmission)37 Collections (java.util.Collections)15 OBErrorResponseException (com.forgerock.openbanking.exceptions.OBErrorResponseException)14 FRWriteDomesticConverter.toOBWriteDomestic2 (com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteDomesticConverter.toOBWriteDomestic2)13 DomesticPaymentService (com.forgerock.openbanking.common.services.store.payment.DomesticPaymentService)13 ResponseEntity (org.springframework.http.ResponseEntity)12 ConsentStatusCode (com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode)11 RSEndpointWrapperService (com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService)9 FRWriteDomestic (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomestic)9 FRWriteDomesticConsent (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticConsent)9 RsStoreGateway (com.forgerock.openbanking.common.services.store.RsStoreGateway)9 Principal (java.security.Principal)9 FRAccount (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 DateTime (org.joda.time.DateTime)7 HttpHeaders (org.springframework.http.HttpHeaders)7