use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent in project openbanking-aspsp by OpenBankingToolkit.
the class DomesticPaymentsApiControllerIT method testCreateDomesticPaymentSubmission.
@Test
public void testCreateDomesticPaymentSubmission() throws UnirestException {
// Given
springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
FRDomesticConsent consent = saveConsent(FRReadRefundAccount.NO);
OBWriteDomestic2 submissionRequest = new OBWriteDomestic2().risk(toOBRisk1(consent.getRisk())).data(new OBWriteDataDomestic2().consentId(consent.getId()).initiation(toOBDomestic2(consent.getInitiation())));
// When
HttpResponse<OBWriteDomesticResponse5> response = Unirest.post(RS_STORE_URL + port + CONTEXT_PATH).header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "token").header(OBHeaders.X_IDEMPOTENCY_KEY, "x-idempotency-key").header(OBHeaders.X_JWS_SIGNATURE, "x-jws-signature").header(OBHeaders.CONTENT_TYPE, "application/json; charset=utf-8").body(submissionRequest).asObject(OBWriteDomesticResponse5.class);
// Then
assertThat(response.getStatus()).isEqualTo(201);
OBWriteDomesticResponse5 consentResponse = response.getBody();
FRDomesticPaymentSubmission submission = submissionRepository.findById(response.getBody().getData().getDomesticPaymentId()).get();
assertThat(submission.getId()).isEqualTo(consentResponse.getData().getConsentId());
assertThat(consentResponse.getData().getRefund()).isNull();
assertThat(toOBWriteDomestic2(submission.getDomesticPayment())).isEqualTo(submissionRequest);
assertThat(submission.getObVersion()).isEqualTo(OBVersion.v3_1_7);
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent in project openbanking-aspsp by OpenBankingToolkit.
the class DomesticPaymentsApiControllerIT method saveConsent.
private FRDomesticConsent saveConsent(FRReadRefundAccount frReadRefundAccount) {
FRDomesticConsent consent = JMockData.mock(FRDomesticConsent.class);
consent.getDomesticConsent().getData().setReadRefundAccount(frReadRefundAccount);
consent.setId(IntentType.PAYMENT_DOMESTIC_CONSENT.generateIntentId());
consent.getInitiation().setInstructedAmount(aValidFRAmount());
consent.getInitiation().setCreditorPostalAddress(aValidFRPostalAddress());
consent.getInitiation().setSupplementaryData(FRSupplementaryData.builder().data("{}").build());
consent.getRisk().setMerchantCategoryCode(aValidFRRisk().getMerchantCategoryCode());
consent.getRisk().setDeliveryAddress(aValidFRRisk().getDeliveryAddress());
consent.setStatus(ConsentStatusCode.ACCEPTEDSETTLEMENTCOMPLETED);
consentRepository.save(consent);
return consent;
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent in project openbanking-aspsp by OpenBankingToolkit.
the class DomesticPaymentsApiControllerIT method testCreateDomesticPaymentSubmission_expectRefundAccount.
@Test
public void testCreateDomesticPaymentSubmission_expectRefundAccount() throws UnirestException {
// Given
springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
FRDomesticConsent consent = saveConsent(FRReadRefundAccount.YES);
OBWriteDomestic2 submissionRequest = new OBWriteDomestic2().risk(toOBRisk1(consent.getRisk())).data(new OBWriteDataDomestic2().consentId(consent.getId()).initiation(toOBDomestic2(consent.getInitiation())));
// When
HttpResponse<OBWriteDomesticResponse5> response = Unirest.post(RS_STORE_URL + port + CONTEXT_PATH).header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "token").header(OBHeaders.X_IDEMPOTENCY_KEY, "x-idempotency-key").header(OBHeaders.X_JWS_SIGNATURE, "x-jws-signature").header(OBHeaders.CONTENT_TYPE, "application/json; charset=utf-8").body(submissionRequest).asObject(OBWriteDomesticResponse5.class);
// Then
assertThat(response.getStatus()).isEqualTo(201);
OBWriteDomesticResponse5 rBody = response.getBody();
FRDomesticPaymentSubmission submission = submissionRepository.findById(response.getBody().getData().getDomesticPaymentId()).get();
assertThat(submission.getId()).isEqualTo(rBody.getData().getConsentId());
// Refund
OBWriteDomesticResponse5DataRefund refund = rBody.getData().getRefund();
assertThat(refund).isNotNull();
assertThat(refund.getAccount().getIdentification()).isEqualTo(consent.getInitiation().getDebtorAccount().getIdentification());
assertThat(refund.getAccount().getName()).isEqualTo(consent.getInitiation().getDebtorAccount().getName());
assertThat(refund.getAccount().getSchemeName()).isEqualTo(consent.getInitiation().getDebtorAccount().getSchemeName());
assertThat(refund.getAccount().getSecondaryIdentification()).isEqualTo(consent.getInitiation().getDebtorAccount().getSecondaryIdentification());
assertThat(toOBWriteDomestic2(submission.getDomesticPayment())).isEqualTo(submissionRequest);
assertThat(submission.getObVersion()).isEqualTo(OBVersion.v3_1_7);
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent in project openbanking-aspsp by OpenBankingToolkit.
the class RCSDomesticPaymentDetailsApi 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");
FRDomesticConsent domesticConsent = paymentService.getPayment(consentId);
// Only show the debtor account if specified in consent
if (domesticConsent.getInitiation().getDebtorAccount() != null) {
Optional<AccountWithBalance> matchingUserAccount = accountService.findAccountByIdentification(domesticConsent.getInitiation().getDebtorAccount().getIdentification(), accounts);
if (matchingUserAccount.isEmpty()) {
log.error("The PISP '{}' created the payment request '{}' but the debtor account: {} on the payment consent " + " is not one of the user's accounts: {}.", domesticConsent.getPispId(), consentId, domesticConsent.getInitiation().getDebtorAccount(), accounts);
return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_DEBTOR_ACCOUNT_NOT_FOUND, domesticConsent.getPispId(), consentId, accounts);
}
accounts = Collections.singletonList(matchingUserAccount.get());
}
Optional<Tpp> isTpp = tppStoreService.findById(domesticConsent.getPispId());
if (isTpp.isEmpty()) {
log.error("The TPP '{}' (Client ID {}) that created this consent id '{}' doesn't exist anymore.", domesticConsent.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, tpp.getClientId(), consentId);
// Associate the payment to this user
domesticConsent.setUserId(username);
paymentService.updatePayment(domesticConsent);
return ResponseEntity.ok(DomesticPaymentConsentDetails.builder().instructedAmount(toOBActiveOrHistoricCurrencyAndAmount(domesticConsent.getInitiation().getInstructedAmount())).accounts(accounts).username(username).logo(tpp.getLogo()).merchantName(domesticConsent.getPispName()).clientId(clientId).paymentReference(Optional.ofNullable(domesticConsent.getInitiation().getRemittanceInformation()).map(FRRemittanceInformation::getReference).orElse("")).build());
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent in project openbanking-aspsp by OpenBankingToolkit.
the class DomesticPaymentConsentsApiControllerIT method testGetDomesticPaymentConsent_refundNull.
@Test
public void testGetDomesticPaymentConsent_refundNull() throws UnirestException {
// Given
springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
FRDomesticConsent consent = saveFRConsent(null, ConsentStatusCode.CONSUMED);
// When
HttpResponse<OBWriteDomesticConsentResponse4> response = Unirest.get(RS_STORE_URL + port + CONTEXT_PATH + consent.getId()).header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "token").asObject(OBWriteDomesticConsentResponse4.class);
log.debug("Response {}:{} {}", response.getStatus(), response.getStatusText(), response.getBody());
if (response.getParsingError().isPresent()) {
log.error("Parsing error", response.getParsingError().get());
}
// Then
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getBody().getData().getConsentId()).isEqualTo(consent.getId());
assertThat(response.getBody().getData().getReadRefundAccount()).isNull();
assertThat(toFRWriteDomesticDataInitiation(response.getBody().getData().getInitiation())).isEqualTo(consent.getInitiation());
assertThat(response.getBody().getData().getStatus().getValue()).isEqualTo(consent.getStatus().toOBExternalConsentStatus2Code().toString());
}
Aggregations