use of uk.org.openbanking.datamodel.payment.OBWriteInternationalStandingOrder3 in project openbanking-aspsp by OpenBankingToolkit.
the class InternationalStandingOrdersApiController method createInternationalStandingOrders.
@Override
public ResponseEntity<OBWriteInternationalStandingOrderResponse3> createInternationalStandingOrders(@ApiParam(value = "Default", required = true) @Valid @RequestBody OBWriteInternationalStandingOrder3 OBWriteInternationalStandingOrder3Param, @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 {
String consentId = OBWriteInternationalStandingOrder3Param.getData().getConsentId();
FRInternationalStandingOrderConsent payment = paymentsService.getPayment(consentId);
return rsEndpointWrapperService.paymentSubmissionEndpoint().authorization(authorization).xFapiFinancialId(xFapiFinancialId).payment(payment).principal(principal).filters(f -> {
f.verifyPaymentIdWithAccessToken();
f.verifyIdempotencyKeyLength(xIdempotencyKey);
f.verifyPaymentStatus();
f.verifyRiskAndInitiation(toFRWriteInternationalStandingOrderDataInitiation(OBWriteInternationalStandingOrder3Param.getData().getInitiation()), toFRRisk(OBWriteInternationalStandingOrder3Param.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'.", consentId);
payment.setStatus(ConsentStatusCode.ACCEPTEDSETTLEMENTCOMPLETED);
LOGGER.info("Updating payment");
paymentsService.updatePayment(payment);
FRWriteInternationalStandingOrderDataInitiation initiation = payment.getInitiation();
FRStandingOrderData standingOrder = FRStandingOrderData.builder().accountId(payment.getAccountId()).standingOrderStatusCode(FRStandingOrderData.FRStandingOrderStatus.ACTIVE).creditorAccount(initiation.getCreditorAccount()).frequency(initiation.getFrequency()).reference(initiation.getReference()).firstPaymentDateTime(initiation.getFirstPaymentDateTime()).firstPaymentAmount(initiation.getInstructedAmount()).nextPaymentAmount(initiation.getInstructedAmount()).nextPaymentDateTime(frequencyService.getNextDateTime(initiation.getFirstPaymentDateTime(), initiation.getFrequency())).finalPaymentDateTime(initiation.getFinalPaymentDateTime()).finalPaymentAmount(initiation.getInstructedAmount()).standingOrderId(payment.getId()).build();
String pispId = tppStoreService.findPispIdByTppId(tppId);
standingOrderService.createStandingOrder(standingOrder, pispId);
HttpHeaders additionalHttpHeaders = new HttpHeaders();
additionalHttpHeaders.add("x-ob-payment-id", consentId);
return rsStoreGateway.toRsStore(request, additionalHttpHeaders, Collections.emptyMap(), OBWriteInternationalStandingOrderResponse3.class, OBWriteInternationalStandingOrder3Param);
});
}
use of uk.org.openbanking.datamodel.payment.OBWriteInternationalStandingOrder3 in project openbanking-aspsp by OpenBankingToolkit.
the class InternationalStandingOrderPaymentsApiControllerIT method testCreateInternationalStandingOrderPaymentSubmission.
@Test
public void testCreateInternationalStandingOrderPaymentSubmission() throws UnirestException {
// Given
springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
FRInternationalStandingOrderConsent consent = saveConsent();
OBWriteInternationalStandingOrder3 submissionRequest = new OBWriteInternationalStandingOrder3().risk(toOBRisk1(consent.getRisk())).data((new OBWriteDataInternationalStandingOrder3()).consentId(consent.getId()).initiation(toOBInternationalStandingOrder3(consent.getInitiation())));
// When
HttpResponse<OBWriteInternationalStandingOrderResponse3> response = Unirest.post("https://rs-store:" + port + "/open-banking/v3.1.1/pisp/international-standing-orders").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(OBWriteInternationalStandingOrderResponse3.class);
// Then
assertThat(response.getStatus()).isEqualTo(201);
OBWriteInternationalStandingOrderResponse3 consentResponse = response.getBody();
FRInternationalStandingOrderPaymentSubmission submission = submissionRepository.findById(response.getBody().getData().getInternationalStandingOrderId()).get();
assertThat(submission.getId()).isEqualTo(consentResponse.getData().getConsentId());
}
use of uk.org.openbanking.datamodel.payment.OBWriteInternationalStandingOrder3 in project openbanking-aspsp by OpenBankingToolkit.
the class InternationalStandingOrderPaymentsApiControllerIT method testDuplicateStandingOrderPaymentInitiationShouldReturnForbidden.
@Test
public void testDuplicateStandingOrderPaymentInitiationShouldReturnForbidden() throws Exception {
// Given
springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
FRInternationalStandingOrderConsent consent = saveConsent();
FRInternationalStandingOrderPaymentSubmission submission = savePaymentSubmission(consent);
OBWriteInternationalStandingOrder3 obWriteInternational3 = new OBWriteInternationalStandingOrder3();
obWriteInternational3.risk(toOBRisk1(consent.getRisk()));
obWriteInternational3.data((new OBWriteDataInternationalStandingOrder3()).consentId(submission.getId()).initiation(toOBInternationalStandingOrder3(consent.getInitiation())));
// When
HttpResponse<String> response = Unirest.post("https://rs-store:" + port + "/open-banking/v3.1.1/pisp/international-standing-orders").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(obWriteInternational3).asObject(String.class);
// Then
assertThat(response.getStatus()).isEqualTo(403);
}
use of uk.org.openbanking.datamodel.payment.OBWriteInternationalStandingOrder3 in project openbanking-aspsp by OpenBankingToolkit.
the class InternationalStandingOrderPaymentsApiControllerIT method testMissingConsentOnStandingOrderPaymentInitiationShouldReturnNotFound.
@Test
public void testMissingConsentOnStandingOrderPaymentInitiationShouldReturnNotFound() throws Exception {
// Given
springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
FRInternationalStandingOrderConsent consent = JMockData.mock(FRInternationalStandingOrderConsent.class);
consent.setId(IntentType.PAYMENT_DOMESTIC_CONSENT.generateIntentId());
setupTestConsentInitiation(consent.getInitiation());
consent.getRisk().setMerchantCategoryCode(aValidFRRisk().getMerchantCategoryCode());
consent.getRisk().setDeliveryAddress(aValidFRRisk().getDeliveryAddress());
OBWriteInternationalStandingOrder3 submissionRequest = new OBWriteInternationalStandingOrder3().risk(toOBRisk1(consent.getRisk())).data((new OBWriteDataInternationalStandingOrder3()).consentId(consent.getId()).initiation(toOBInternationalStandingOrder3(consent.getInitiation())));
// When
HttpResponse<String> response = Unirest.post("https://rs-store:" + port + "/open-banking/v3.1.1/pisp/international-standing-orders").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(String.class);
// Then
System.err.println("Response:" + response.getBody());
assertThat(response.getStatus()).isEqualTo(400);
}
use of uk.org.openbanking.datamodel.payment.OBWriteInternationalStandingOrder3 in project openbanking-aspsp by OpenBankingToolkit.
the class InternationalStandingOrdersApiController method createInternationalStandingOrders.
@Override
public ResponseEntity<OBWriteInternationalStandingOrderResponse3> createInternationalStandingOrders(@ApiParam(value = "Default", required = true) @Valid @RequestBody OBWriteInternationalStandingOrder3 OBWriteInternationalStandingOrder3Param, @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 {
String consentId = OBWriteInternationalStandingOrder3Param.getData().getConsentId();
FRInternationalStandingOrderConsent payment = paymentsService.getPayment(consentId);
return rsEndpointWrapperService.paymentSubmissionEndpoint().authorization(authorization).xFapiFinancialId(xFapiFinancialId).payment(payment).principal(principal).filters(f -> {
f.verifyPaymentIdWithAccessToken();
f.verifyIdempotencyKeyLength(xIdempotencyKey);
f.verifyPaymentStatus();
f.verifyRiskAndInitiation(toFRWriteInternationalStandingOrderDataInitiation(OBWriteInternationalStandingOrder3Param.getData().getInitiation()), toFRRisk(OBWriteInternationalStandingOrder3Param.getRisk()));
f.verifyJwsDetachedSignature(xJwsSignature, request);
}).execute((String tppId) -> {
// Modify the status of the payment
log.info("Switch status of payment {} to 'accepted settlement in process'.", consentId);
payment.setStatus(ConsentStatusCode.ACCEPTEDSETTLEMENTCOMPLETED);
log.info("Updating payment");
paymentsService.updatePayment(payment);
FRWriteInternationalStandingOrderDataInitiation initiation = payment.getInitiation();
FRStandingOrderData standingOrder = FRStandingOrderData.builder().accountId(payment.getAccountId()).standingOrderStatusCode(FRStandingOrderData.FRStandingOrderStatus.ACTIVE).creditorAccount(initiation.getCreditorAccount()).frequency(initiation.getFrequency()).reference(initiation.getReference()).firstPaymentDateTime(initiation.getFirstPaymentDateTime()).firstPaymentAmount(initiation.getInstructedAmount()).nextPaymentAmount(initiation.getInstructedAmount()).nextPaymentDateTime(frequencyService.getNextDateTime(initiation.getFirstPaymentDateTime(), initiation.getFrequency())).finalPaymentDateTime(initiation.getFinalPaymentDateTime()).finalPaymentAmount(initiation.getInstructedAmount()).standingOrderId(payment.getId()).build();
String pispId = tppStoreService.findPispIdByTppId(tppId);
standingOrderService.createStandingOrder(standingOrder, pispId);
HttpHeaders additionalHttpHeaders = new HttpHeaders();
additionalHttpHeaders.add("x-ob-payment-id", consentId);
return rsStoreGateway.toRsStore(request, additionalHttpHeaders, Collections.emptyMap(), OBWriteInternationalStandingOrderResponse3.class, OBWriteInternationalStandingOrder3Param);
});
}
Aggregations