Search in sources :

Example 21 with FRFileConsent

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

the class FilePaymentsApiControllerIT method testGetInternationalPaymentSubmissionMissingConsentReturnNotFound.

@Test
public void testGetInternationalPaymentSubmissionMissingConsentReturnNotFound() throws UnirestException {
    // Given
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    FRFileConsent consent = JMockData.mock(FRFileConsent.class);
    consent.setId(IntentType.PAYMENT_FILE_CONSENT.generateIntentId());
    FRFilePaymentSubmission submission = savePaymentSubmission(consent);
    // When
    HttpResponse<String> response = Unirest.get("https://rs-store:" + port + "/open-banking/v3.1/pisp/file-payments/" + submission.getId()).header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "token").header(OBHeaders.CONTENT_TYPE, "application/json; charset=utf-8").asObject(String.class);
    // Then
    assertThat(response.getStatus()).isEqualTo(400);
}
Also used : FRFileConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent) FRFilePaymentSubmission(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFilePaymentSubmission) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 22 with FRFileConsent

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

the class RCSFilePaymentDetailsApi method consentDetails.

@Override
public ResponseEntity consentDetails(String remoteConsentRequest, List<AccountWithBalance> accounts, String username, String consentId, String clientId) throws OBErrorException {
    log.debug("Received a consent request with consent_request='{}'", remoteConsentRequest);
    log.debug("=> The payment id '{}'", consentId);
    log.debug("Populate the model with the payment and consent data");
    FRFileConsent consent = paymentService.getPayment(consentId);
    checkValidPisp(consent, clientId);
    // A null debtor account will let PSU select account when authorising
    if (consent.getInitiation().getDebtorAccount() != null) {
        Optional<AccountWithBalance> matchingUserAccount = accountService.findAccountByIdentification(consent.getInitiation().getDebtorAccount().getIdentification(), accounts);
        if (!matchingUserAccount.isPresent()) {
            log.error("The PISP '{}' created the payment consent '{}' but the debtor account: {} on the consent " + " is not one of the user's accounts: {}.", consent.getPispId(), consent.getId(), consent.getInitiation().getDebtorAccount(), accounts);
            return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_DEBTOR_ACCOUNT_NOT_FOUND, consent.getPispId(), consent.getId(), accounts);
        } else {
            accounts = Collections.singletonList(matchingUserAccount.get());
        }
    }
    associatePaymentToUser(consent, username);
    Optional<Tpp> isTpp = tppStoreService.findById(consent.getPispId());
    if (!isTpp.isPresent()) {
        log.error("The TPP '{}' (Client ID {}) that created this consent id '{}' doesn't exist anymore.", consent.getPispId(), clientId, consentId);
        return rcsErrorService.error(OBRIErrorType.RCS_CONSENT_REQUEST_NOT_FOUND_TPP, clientId, consentId);
    }
    Tpp tpp = isTpp.get();
    FRWriteFileDataInitiation initiation = consent.getWriteFileConsent().getData().getInitiation();
    return ResponseEntity.ok(FilePaymentConsentDetails.builder().accounts(accounts).username(username).merchantName(consent.getPispName()).clientId(clientId).fileReference(initiation.getFileReference()).numberOfTransactions(initiation.getNumberOfTransactions()).totalAmount(new OBActiveOrHistoricCurrencyAndAmount().amount(initiation.getControlSum().toPlainString()).currency(consent.getPayments().get(0).getInstructedAmount().getCurrency())).requestedExecutionDateTime(initiation.getRequestedExecutionDateTime()).paymentReference(Optional.ofNullable(initiation.getRemittanceInformation()).map(FRRemittanceInformation::getReference).orElse("")).build());
}
Also used : FRRemittanceInformation(com.forgerock.openbanking.common.model.openbanking.domain.payment.common.FRRemittanceInformation) OBActiveOrHistoricCurrencyAndAmount(uk.org.openbanking.datamodel.payment.OBActiveOrHistoricCurrencyAndAmount) FRFileConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent) Tpp(com.forgerock.openbanking.model.Tpp) AccountWithBalance(com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance) FRWriteFileDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileDataInitiation)

Example 23 with FRFileConsent

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

the class FilePaymentsApiControllerIT method testMissingConsentOnPaymentInitiationShouldReturnNotFound.

