Search in sources :

Example 1 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<OBWriteDomesticConsentResponse5> createDomesticPaymentConsents(OBWriteDomesticConsent4 obWriteDomesticConsent4, 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: '{}'", obWriteDomesticConsent4);
    FRWriteDomesticConsent frWriteDomesticConsent = toFRWriteDomesticConsent(obWriteDomesticConsent4);
    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(responseEntity(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(responseEntity(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)

Example 2 with FRDomesticConsent

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

the class DomesticPaymentsApiController method getDomesticPaymentsDomesticPaymentId.

public ResponseEntity getDomesticPaymentsDomesticPaymentId(String domesticPaymentId, String authorization, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, 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 3 with FRDomesticConsent

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

the class DomesticPaymentsApiController method createDomesticPayments.

public ResponseEntity<OBWriteDomesticResponse5> createDomesticPayments(OBWriteDomestic2 obWriteDomestic2, 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: '{}'", 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 4 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<OBWriteDomesticConsentResponse4> createDomesticPaymentConsents(OBWriteDomesticConsent4 obWriteDomesticConsent4, 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: '{}'", obWriteDomesticConsent4);
    FRWriteDomesticConsent frWriteDomesticConsent = toFRWriteDomesticConsent(obWriteDomesticConsent4);
    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(responseEntity(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(responseEntity(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)

Example 5 with FRDomesticConsent

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

the class DomesticPaymentApiControllerTest method findByStatus.

@Test
public void findByStatus() {
    // Given
    FRDomesticConsent expectedConsent = new FRDomesticConsent();
    expectedConsent.id = "expectedId123";
    when(repository.findByStatus(eq(OBTransactionIndividualStatus1Code.ACCEPTEDSETTLEMENTINPROCESS))).thenReturn(Collections.singleton(expectedConsent));
    // When
    ResponseEntity<Collection<FRDomesticConsent>> resp = controller.findByStatus(ConsentStatusCode.ACCEPTEDSETTLEMENTINPROCESS);
    // Then
    assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(resp.getBody()).containsExactly(expectedConsent);
}
Also used : FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) Collection(java.util.Collection) Test(org.junit.Test)

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