Search in sources :

Example 6 with FRPaymentSetup

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

the class PaymentSetup method tracePaymentSetup.

private FRPaymentSetup tracePaymentSetup(OBHeaders headers, OBPaymentSetup1 paymentSetupPOSTRequest, String paymentID) {
    FRPaymentSetup paymentSetupEntity = new FRPaymentSetup();
    paymentSetupEntity.setId(paymentID);
    paymentSetupEntity.setPaymentSetupRequest(toFRWriteDomesticConsent(paymentSetupPOSTRequest));
    // paymentSetupEntity = paymentSetupsService.createPaymentSetup(paymentSetupEntity);
    return paymentSetupEntity;
}
Also used : FRPaymentSetup(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup)

Example 7 with FRPaymentSetup

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

the class PaymentSetup method create.

public OBPaymentSetupResponse1 create(OBHeaders headers, String tppId, OBPaymentSetup1 paymentSetupPOSTRequest) {
    String paymentID = paymentId.create();
    log.debug("FRPaymentConsent ID generated '{}'.", paymentID);
    FRPaymentSetup payment = registerPendingPayment(tppId, paymentSetupPOSTRequest, paymentID);
    FRPaymentSetup paymentSetupEntity = tracePaymentSetup(headers, paymentSetupPOSTRequest, paymentID);
    updatePaymentToAcceptedTechnicalValidation(payment);
    return updatePaymentSetup(paymentSetupPOSTRequest, payment, paymentSetupEntity);
}
Also used : FRPaymentSetup(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup)

Example 8 with FRPaymentSetup

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

the class PaymentsApiController method createSingleImmediatePayment.

@Override
public ResponseEntity createSingleImmediatePayment(@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 = "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 = "Header containing a detached JWS signature of the body of the payload.", required = true) @RequestHeader(value = "x-jws-signature", required = false) 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 = "The PISP ID") @RequestHeader(value = "x-ob-client-id", required = false) String clientId, @ApiParam(value = "Setup a single immediate payment", required = true) @Valid @RequestBody OBPaymentSetup1 paymentSetupPOSTRequest, HttpServletRequest httpServletRequest) throws OBErrorResponseException {
    log.debug("Received a POST payment setup request '{}'.", paymentSetupPOSTRequest);
    final Tpp tpp = tppRepository.findByClientId(clientId);
    log.debug("Got TPP '{}' for client Id '{}'", tpp, clientId);
    Optional<FRPaymentSetup> consentByIdempotencyKey = frPaymentSetupRepository.findByIdempotencyKeyAndPispId(xIdempotencyKey, tpp.getId());
    if (consentByIdempotencyKey.isPresent()) {
        validateIdempotencyRequest(xIdempotencyKey, paymentSetupPOSTRequest, consentByIdempotencyKey.get(), () -> consentByIdempotencyKey.get().getPaymentSetupRequest());
        log.info("Idempotent request is valid. Returning [201 CREATED] but take no further action.");
        return ResponseEntity.status(HttpStatus.CREATED).body(packageIntoPaymentSetupResponse(consentByIdempotencyKey.get()));
    }
    log.debug("No consent with matching idempotency key has been found. Creating new consent.");
    FRPaymentSetup frPaymentSetup = new FRPaymentSetup();
    frPaymentSetup.setId(IntentType.PAYMENT_SINGLE_REQUEST.generateIntentId());
    frPaymentSetup.setStatus(ConsentStatusCode.ACCEPTEDTECHNICALVALIDATION);
    frPaymentSetup.setPaymentSetupRequest(toFRWriteDomesticConsent(paymentSetupPOSTRequest));
    frPaymentSetup.setPisp(tpp);
    frPaymentSetup.setIdempotencyKey(xIdempotencyKey);
    frPaymentSetup.setObVersion(VersionPathExtractor.getVersionFromPath(httpServletRequest));
    consentMetricService.sendConsentActivity(new ConsentStatusEntry(frPaymentSetup.getId(), frPaymentSetup.getStatus().name()));
    frPaymentSetup = frPaymentSetupRepository.save(frPaymentSetup);
    return ResponseEntity.status(HttpStatus.CREATED).body(packageIntoPaymentSetupResponse(frPaymentSetup));
}
Also used : Tpp(com.forgerock.openbanking.model.Tpp) FRPaymentSetup(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup) ConsentStatusEntry(com.forgerock.openbanking.analytics.model.entries.ConsentStatusEntry)

Example 9 with FRPaymentSetup

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

the class PaymentSubmissionsApiController method createPaymentSubmission.

