Search in sources :

Example 11 with FRPaymentSetup

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());
}
Also used : FRRemittanceInformation(com.forgerock.openbanking.common.model.openbanking.domain.payment.common.FRRemittanceInformation) Tpp(com.forgerock.openbanking.model.Tpp) FRPaymentSetup(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup)

Example 12 with FRPaymentSetup

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);
    });
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RsStoreGateway(com.forgerock.openbanking.common.services.store.RsStoreGateway) SinglePaymentService(com.forgerock.openbanking.common.services.store.payment.SinglePaymentService) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) Autowired(org.springframework.beans.factory.annotation.Autowired) Controller(org.springframework.stereotype.Controller) OBPaymentSubmission1(uk.org.openbanking.datamodel.payment.paymentsubmission.OBPaymentSubmission1) DateTimeFormat(org.springframework.format.annotation.DateTimeFormat) RequestBody(org.springframework.web.bind.annotation.RequestBody) Valid(javax.validation.Valid) HttpServletRequest(javax.servlet.http.HttpServletRequest) ConsentStatusCode(com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode) HTTP_DATE_FORMAT(com.forgerock.openbanking.constants.OpenBankingConstants.HTTP_DATE_FORMAT) RSEndpointWrapperService(com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService) FRPaymentSetup(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup) FRWriteDomesticConsentConverter.toFRWriteDomesticDataInitiation(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteDomesticConsentConverter.toFRWriteDomesticDataInitiation) Logger(org.slf4j.Logger) HttpHeaders(org.springframework.http.HttpHeaders) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) Principal(java.security.Principal) OBPaymentSubmissionResponse1(uk.org.openbanking.datamodel.payment.paymentsubmission.OBPaymentSubmissionResponse1) ResponseEntity(org.springframework.http.ResponseEntity) RequestHeader(org.springframework.web.bind.annotation.RequestHeader) FRPaymentRiskConverter.toFRRisk(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRPaymentRiskConverter.toFRRisk) Collections(java.util.Collections) HttpHeaders(org.springframework.http.HttpHeaders) FRPaymentSetup(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup)

Example 13 with FRPaymentSetup

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));
}
Also used : FRPaymentSetup(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup)

Example 14 with 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));
}
Also used : FRPaymentSubmission(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSubmission) FRPaymentSetup(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup)

Example 15 with 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()));
}
Also used : Account(com.forgerock.openbanking.common.model.openbanking.persistence.account.Account) CurrencyConverterException(com.tunyk.currencyconverter.api.CurrencyConverterException) FRPaymentSetup(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup) CurrencyConverterException(com.tunyk.currencyconverter.api.CurrencyConverterException) Scheduled(org.springframework.scheduling.annotation.Scheduled) SchedulerLock(net.javacrumbs.shedlock.core.SchedulerLock)

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