Search in sources :

Example 1 with FRInternationalConsent

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

the class InternationalPaymentsApiController method createInternationalPayments.

@Override
public ResponseEntity<OBWriteInternationalResponse4> createInternationalPayments(OBWriteInternational3 obWriteInternational3, String authorization, String xIdempotencyKey, String xJwsSignature, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    log.debug("Received payment submission: '{}'", obWriteInternational3);
    FRWriteInternational frWriteInternational = toFRWriteInternational(obWriteInternational3);
    log.trace("Converted to: '{}'", frWriteInternational);
    String paymentId = obWriteInternational3.getData().getConsentId();
    FRInternationalConsent paymentConsent = internationalConsentRepository.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);
    FRInternationalPaymentSubmission frPaymentSubmission = FRInternationalPaymentSubmission.builder().id(paymentId).internationalPayment(frWriteInternational).created(new Date()).updated(new Date()).idempotencyKey(xIdempotencyKey).obVersion(VersionPathExtractor.getVersionFromPath(request)).build();
    frPaymentSubmission = new IdempotentRepositoryAdapter<>(internationalPaymentSubmissionRepository).idempotentSave(frPaymentSubmission);
    return ResponseEntity.status(HttpStatus.CREATED).body(responseEntity(frPaymentSubmission, paymentConsent));
}
Also used : IdempotentRepositoryAdapter(com.forgerock.openbanking.aspsp.rs.store.repository.IdempotentRepositoryAdapter) FRWriteInternational(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternational) FRWriteInternationalConverter.toFRWriteInternational(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteInternationalConverter.toFRWriteInternational) FRInternationalConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) FRInternationalPaymentSubmission(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalPaymentSubmission) Date(java.util.Date)

Example 2 with FRInternationalConsent

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

the class InternationalPaymentsApiController method getInternationalPaymentsInternationalPaymentId.

public ResponseEntity getInternationalPaymentsInternationalPaymentId(String internationalPaymentId, String authorization, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    Optional<FRInternationalPaymentSubmission> isPaymentSubmission = internationalPaymentSubmissionRepository.findById(internationalPaymentId);
    if (!isPaymentSubmission.isPresent()) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Payment submission '" + internationalPaymentId + "' can't be found");
    }
    FRInternationalPaymentSubmission frPaymentSubmission = isPaymentSubmission.get();
    Optional<FRInternationalConsent> isPaymentSetup = internationalConsentRepository.findById(internationalPaymentId);
    if (!isPaymentSetup.isPresent()) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Payment setup behind payment submission '" + internationalPaymentId + "' can't be found");
    }
    FRInternationalConsent frPaymentSetup = isPaymentSetup.get();
    return ResponseEntity.ok(responseEntity(frPaymentSubmission, frPaymentSetup));
}
Also used : FRInternationalConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent) FRInternationalPaymentSubmission(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalPaymentSubmission)

Example 3 with FRInternationalConsent

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

the class InternationalPaymentConsentsApiController method getInternationalPaymentConsentsConsentIdFundsConfirmation.

public ResponseEntity<OBWriteFundsConfirmationResponse1> getInternationalPaymentConsentsConsentIdFundsConfirmation(String consentId, String authorization, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    FRInternationalConsent payment = paymentsService.getPayment(consentId);
    return rsEndpointWrapperService.paymentEndpoint().authorization(authorization).xFapiFinancialId(rsEndpointWrapperService.rsConfiguration.financialId).payment(payment).principal(principal).obVersion(getOBVersion(request.getRequestURI())).isFundsConfirmationRequest(true).filters(f -> {
        f.verifyConsentStatusForConfirmationOfFund();
    }).execute((String tppId) -> {
        HttpHeaders additionalHttpHeaders = new HttpHeaders();
        additionalHttpHeaders.add("x-ob-url", new ServletServerHttpRequest(request).getURI().toString());
        return rsStoreGateway.toRsStore(request, additionalHttpHeaders, OBWriteFundsConfirmationResponse1.class);
    });
}
Also used : OBWriteFundsConfirmationResponse1(uk.org.openbanking.datamodel.payment.OBWriteFundsConfirmationResponse1) RsStoreGateway(com.forgerock.openbanking.common.services.store.RsStoreGateway) HttpHeaders(org.springframework.http.HttpHeaders) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) InternationalPaymentService(com.forgerock.openbanking.common.services.store.payment.InternationalPaymentService) Controller(org.springframework.stereotype.Controller) ExchangeRateVerifier(com.forgerock.openbanking.aspsp.rs.api.payment.verifier.ExchangeRateVerifier) FRInternationalConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent) OBWriteInternationalConsent5(uk.org.openbanking.datamodel.payment.OBWriteInternationalConsent5) HttpServletRequest(javax.servlet.http.HttpServletRequest) Principal(java.security.Principal) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) ApiVersionUtils.getOBVersion(com.forgerock.openbanking.common.utils.ApiVersionUtils.getOBVersion) RSEndpointWrapperService(com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService) ResponseEntity(org.springframework.http.ResponseEntity) Collections(java.util.Collections) OBWriteInternationalConsentResponse6(uk.org.openbanking.datamodel.payment.OBWriteInternationalConsentResponse6) HttpHeaders(org.springframework.http.HttpHeaders) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) FRInternationalConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent)

