use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptFilePaymentTask method autoAcceptPayment.
@Scheduled(fixedRate = 60 * 1000 * 5)
@SchedulerLock(name = "filePayment")
public void autoAcceptPayment() {
log.info("Auto-accept file payment task waking up. The time is now {}.", format.print(DateTime.now()));
final Collection<FRFileConsent> allPaymentsInProcess = filePaymentService.getAllPaymentFilesInProcess();
for (FRFileConsent consent : allPaymentsInProcess) {
log.info("Processing file consent {}", consent);
try {
int paymentNo = 0;
int success = 0;
int reject = 0;
if (consent.getPayments() == null) {
consent.setStatus(ConsentStatusCode.REJECTED);
continue;
}
for (FRFilePayment payment : consent.getPayments()) {
paymentNo++;
try {
if (payment.getStatus() != FRFilePayment.PaymentStatus.PENDING) {
log.debug("Payment '{}' from consent '{}' is not pending", payment, consent.getId());
continue;
}
log.info("Processing pending file payment [{}] : {}", paymentNo, payment);
String identificationTo = moveDebitPayment(payment, consent.getAccountId());
Optional<Account> isAccountToFromOurs = accountStoreService.findAccountByIdentification(identificationTo);
if (isAccountToFromOurs.isPresent()) {
moveCreditPayment(payment, identificationTo, isAccountToFromOurs.get());
} else {
log.info("Account '{}' not ours", identificationTo);
}
log.debug("File payment [{}] succeeded: {}", paymentNo, payment);
success++;
payment.setStatus(FRFilePayment.PaymentStatus.COMPLETED);
} catch (CurrencyConverterException e) {
log.info("Can't convert amount in the right currency for payment within a file. Payment: {}, ConsentId: {}", payment, consent.getId(), e);
log.info("Update individual payment status to rejected - other payments in file may still succeed");
reject++;
payment.setStatus(FRFilePayment.PaymentStatus.REJECTED);
} catch (Exception e) {
log.warn("An individual payment within a file failed. Payment: {}, ConsentId: {}", payment, consent.getId(), e);
log.info("Update individual payment status to rejected - other payments in file may still succeed");
reject++;
payment.setStatus(FRFilePayment.PaymentStatus.REJECTED);
}
}
log.info("Finished file payments for consent: '{}'. {} payments succeeded. {} payments were rejected. Update file consent status to completed", consent.getId(), success, reject);
consent.setStatus(ConsentStatusCode.ACCEPTEDSETTLEMENTCOMPLETED);
log.debug("Consent {}", consent);
} finally {
filePaymentService.updatePayment(consent);
paymentNotificationService.paymentStatusChanged(consent);
}
}
log.info("All file payments in process are now accepted. See you in 5 minutes! The time is now {}.", format.print(DateTime.now()));
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent in project openbanking-aspsp by OpenBankingToolkit.
the class FilePaymentConsentsApiController method createFilePaymentConsentsConsentIdFile.
@Override
public ResponseEntity createFilePaymentConsentsConsentIdFile(@ApiParam(value = "Default", required = true) @Valid @RequestBody String fileParam, @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 = "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, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
log.debug("Received: '{}'", fileParam);
final 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.common.model.openbanking.persistence.payment.FRFileConsent in project openbanking-aspsp by OpenBankingToolkit.
the class FilePaymentsApiController method getFilePaymentsFilePaymentId.
@Override
public ResponseEntity getFilePaymentsFilePaymentId(@ApiParam(value = "FilePaymentId", required = true) @PathVariable("FilePaymentId") String filePaymentId, @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, 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.common.model.openbanking.persistence.payment.FRFileConsent in project openbanking-aspsp by OpenBankingToolkit.
the class FilePaymentsApiController method getFilePaymentsFilePaymentIdReportFile.
@Override
public ResponseEntity getFilePaymentsFilePaymentIdReportFile(@ApiParam(value = "FilePaymentId", required = true) @PathVariable("FilePaymentId") String filePaymentId, @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, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
FRFileConsent consent = fileConsentRepository.findById(filePaymentId).orElseThrow(() -> new OBErrorResponseException(HttpStatus.BAD_REQUEST, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.PAYMENT_ID_NOT_FOUND.toOBError1(filePaymentId)));
log.debug("Consent '{}' exists so generating a report file for type: '{}'", consent.getId(), consent.getStatus(), consent.getFileType());
try {
final String reportFile = paymentReportFileService.createPaymentReport(consent);
log.debug("Generated report file for consent: '{}'", consent.getId());
return ResponseEntity.ok(reportFile);
} catch (UnsupportedFileTypeException exception) {
return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).body("{ \"Description\" : \"Report for file type " + consent.getFileType().getFileType() + " not supported\" }");
}
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent 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 {
final String contentTypeOfFile = request.getHeader(CONTENT_TYPE);
FRFileConsent consent = filePaymentService.getPayment(consentId);
return rsEndpointWrapperService.filePaymentEndpoint().authorization(authorization).payment(consent).xFapiFinancialId(rsEndpointWrapperService.rsConfiguration.financialId).principal(principal).obVersion(getOBVersion(request.getRequestURI())).filters(f -> {
f.verifyFileHash(fileParam);
f.verifyContentTypeHeader(contentTypeOfFile);
f.verifyIdempotencyKeyLength(xIdempotencyKey);
}).execute((String tppId) -> {
HttpHeaders additionalHttpHeaders = new HttpHeaders();
additionalHttpHeaders.add("x-ob-client-id", tppId);
ParameterizedTypeReference<String> ptr = new ParameterizedTypeReference<String>() {
};
return rsStoreGateway.toRsStore(request, additionalHttpHeaders, Collections.emptyMap(), String.class, fileParam);
});
}
Aggregations