@Test
public void testMissingConsentOnPaymentInitiationShouldReturnNotFound() throws Exception {
    // Given
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    FRFileConsent consent = JMockData.mock(FRFileConsent.class);
    consent.setId(IntentType.PAYMENT_FILE_CONSENT.generateIntentId());
    consent.getInitiation().setControlSum(new BigDecimal("1001.1"));
    consent.getInitiation().setFileType("UK.OBIE.PaymentInitiation.3.0");
    consent.getInitiation().setFileReference("Test");
    consent.getInitiation().setNumberOfTransactions("100");
    consent.getInitiation().setFileHash("sdjhgfksfkshfjksh");
    consent.getInitiation().setSupplementaryData(FRSupplementaryData.builder().data("{}").build());
    OBWriteFile2 submissionRequest = new OBWriteFile2().data(new OBWriteFile2Data().consentId(consent.getId()).initiation(toOBWriteFile2DataInitiation(consent.getInitiation())));
    // When
    HttpResponse<String> response = Unirest.post("https://rs-store:" + port + "/open-banking/v3.1/pisp/file-payments").header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "token").header(OBHeaders.X_IDEMPOTENCY_KEY, "x-idempotency-key").header(OBHeaders.X_JWS_SIGNATURE, "x-jws-signature").header(OBHeaders.CONTENT_TYPE, "application/json; charset=utf-8").body(submissionRequest).asObject(String.class);
    // Then
    assertThat(response.getStatus()).isEqualTo(400);
}
Also used : FRWriteFileConverter.toOBWriteFile2(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteFileConverter.toOBWriteFile2) FRFileConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent) BigDecimal(java.math.BigDecimal) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 24 with FRFileConsent

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

the class FilePaymentsApiControllerIT method testGetInternationalPaymentSubmission.

@Test
public void testGetInternationalPaymentSubmission() throws UnirestException {
    // Given
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    FRFileConsent consent = saveConsent();
    FRFilePaymentSubmission submission = savePaymentSubmission(consent);
    // When
    HttpResponse<OBWriteFileConsentResponse2> response = Unirest.get("https://rs-store:" + port + "/open-banking/v3.1/pisp/file-payments/" + submission.getId()).header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "token").header(OBHeaders.CONTENT_TYPE, "application/json; charset=utf-8").asObject(OBWriteFileConsentResponse2.class);
    // Then
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getBody().getData().getConsentId()).isEqualTo(consent.getId());
    assertThat(response.getBody().getData().getInitiation()).isEqualTo(toOBFile2(submission.getFilePayment().getData().getInitiation()));
    assertThat(response.getBody().getData().getCreationDateTime()).isEqualTo(consent.getCreated());
}
Also used : FRFileConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent) FRFilePaymentSubmission(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFilePaymentSubmission) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 25 with FRFileConsent

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

the class FilePaymentsApiControllerIT method testGetReportFileSuccess.

@Test
public void testGetReportFileSuccess() throws Exception {
    // Given
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    FRFileConsent consent = saveConsent();
    when(paymentReportFileService.createPaymentReport(eq(consent))).thenReturn("{\"Data\": {\"DomesticPayments\": []} }");
    // When
    HttpResponse<String> response = Unirest.get("https://rs-store:" + port + "/open-banking/v3.1/pisp/file-payments/" + consent.getId() + "/report-file").header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "token").header(OBHeaders.X_IDEMPOTENCY_KEY, "x-idempotency-key").header(OBHeaders.X_JWS_SIGNATURE, "x-jws-signature").header(OBHeaders.CONTENT_TYPE, "application/json; charset=utf-8").header("Accept", "application/json; charset=utf-8").asString();
    log.debug("Response: {}", response.getBody());
    // Then
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getBody()).isEqualTo("{\"Data\": {\"DomesticPayments\": []} }");
}
Also used : FRFileConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

FRFileConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent)45 OBErrorResponseException (com.forgerock.openbanking.exceptions.OBErrorResponseException)29 FRFilePaymentSubmission (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFilePaymentSubmission)13 SpringSecForTest (com.forgerock.openbanking.integration.test.support.SpringSecForTest)12 Date (java.util.Date)12 Test (org.junit.Test)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 RSEndpointWrapperService (com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService)8 RsStoreGateway (com.forgerock.openbanking.common.services.store.RsStoreGateway)8 FilePaymentService (com.forgerock.openbanking.common.services.store.payment.FilePaymentService)8 Principal (java.security.Principal)8 Collections (java.util.Collections)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 DateTime (org.joda.time.DateTime)8 Resource (org.springframework.core.io.Resource)8 HttpHeaders (org.springframework.http.HttpHeaders)8 ResponseEntity (org.springframework.http.ResponseEntity)7 Controller (org.springframework.stereotype.Controller)7 FRWriteFile (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFile)5 Tpp (com.forgerock.openbanking.model.Tpp)5