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));
}
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));
}
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);
});
}
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));
}
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()));
}
Aggregations