Search in sources :

Example 66 with FRDomesticConsent

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

the class PaymentConsentDecisionUpdaterTest method paymentDecisionAllowed_applyUpdateToConsent.

@Test
public void paymentDecisionAllowed_applyUpdateToConsent() throws Exception {
    // Given
    FRAccount account = new FRAccount();
    account.id = ACCOUNT_ID;
    when(accountStoreService.get(USER_ID)).thenReturn(Collections.singletonList(account));
    FRDomesticConsent paymentConsent = new FRDomesticConsent();
    // When
    paymentConsentDecisionUpdater.applyUpdate(USER_ID, ACCOUNT_ID, true, p -> {
    }, paymentConsent);
    // Then
    assertThat(paymentConsent.getStatus()).isEqualTo(ConsentStatusCode.AUTHORISED);
    assertThat(paymentConsent.getAccountId()).isEqualTo(ACCOUNT_ID);
}
Also used : FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) Test(org.junit.Test)

Example 67 with FRDomesticConsent

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

the class PaymentConsentDecisionUpdaterTest method paymentDecisionAllowed_butUserDoesNotOwnAccount_rejectWithException.

@Test
public void paymentDecisionAllowed_butUserDoesNotOwnAccount_rejectWithException() {
    // Given
    FRAccount account = new FRAccount();
    account.id = "differentId";
    when(accountStoreService.get(USER_ID)).thenReturn(Collections.singletonList(account));
    FRDomesticConsent paymentConsent = new FRDomesticConsent();
    // When
    assertThatThrownBy(() -> paymentConsentDecisionUpdater.applyUpdate(USER_ID, ACCOUNT_ID, true, p -> {
    }, paymentConsent)).isExactlyInstanceOf(OBErrorException.class).hasMessage("The PSU user1 is trying to share an account 'acc123' he doesn't own. List of his accounts '[FRAccount(id=differentId, userID=null, account=null, latestStatementId=null, created=null, updated=null)]'");
}
Also used : InjectMocks(org.mockito.InjectMocks) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException) AccountStoreService(com.forgerock.openbanking.common.services.store.account.AccountStoreService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ConsentStatusCode(com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode) FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException) Test(org.junit.Test)

Example 68 with FRDomesticConsent

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

the class PaymentConsentDecisionUpdaterTest method paymentDecisionDeclined_applyRejectedUpdateToConsent.

@Test
public void paymentDecisionDeclined_applyRejectedUpdateToConsent() throws Exception {
    // Given
    FRDomesticConsent paymentConsent = new FRDomesticConsent();
    // When
    paymentConsentDecisionUpdater.applyUpdate(USER_ID, null, false, p -> {
    }, paymentConsent);
    // Then
    assertThat(paymentConsent.getStatus()).isEqualTo(ConsentStatusCode.REJECTED);
}
Also used : FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) Test(org.junit.Test)

Example 69 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<OBWriteDomesticConsentResponse2> createDomesticPaymentConsents(@ApiParam(value = "Default", required = true) @Valid @RequestBody OBWriteDomesticConsent2 obWriteDomesticConsent2, @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, @ApiParam(value = "The PISP ID") @RequestHeader(value = "x-ob-client-id", required = false) String clientId, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    log.debug("Received: '{}'", obWriteDomesticConsent2);
    FRWriteDomesticConsent frWriteDomesticConsent = toFRWriteDomesticConsent(obWriteDomesticConsent2);
    log.trace("Converted to: '{}'", frWriteDomesticConsent);
    final 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)

Example 70 with FRDomesticConsent

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

the class DomesticPaymentConsentsApiController method getDomesticPaymentConsentsConsentIdFundsConfirmation.

@Override
public ResponseEntity getDomesticPaymentConsentsConsentIdFundsConfirmation(@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, @RequestHeader(value = "x-ob-url", required = true) String httpUrl, 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();
    // Check if funds are available on the account selected in consent
    boolean areFundsAvailable = fundsAvailabilityService.isFundsAvailable(domesticConsent.getAccountId(), domesticConsent.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) FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent)

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