use of com.forgerock.openbanking.exceptions.OBErrorResponseException 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));
}
use of com.forgerock.openbanking.exceptions.OBErrorResponseException in project openbanking-aspsp by OpenBankingToolkit.
the class FilePaymentConsentsApiController method createFilePaymentConsentsConsentIdFile.
public ResponseEntity<Void> createFilePaymentConsentsConsentIdFile(String fileParam, String consentId, String authorization, String xIdempotencyKey, String xJwsSignature, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
log.trace("Received: '{}'", fileParam);
FRFileConsent fileConsent = fileConsentRepository.findById(consentId).orElseThrow(() -> new OBErrorResponseException(HttpStatus.BAD_REQUEST, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.PAYMENT_ID_NOT_FOUND.toOBError1()));
// If file already exists it could be idempotent request
if (!StringUtils.isEmpty(fileConsent.getFileContent())) {
if (xIdempotencyKey.equals(fileConsent.getIdempotencyKey())) {
validateIdempotencyRequest(xIdempotencyKey, fileConsent);
log.info("File already exists for consent: '{}' and has matching idempotent key: '{}'. No action taken but returning 200/OK");
return ResponseEntity.ok().build();
} else {
log.debug("This consent already has a file uploaded and the idempotency key does not match the previous upload so rejecting.");
throw new OBErrorResponseException(HttpStatus.FORBIDDEN, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.PAYMENT_ALREADY_SUBMITTED.toOBError1(fileConsent.getStatus().toOBExternalConsentStatus2Code()));
}
}
// We parse the file and check metadata against the parsed file
try {
PaymentFile paymentFile = PaymentFileFactory.createPaymentFile(fileConsent.getFileType(), fileParam);
log.info("Successfully parsed file of type: '{}' for consent: '{}'", fileConsent.getFileType(), fileConsent.getId());
FileTransactionCountValidator.validate(fileConsent, paymentFile);
ControlSumValidator.validate(fileConsent, paymentFile);
fileConsent.setPayments(paymentFile.getPayments());
fileConsent.setFileContent(fileParam);
fileConsent.setUpdated(new Date());
fileConsent.setStatus(ConsentStatusCode.AWAITINGAUTHORISATION);
fileConsent.setStatusUpdate(DateTime.now());
fileConsentRepository.save(fileConsent);
} catch (OBErrorException e) {
throw new OBErrorResponseException(e.getObriErrorType().getHttpStatus(), OBRIErrorResponseCategory.REQUEST_INVALID, e.getOBError());
}
return ResponseEntity.ok().build();
}
use of com.forgerock.openbanking.exceptions.OBErrorResponseException in project openbanking-aspsp by OpenBankingToolkit.
the class FilePaymentsApiController method getFilePaymentsFilePaymentId.
public ResponseEntity<OBWriteFileResponse2> getFilePaymentsFilePaymentId(String filePaymentId, String authorization, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
Optional<FRFilePaymentSubmission> isPaymentSubmission = filePaymentSubmissionRepository.findById(filePaymentId);
if (!isPaymentSubmission.isPresent()) {
throw new OBErrorResponseException(HttpStatus.BAD_REQUEST, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.PAYMENT_SUBMISSION_NOT_FOUND.toOBError1(filePaymentId));
}
FRFilePaymentSubmission frPaymentSubmission = isPaymentSubmission.get();
Optional<FRFileConsent> isPaymentSetup = fileConsentRepository.findById(filePaymentId);
if (!isPaymentSetup.isPresent()) {
throw new OBErrorResponseException(HttpStatus.BAD_REQUEST, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.PAYMENT_CONSENT_BEHIND_SUBMISSION_NOT_FOUND.toOBError1(filePaymentId));
}
FRFileConsent frPaymentSetup = isPaymentSetup.get();
return ResponseEntity.ok(responseEntity(frPaymentSubmission, frPaymentSetup));
}
use of com.forgerock.openbanking.exceptions.OBErrorResponseException in project openbanking-aspsp by OpenBankingToolkit.
the class FilePaymentsApiController method createFilePayments.
public ResponseEntity<OBWriteFileResponse2> createFilePayments(OBWriteFile2 obWriteFile2, 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: '{}'", obWriteFile2);
FRWriteFile frWriteFile = toFRWriteFile(obWriteFile2);
log.trace("Converted to: '{}'", frWriteFile);
String paymentId = obWriteFile2.getData().getConsentId();
FRFileConsent paymentConsent = fileConsentRepository.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);
FRFilePaymentSubmission frPaymentSubmission = FRFilePaymentSubmission.builder().id(paymentId).filePayment(frWriteFile).created(new Date()).updated(new Date()).idempotencyKey(xIdempotencyKey).obVersion(VersionPathExtractor.getVersionFromPath(request)).build();
frPaymentSubmission = new IdempotentRepositoryAdapter<>(filePaymentSubmissionRepository).idempotentSave(frPaymentSubmission);
return ResponseEntity.status(HttpStatus.CREATED).body(responseEntity(frPaymentSubmission, paymentConsent));
}
use of com.forgerock.openbanking.exceptions.OBErrorResponseException in project openbanking-aspsp by OpenBankingToolkit.
the class DomesticScheduledPaymentsApiController method createDomesticScheduledPayments.
public ResponseEntity<OBWriteDomesticScheduledResponse5> createDomesticScheduledPayments(OBWriteDomesticScheduled2 obWriteDomesticScheduled2, 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: '{}'", obWriteDomesticScheduled2);
FRWriteDomesticScheduled frWriteDomesticScheduled = toFRWriteDomesticScheduled(obWriteDomesticScheduled2);
log.trace("Converted to: '{}'", frWriteDomesticScheduled);
String paymentId = obWriteDomesticScheduled2.getData().getConsentId();
FRDomesticScheduledConsent paymentConsent = domesticScheduledConsentRepository.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);
// Save Payment
FRDomesticScheduledPaymentSubmission frPaymentSubmission = FRDomesticScheduledPaymentSubmission.builder().id(paymentId).domesticScheduledPayment(frWriteDomesticScheduled).created(new Date()).updated(new Date()).idempotencyKey(xIdempotencyKey).obVersion(VersionPathExtractor.getVersionFromPath(request)).build();
frPaymentSubmission = new IdempotentRepositoryAdapter<>(domesticScheduledPaymentSubmissionRepository).idempotentSave(frPaymentSubmission);
return ResponseEntity.status(HttpStatus.CREATED).body(responseEntity(frPaymentSubmission, paymentConsent));
}
Aggregations