@Override
public ResponseEntity createPaymentSubmission(@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 = "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 = "Header containing a detached JWS signature of the body of the payload.", required = true) @RequestHeader(value = "x-jws-signature", required = false) 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 = "The payment ID") @RequestHeader(value = "x-ob-payment-id", required = false) String paymentId, @ApiParam(value = "Setup a single immediate payment", required = true) @Valid @RequestBody OBPaymentSubmission1 paymentSubmission, HttpServletRequest httpServletRequest) throws OBErrorResponseException {
    log.debug("Received payment submission: '{}'", paymentSubmission);
    Optional<FRPaymentSetup> isPaymentSetup = frPaymentSetupRepository.findById(paymentId);
    if (isPaymentSetup.isEmpty()) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Payment setup behind payment submission '" + paymentId + "' can't be found");
    }
    // Trace the payment submission request
    FRPaymentSubmission frPaymentSubmission = new FRPaymentSubmission();
    frPaymentSubmission.setId(paymentId);
    frPaymentSubmission.setPaymentSubmission(paymentSubmission);
    frPaymentSubmission.setIdempotencyKey(xIdempotencyKey);
    frPaymentSubmission.setObVersion(VersionPathExtractor.getVersionFromPath(httpServletRequest));
    frPaymentSubmission = new IdempotentRepositoryAdapter<>(frPaymentSubmissionRepository).idempotentSave(frPaymentSubmission);
    FRPaymentSetup frPaymentSetup = isPaymentSetup.get();
    return ResponseEntity.status(HttpStatus.CREATED).body(packageToPaymentSubmission(frPaymentSubmission, frPaymentSetup));
}
Also used : IdempotentRepositoryAdapter(com.forgerock.openbanking.aspsp.rs.store.repository.IdempotentRepositoryAdapter) FRPaymentSubmission(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSubmission) FRPaymentSetup(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup)

Example 10 with FRPaymentSetup

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

the class RCSConsentDecisionApiControllerIT method getConsentDetailsForSinglePayment.

@Test
public void getConsentDetailsForSinglePayment() throws Exception {
    // Given
    FRWriteDomesticConsentData writeDomesticConsentData = FRWriteDomesticConsentData.builder().initiation(FRWriteDomesticDataInitiation.builder().build()).build();
    FRPaymentSetup payment = FRPaymentSetup.builder().pispId(PISP_ID).pispName(PISP_NAME).status(ConsentStatusCode.AWAITINGAUTHORISATION).paymentSetupRequest(FRWriteDomesticConsent.builder().data(writeDomesticConsentData).build()).build();
    payment.getInitiation().setInstructedAmount(FRAmount.builder().build());
    when(singlePaymentService.getPayment(any())).thenReturn(payment);
    String signedJwtEncoded = toEncodedSignedTestJwt("jwt/singlePaymentConsentRequestPayload.json");
    // When
    HttpResponse<SinglePaymentConsentDetails> response = Unirest.post("https://rs-rcs:" + port + "/api/rcs/consent/details/").header(OBHeaders.CONTENT_TYPE, CONTENT_TYPE_JWT).header("Cookie", MOCK_COOKIE).body(signedJwtEncoded).asObject(SinglePaymentConsentDetails.class);
    // Then
    assertThat(response.getStatus()).isEqualTo(200);
    SinglePaymentConsentDetails resp = response.getBody();
    assertThat(resp.getClientId()).isEqualTo(PISP_ID);
    assertThat(resp.getPispName()).isEqualTo(PISP_NAME);
    assertThat(resp.getUsername()).isEqualTo(USER_ID);
    assertThat(resp.getIntentType()).isEqualTo(IntentType.PAYMENT_SINGLE_REQUEST);
    assertThat(resp.getDecisionAPIUri()).isEqualTo(EXPECTED_DECISION_API_URI);
}
Also used : SinglePaymentConsentDetails(com.forgerock.openbanking.common.model.rcs.consentdetails.SinglePaymentConsentDetails) FRPaymentSetup(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup) FRWriteDomesticConsentData(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticConsentData) JwtTestHelper.utf8FileToString(com.forgerock.openbanking.aspsp.rs.rcs.api.rcs.JwtTestHelper.utf8FileToString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

FRPaymentSetup (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup)20 Test (org.junit.Test)8 FRAmount (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount)5 FRWriteDomesticConsentData (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticConsentData)5 FRAccount (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount)5 ConsentStatusCode (com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode)5 SinglePaymentService (com.forgerock.openbanking.common.services.store.payment.SinglePaymentService)5 CurrencyConverterException (com.tunyk.currencyconverter.api.CurrencyConverterException)5 Collections (java.util.Collections)5 MoneyService (com.forgerock.openbanking.aspsp.rs.simulator.service.MoneyService)4 PaymentNotificationFacade (com.forgerock.openbanking.aspsp.rs.simulator.service.PaymentNotificationFacade)4 FRCreditDebitIndicator (com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRCreditDebitIndicator)4 FRAccountIdentifier (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier)4 FRWriteDomesticConsent (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticConsent)4 FRWriteDomesticDataInitiation (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticDataInitiation)4 AccountStoreService (com.forgerock.openbanking.common.services.store.account.AccountStoreService)4 Optional (java.util.Optional)4 RunWith (org.junit.runner.RunWith)4 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)4 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)4