use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup in project openbanking-aspsp by OpenBankingToolkit.
the class RCSSinglePaymentDetailsApi 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");
FRPaymentSetup payment = singlePaymentService.getPayment(consentId);
Optional<Tpp> isTpp = tppStoreService.findById(payment.getPispId());
if (!isTpp.isPresent()) {
log.error("The TPP '{}' (Client ID {}) that created this consent id '{}' doesn't exist anymore.", payment.getPispId(), clientId, consentId);
return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_NOT_FOUND_TPP, clientId, consentId);
}
Tpp tpp = isTpp.get();
// Verify the pisp is the same than the one that created this payment ^
verifyTppCreatedPayment(clientId, isTpp.get().getClientId(), consentId);
// Associate the payment to this user
payment.setUserId(username);
singlePaymentService.updatePayment(payment);
return ResponseEntity.ok(SinglePaymentConsentDetails.builder().instructedAmount(toOBActiveOrHistoricCurrencyAndAmount(payment.getInitiation().getInstructedAmount())).accounts(accounts).username(username).logo(tpp.getLogo()).merchantName(payment.getPispName()).clientId(clientId).pispName(payment.getPispName()).paymentReference(Optional.ofNullable(payment.getInitiation().getRemittanceInformation()).map(FRRemittanceInformation::getReference).orElse("")).build());
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup in project openbanking-aspsp by OpenBankingToolkit.
the class PaymentSubmissionsApiController method createPaymentSubmission.
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 = "Setup a single immediate payment", required = true) @Valid @RequestBody OBPaymentSubmission1 paymentSubmission, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
String paymentId = paymentSubmission.getData().getPaymentId();
FRPaymentSetup payment = paymentsService.getPayment(paymentId);
return rsEndpointWrapperService.paymentSubmissionEndpoint().authorization(authorization).xFapiFinancialId(xFapiFinancialId).payment(payment).principal(principal).filters(f -> {
f.verifyPaymentIdWithAccessToken();
f.verifyIdempotencyKeyLength(xIdempotencyKey);
f.verifyPaymentStatus();
f.verifyRiskAndInitiation(toFRWriteDomesticDataInitiation(paymentSubmission.getData().getInitiation()), toFRRisk(paymentSubmission.getRisk()));
f.verifyJwsDetachedSignature(xJwsSignature, request);
}).execute((String tppId) -> {
// Modify the status of the payment
LOGGER.info("Switch status of payment {} to 'accepted settlement in process'.", paymentId);
payment.setStatus(ConsentStatusCode.ACCEPTEDSETTLEMENTINPROCESS);
LOGGER.info("Updating payment");
paymentsService.updatePayment(payment);
HttpHeaders additionalHttpHeaders = new HttpHeaders();
additionalHttpHeaders.add("x-ob-payment-id", paymentId);
return rsStoreGateway.toRsStore(request, additionalHttpHeaders, Collections.emptyMap(), OBPaymentSubmissionResponse1.class, paymentSubmission);
});
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup in project openbanking-aspsp by OpenBankingToolkit.
the class PaymentsApiController method getSingleImmediatePayment.
@Override
public ResponseEntity getSingleImmediatePayment(@ApiParam(value = "Unique identification as assigned by the ASPSP to uniquely identify " + "the payment setup resource.", required = true) @PathVariable("PaymentId") String paymentId, @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) throws OBErrorResponseException {
Optional<FRPaymentSetup> isPaymentSetup = frPaymentSetupRepository.findById(paymentId);
if (isPaymentSetup.isEmpty()) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Payment setup '" + paymentId + "' can't be found");
}
FRPaymentSetup frPaymentSetup = isPaymentSetup.get();
return ResponseEntity.ok(packageIntoPaymentSetupResponse(frPaymentSetup));
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup in project openbanking-aspsp by OpenBankingToolkit.
the class PaymentSubmissionsApiController method getPaymentSubmission.
@Override
public ResponseEntity getPaymentSubmission(@ApiParam(value = "Unique identification as assigned by the ASPSP to uniquely identify " + "the payment submission resource.", required = true) @PathVariable("PaymentSubmissionId") String paymentSubmissionId, @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) throws OBErrorResponseException {
Optional<FRPaymentSubmission> isPaymentSubmission = frPaymentSubmissionRepository.findById(paymentSubmissionId);
if (isPaymentSubmission.isEmpty()) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Payment submission '" + paymentSubmissionId + "' can't be found");
}
FRPaymentSubmission frPaymentSubmission = isPaymentSubmission.get();
Optional<FRPaymentSetup> isPaymentSetup = frPaymentSetupRepository.findById(paymentSubmissionId);
if (isPaymentSetup.isEmpty()) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Payment setup behind payment submission '" + paymentSubmissionId + "' can't be found");
}
FRPaymentSetup frPaymentSetup = isPaymentSetup.get();
return ResponseEntity.ok(packageToPaymentSubmission(frPaymentSubmission, frPaymentSetup));
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptSinglePaymentTask method autoAcceptPayment.
@Scheduled(fixedRate = 60 * 1000)
@SchedulerLock(name = "singlePayment")
public void autoAcceptPayment() {
log.info("Auto-accept payment task waking up. The time is now {}.", format.print(DateTime.now()));
Collection<FRPaymentSetup> allPaymentsInProcess = paymentsService.getAllPaymentsInProcess();
for (FRPaymentSetup payment : allPaymentsInProcess) {
log.info("Processing payment {}", payment);
try {
Account accountTo = accountStoreService.getAccount(payment.getAccountId());
String identificationFrom = moveDebitPayment(payment, accountTo);
Optional<Account> isAccountFromOurs = accountStoreService.findAccountByIdentification(identificationFrom);
if (isAccountFromOurs.isPresent()) {
moveCreditPayment(payment, identificationFrom, isAccountFromOurs.get());
} else {
log.info("Account '{}' not ours", identificationFrom);
}
log.info("Update payment status to completed");
payment.setStatus(ConsentStatusCode.ACCEPTEDSETTLEMENTCOMPLETED);
log.info("Payment {}", payment);
} catch (CurrencyConverterException e) {
log.info("Can't convert amount in the right currency", e);
log.info("Update payment status to rejected");
payment.setStatus(ConsentStatusCode.REJECTED);
log.info("Payment {}", payment);
} catch (Exception e) {
log.error("Couldn't auto-pay payment.", e);
log.info("Update payment status to rejected");
payment.setStatus(ConsentStatusCode.REJECTED);
log.info("Payment {}", payment);
} finally {
paymentsService.updatePayment(payment);
paymentNotificationService.paymentStatusChanged(payment);
}
}
log.info("All payments in process are now accepted. See you in a minutes! The time is now {}.", format.print(DateTime.now()));
}
Aggregations