Example 4 with FRInternationalConsent

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

the class InternationalPaymentConsentsApiController method createInternationalPaymentConsents.

public ResponseEntity<OBWriteInternationalConsentResponse6> createInternationalPaymentConsents(OBWriteInternationalConsent5 obWriteInternationalConsent5, 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: '{}'", obWriteInternationalConsent5);
    FRWriteInternationalConsent frWriteInternationalConsent = toFRWriteInternationalConsent(obWriteInternationalConsent5);
    log.trace("Converted to: '{}'", frWriteInternationalConsent);
    final Tpp tpp = tppRepository.findByClientId(clientId);
    log.debug("Got TPP '{}' for client Id '{}'", tpp, clientId);
    Optional<FRInternationalConsent> consentByIdempotencyKey = internationalConsentRepository.findByIdempotencyKeyAndPispId(xIdempotencyKey, tpp.getId());
    if (consentByIdempotencyKey.isPresent()) {
        validateIdempotencyRequest(xIdempotencyKey, frWriteInternationalConsent, consentByIdempotencyKey.get(), () -> consentByIdempotencyKey.get().getInternationalConsent());
        log.info("Idempotent request is valid. Returning [201 CREATED] but take no further action.");
        return ResponseEntity.status(HttpStatus.CREATED).body(responseEntity(consentByIdempotencyKey.get()));
    }
    log.debug("No consent with matching idempotency key has been found. Creating new consent.");
    log.debug("Got TPP '{}' for client Id '{}'", tpp, clientId);
    FRInternationalConsent internationalConsent = FRInternationalConsent.builder().id(IntentType.PAYMENT_INTERNATIONAL_CONSENT.generateIntentId()).status(ConsentStatusCode.AWAITINGAUTHORISATION).internationalConsent(frWriteInternationalConsent).pispId(tpp.getId()).pispName(tpp.getOfficialName()).statusUpdate(DateTime.now()).obVersion(VersionPathExtractor.getVersionFromPath(request)).build();
    log.debug("Saving consent: '{}'", internationalConsent);
    consentMetricService.sendConsentActivity(new ConsentStatusEntry(internationalConsent.getId(), internationalConsent.getStatus().name()));
    internationalConsent = internationalConsentRepository.save(internationalConsent);
    log.info("Created consent id: '{}'", internationalConsent.getId());
    return ResponseEntity.status(HttpStatus.CREATED).body(responseEntity(internationalConsent));
}
Also used : FRWriteInternationalConsentConverter.toFRWriteInternationalConsent(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteInternationalConsentConverter.toFRWriteInternationalConsent) FRWriteInternationalConsent(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternationalConsent) Tpp(com.forgerock.openbanking.model.Tpp) FRInternationalConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent) ConsentStatusEntry(com.forgerock.openbanking.analytics.model.entries.ConsentStatusEntry)

Example 5 with FRInternationalConsent

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

the class InternationalPaymentConsentsApiController method getInternationalPaymentConsentsConsentIdFundsConfirmation.

public ResponseEntity getInternationalPaymentConsentsConsentIdFundsConfirmation(String consentId, String authorization, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, String httpUrl, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    Optional<FRInternationalConsent> isInternationalConsent = internationalConsentRepository.findById(consentId);
    if (!isInternationalConsent.isPresent()) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("International consent '" + consentId + "' can't be found");
    }
    FRInternationalConsent internationalConsent = isInternationalConsent.get();
    // Check if funds are available on the account selected in consent
    boolean areFundsAvailable = fundsAvailabilityService.isFundsAvailable(internationalConsent.getAccountId(), internationalConsent.getInitiation().getInstructedAmount().getAmount());
    return ResponseEntity.status(HttpStatus.OK).body(new OBWriteFundsConfirmationResponse1().data(new OBWriteFundsConfirmationResponse1Data().fundsAvailableResult(new OBWriteFundsConfirmationResponse1DataFundsAvailableResult().fundsAvailable(areFundsAvailable).fundsAvailableDateTime(DateTime.now()))).links(PaginationUtil.generateLinksOnePager(httpUrl)).meta(new Meta()));
}
Also used : Meta(uk.org.openbanking.datamodel.account.Meta) FRInternationalConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent)

Aggregations

FRInternationalConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent)87 Test (org.junit.Test)46 SpringSecForTest (com.forgerock.openbanking.integration.test.support.SpringSecForTest)35 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)35 FRInternationalPaymentSubmission (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalPaymentSubmission)29 ResponseEntity (org.springframework.http.ResponseEntity)16 OBErrorResponseException (com.forgerock.openbanking.exceptions.OBErrorResponseException)14 InternationalPaymentService (com.forgerock.openbanking.common.services.store.payment.InternationalPaymentService)13 Collections (java.util.Collections)13 RSEndpointWrapperService (com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService)9 FRAccountIdentifier (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier)9 FRWriteInternationalConsent (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternationalConsent)9 ConsentStatusCode (com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode)9 RsStoreGateway (com.forgerock.openbanking.common.services.store.RsStoreGateway)9 Principal (java.security.Principal)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 DateTime (org.joda.time.DateTime)9 HttpHeaders (org.springframework.http.HttpHeaders)9 Controller (org.springframework.stereotype.Controller)9 AccountWithBalance (com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance)7