use of net.petafuel.styx.core.xs2a.entities.InitiatedPayment in project styx by petafuel.
the class PaymentInitiationResource method initiateSinglePayment.
/**
* Initiate single or future dated payments
*
* @param paymentTypeBean contains which payment product is used
* @param singlePaymentBody contains the request body as parsed json
* @return 201 if successful
* @throws BankRequestFailedException in case the communication between styx and aspsp was not successful
*/
@POST
@Path("/payments/{paymentProduct}")
@RequiresMandatoryHeader
@AcceptsPreStepAuth
public Response initiateSinglePayment(@BeanParam PaymentTypeBean paymentTypeBean, @Valid SinglePaymentInitiation singlePaymentBody) throws BankRequestFailedException {
Optional<SinglePayment> singlePayment = singlePaymentBody.getPayments().stream().findFirst();
if (!singlePayment.isPresent()) {
throw new StyxException(new ResponseEntity("No valid single payment object was found within the payments array", ResponseConstant.BAD_REQUEST, ResponseCategory.ERROR, ResponseOrigin.CLIENT));
}
SinglePayment payment = singlePayment.get();
XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
xs2AFactoryInput.setPayment(payment);
xs2AFactoryInput.setPsu(getPsu());
xs2AFactoryInput.setPaymentService(PaymentService.PAYMENTS);
xs2AFactoryInput.setPaymentProduct(paymentTypeBean.getPaymentProduct());
IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
ioProcessor.modifyInput(xs2AFactoryInput);
PISRequest paymentInitiationRequest = new PISRequestFactory().create(getXS2AStandard().getRequestClassProvider().paymentInitiation(), xs2AFactoryInput);
paymentInitiationRequest.getHeaders().putAll(getAdditionalHeaders());
paymentInitiationRequest.setTppRedirectPreferred(getRedirectPreferred());
paymentInitiationRequest.setXrequestId(ThreadContext.get(RequestUUIDAdapter.REQUEST_UUID));
ioProcessor.modifyRequest(paymentInitiationRequest, xs2AFactoryInput);
InitiatedPayment initiatedPayment = getXS2AStandard().getPis().initiatePayment(paymentInitiationRequest);
PersistentPayment.create(paymentInitiationRequest.getXrequestId(), initiatedPayment.getPaymentId(), (String) getContainerRequestContext().getProperty(AbstractTokenFilter.class.getName()), getXS2AStandard().getAspsp().getBic(), initiatedPayment.getStatus(), PaymentService.PAYMENTS, paymentTypeBean.getPaymentProduct());
if (containerRequestContext.getProperty(PreAuthAccessFilter.class.getName()) != null) {
initiatedPayment.setxRequestId(UUID.fromString(containerRequestContext.getHeaderString(PreAuthAccessFilter.PRE_AUTH_ID)));
}
xs2AFactoryInput.setPaymentId(initiatedPayment.getPaymentId());
ioProcessor.modifyResponse(initiatedPayment, xs2AFactoryInput);
PaymentResponse paymentResponse = new PaymentResponse(initiatedPayment);
SCAApproach approach = SCAHandler.decision(initiatedPayment);
if (approach instanceof OAuth2) {
paymentResponse.getLinks().getScaOAuth().setUrl(((OAuth2) approach).getAuthoriseLink());
}
LOG.info("Initiate single payment bic={} aspsp_name={} aspsp_id={} paymentId={} xrequestid={}", getXS2AStandard().getAspsp().getBic(), getXS2AStandard().getAspsp().getName(), getXS2AStandard().getAspsp().getId(), paymentResponse.getPaymentId(), paymentInitiationRequest.getXrequestId());
AspspUrlMapper aspspUrlMapper = new AspspUrlMapper(PaymentService.PAYMENTS, paymentTypeBean.getPaymentProduct(), paymentResponse.getPaymentId(), null);
paymentResponse.setLinks(aspspUrlMapper.map(paymentResponse.getLinks()));
return Response.status(ResponseConstant.CREATED).entity(paymentResponse).build();
}
use of net.petafuel.styx.core.xs2a.entities.InitiatedPayment in project styx by petafuel.
the class INGScaLinksTest method testHrefSerializer.
@Test
void testHrefSerializer() {
String body = "{\n" + " \"_links\": {\n" + " \"scaRedirect\": \"https://myaccount.ing.com/payment-initiation/023feba0-ce9b-4f6b-be09-0bff281ccb55/XX\",\n" + " \"self\": \"https://preprod-styx.paycenter.de:8452/v1/payments/sepa-credit-transfers/023feba0-ce9b-4f6b-be09-0bff281ccb55\",\n" + " \"status\": \"https://preprod-styx.paycenter.de:8452/v1/payments/sepa-credit-transfers/023feba0-ce9b-4f6b-be09-0bff281ccb55/status\"\n" + " },\n" + " \"paymentId\": \"023feba0-ce9b-4f6b-be09-0bff281ccb55\",\n" + " \"transactionStatus\": \"RCVD\"\n" + "}\n";
String bodyWithHref = "{\n" + " \"_links\": {\n" + " \"scaRedirect\": {\n" + " \"href\": \"https://idp-mock.sparda-n.de.schulung.sparda.de/oauth2/authorize?bic=TEST7999&client_id=PSDDE-BAFIN-125314&redirect_uri=https://preprod-styx.paycenter.de:8450/v1/callbacks/payment/ok/79b19aae-2a6e-4afe-889d-dfe32190fad8&response_type=code&scope=PIS:tx-d6e3b38f7456cd1f2a7088c5588a603a282c5486001c8e50076641256efef369&code_challenge_method=S256&code_challenge=0Tk_vTrN56Lo9tngmcrwqnJDlDY5V3v4jnqfM2b3_bY&state=a6e76223-06b7-490c-a4fa-6cbef4b85c36\"\n" + " },\n" + " \"scaStatus\": {\n" + " \"href\": \"https://preprod-styx.paycenter.de:8452/v1/payments/sepa-credit-transfers/35ngApqKH9d5icGeUcMSlqT5DA9svEL8n0HXL8sqkcBv_IV4muLvF3J7pWTqrZzQh623L3yTr2un-vqsP38W38E8ZcgkupoAptjViDqg52c=_=_psGLvQpt9Q/authorisations/a94c348e-0bd1-416a-a5c2-8dbf15fbdbfd\"\n" + " },\n" + " \"self\": {\n" + " \"href\": \"https://preprod-styx.paycenter.de:8452/v1/payments/sepa-credit-transfers/35ngApqKH9d5icGeUcMSlqT5DA9svEL8n0HXL8sqkcBv_IV4muLvF3J7pWTqrZzQh623L3yTr2un-vqsP38W38E8ZcgkupoAptjViDqg52c=_=_psGLvQpt9Q\"\n" + " },\n" + " \"status\": {\n" + " \"href\": \"https://preprod-styx.paycenter.de:8452/v1/payments/sepa-credit-transfers/35ngApqKH9d5icGeUcMSlqT5DA9svEL8n0HXL8sqkcBv_IV4muLvF3J7pWTqrZzQh623L3yTr2un-vqsP38W38E8ZcgkupoAptjViDqg52c=_=_psGLvQpt9Q/status\"\n" + " }\n" + " },\n" + " \"paymentId\": \"35ngApqKH9d5icGeUcMSlqT5DA9svEL8n0HXL8sqkcBv_IV4muLvF3J7pWTqrZzQh623L3yTr2un-vqsP38W38E8ZcgkupoAptjViDqg52c=_=_psGLvQpt9Q\",\n" + " \"transactionStatus\": \"RCVD\"\n" + "}";
Jsonb jsonb = JsonbBuilder.create();
InitiatedPayment payment1 = jsonb.fromJson(body, InitiatedPayment.class);
InitiatedPayment payment2 = jsonb.fromJson(bodyWithHref, InitiatedPayment.class);
Assertions.assertNotNull(payment1.getPaymentId());
Assertions.assertNotNull(payment1.getLinks().getScaRedirect());
Assertions.assertEquals("https://myaccount.ing.com/payment-initiation/023feba0-ce9b-4f6b-be09-0bff281ccb55/XX", payment1.getLinks().getScaRedirect().getUrl());
Assertions.assertNotNull(payment2.getPaymentId());
Assertions.assertNotNull(payment2.getLinks().getScaRedirect());
Assertions.assertEquals("https://idp-mock.sparda-n.de.schulung.sparda.de/oauth2/authorize?bic=TEST7999&client_id=PSDDE-BAFIN-125314&redirect_uri=https://preprod-styx.paycenter.de:8450/v1/callbacks/payment/ok/79b19aae-2a6e-4afe-889d-dfe32190fad8&response_type=code&scope=PIS:tx-d6e3b38f7456cd1f2a7088c5588a603a282c5486001c8e50076641256efef369&code_challenge_method=S256&code_challenge=0Tk_vTrN56Lo9tngmcrwqnJDlDY5V3v4jnqfM2b3_bY&state=a6e76223-06b7-490c-a4fa-6cbef4b85c36", payment2.getLinks().getScaRedirect().getUrl());
}
use of net.petafuel.styx.core.xs2a.entities.InitiatedPayment in project styx by petafuel.
the class PaymentInitiationResource method initiatePeriodicPayment.
/**
* Initiate a reoccurring payment
*
* @param paymentTypeBean contains which payment product is used
* @param periodicPaymentBody contains the request body as parsed json
* @return 201 if successful
* @throws BankRequestFailedException in case the communication between styx and aspsp was not successful
*/
@POST
@Path("/periodic-payments/{paymentProduct}")
@RequiresMandatoryHeader
@AcceptsPreStepAuth
public Response initiatePeriodicPayment(@BeanParam PaymentTypeBean paymentTypeBean, @Valid PeriodicPaymentInitiation periodicPaymentBody) throws BankRequestFailedException {
Optional<SinglePayment> singlePayment = periodicPaymentBody.getPayments().stream().findFirst();
if (!singlePayment.isPresent()) {
throw new StyxException(new ResponseEntity("No valid payment object was found", ResponseConstant.BAD_REQUEST, ResponseCategory.ERROR, ResponseOrigin.CLIENT));
}
SinglePayment payment = singlePayment.get();
PeriodicPayment periodicPayment = new PeriodicPayment();
periodicPayment.setCreditorAccount(payment.getCreditorAccount());
periodicPayment.setCreditorName(payment.getCreditorName());
periodicPayment.setDebtorAccount(payment.getDebtorAccount());
periodicPayment.setEndToEndIdentification(payment.getEndToEndIdentification());
periodicPayment.setInstructedAmount(payment.getInstructedAmount());
periodicPayment.setRemittanceInformationUnstructured(payment.getRemittanceInformationUnstructured());
periodicPayment.setDayOfExecution(String.valueOf(periodicPaymentBody.getDayOfExecution()));
periodicPayment.setExecutionRule(periodicPaymentBody.getExecutionRule());
periodicPayment.setStartDate(Date.from(periodicPaymentBody.getStartDate().atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()));
periodicPayment.setFrequency(periodicPaymentBody.getFrequency().name());
XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
xs2AFactoryInput.setPayment(periodicPayment);
xs2AFactoryInput.setPsu(getPsu());
xs2AFactoryInput.setPaymentService(PaymentService.PERIODIC_PAYMENTS);
xs2AFactoryInput.setPaymentProduct(paymentTypeBean.getPaymentProduct());
IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
ioProcessor.modifyInput(xs2AFactoryInput);
PISRequest periodicPaymentInitiation = new PISRequestFactory().create(getXS2AStandard().getRequestClassProvider().paymentInitiation(), xs2AFactoryInput);
periodicPaymentInitiation.getHeaders().putAll(getAdditionalHeaders());
ioProcessor.modifyRequest(periodicPaymentInitiation, xs2AFactoryInput);
periodicPaymentInitiation.setTppRedirectPreferred(getRedirectPreferred());
periodicPaymentInitiation.setXrequestId(ThreadContext.get(RequestUUIDAdapter.REQUEST_UUID));
InitiatedPayment initiatedPayment = getXS2AStandard().getPis().initiatePayment(periodicPaymentInitiation);
PaymentResponse paymentResponse = new PaymentResponse(initiatedPayment);
SCAApproach approach = SCAHandler.decision(initiatedPayment);
if (approach instanceof OAuth2) {
paymentResponse.getLinks().getScaOAuth().setUrl(((OAuth2) approach).getAuthoriseLink());
}
LOG.info("Initiate periodic payment bic={} aspsp_name={} aspsp_id={}", getXS2AStandard().getAspsp().getBic(), getXS2AStandard().getAspsp().getName(), getXS2AStandard().getAspsp().getId());
AspspUrlMapper aspspUrlMapper = new AspspUrlMapper(PaymentService.PERIODIC_PAYMENTS, paymentTypeBean.getPaymentProduct(), paymentResponse.getPaymentId(), null);
paymentResponse.setLinks(aspspUrlMapper.map(paymentResponse.getLinks()));
PersistentPayment.create(periodicPaymentInitiation.getXrequestId(), paymentResponse.getPaymentId(), (String) getContainerRequestContext().getProperty(AbstractTokenFilter.class.getName()), getXS2AStandard().getAspsp().getBic(), paymentResponse.getTransactionStatus(), PaymentService.PERIODIC_PAYMENTS, paymentTypeBean.getPaymentProduct());
return Response.status(ResponseConstant.CREATED).entity(paymentResponse).build();
}
use of net.petafuel.styx.core.xs2a.entities.InitiatedPayment in project styx by petafuel.
the class PaymentInitiationResource method initiateBulkPayment.
/**
* Initiate multiple payments as bulk
*
* @param paymentTypeBean contains which payment product is used
* @param bulkPaymentBody contains the request body as parsed json
* @return 201 if successful
* @throws BankRequestFailedException in case the communication between styx and aspsp was not successful
*/
@POST
@Path("/bulk-payments/{paymentProduct}")
@RequiresMandatoryHeader
@AcceptsPreStepAuth
public Response initiateBulkPayment(@BeanParam PaymentTypeBean paymentTypeBean, @Valid BulkPaymentInitiation bulkPaymentBody) throws BankRequestFailedException {
// Debtors should all be the same within the payments, we take one of them
Optional<SinglePayment> singlePayment = bulkPaymentBody.getPayments().stream().findAny();
if (!singlePayment.isPresent()) {
throw new StyxException(new ResponseEntity("No valid payment object was found within the bulk payments array", ResponseConstant.BAD_REQUEST, ResponseCategory.ERROR, ResponseOrigin.CLIENT));
}
AccountReference debtor = bulkPaymentBody.getDebtorAccount();
BulkPayment bulkPayment = new BulkPayment();
bulkPayment.setBatchBookingPreferred(bulkPaymentBody.getBatchBookingPreferred());
bulkPayment.setDebtorAccount(debtor);
bulkPayment.setPayments(bulkPaymentBody.getPayments());
bulkPayment.setRequestedExecutionDate(bulkPaymentBody.getRequestedExecutionDate());
XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
xs2AFactoryInput.setPayment(bulkPayment);
xs2AFactoryInput.setPsu(getPsu());
xs2AFactoryInput.setPaymentService(PaymentService.BULK_PAYMENTS);
xs2AFactoryInput.setPaymentProduct(paymentTypeBean.getPaymentProduct());
IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
ioProcessor.modifyInput(xs2AFactoryInput);
PISRequest bulkpaymentInitiationRequest = new PISRequestFactory().create(getXS2AStandard().getRequestClassProvider().paymentInitiation(), xs2AFactoryInput);
bulkpaymentInitiationRequest.getHeaders().putAll(getAdditionalHeaders());
ioProcessor.modifyRequest(bulkpaymentInitiationRequest, xs2AFactoryInput);
bulkpaymentInitiationRequest.setTppRedirectPreferred(getRedirectPreferred());
bulkpaymentInitiationRequest.setXrequestId(ThreadContext.get(RequestUUIDAdapter.REQUEST_UUID));
InitiatedPayment initiatedPayment = getXS2AStandard().getPis().initiatePayment(bulkpaymentInitiationRequest);
PaymentResponse paymentResponse = new PaymentResponse(initiatedPayment);
SCAApproach approach = SCAHandler.decision(initiatedPayment);
if (approach instanceof OAuth2) {
paymentResponse.getLinks().getScaOAuth().setUrl(((OAuth2) approach).getAuthoriseLink());
}
LOG.info("Initiate bulk payment bic={} aspsp_name={} aspsp_id={} paymentId={}", getXS2AStandard().getAspsp().getBic(), getXS2AStandard().getAspsp().getName(), getXS2AStandard().getAspsp().getId(), paymentResponse.getPaymentId());
AspspUrlMapper aspspUrlMapper = new AspspUrlMapper(PaymentService.BULK_PAYMENTS, paymentTypeBean.getPaymentProduct(), paymentResponse.getPaymentId(), null);
paymentResponse.setLinks(aspspUrlMapper.map(paymentResponse.getLinks()));
PersistentPayment.create(bulkpaymentInitiationRequest.getXrequestId(), paymentResponse.getPaymentId(), (String) getContainerRequestContext().getProperty(AbstractTokenFilter.class.getName()), getXS2AStandard().getAspsp().getBic(), paymentResponse.getTransactionStatus(), PaymentService.BULK_PAYMENTS, paymentTypeBean.getPaymentProduct());
return Response.status(ResponseConstant.CREATED).entity(paymentResponse).build();
}
use of net.petafuel.styx.core.xs2a.entities.InitiatedPayment in project styx by petafuel.
the class SCAHandler method decision.
public static SCAApproach decision(StrongAuthenticatableResource strongAuthenticatableResource) {
SCA sca;
SCAApproach scaMethod = null;
String scope;
ServiceRealm serviceRealm;
if (strongAuthenticatableResource instanceof Consent) {
Consent consent = (Consent) strongAuthenticatableResource;
sca = consent.getSca();
scope = "AIS: " + consent.getId();
serviceRealm = ServiceRealm.CONSENT;
} else if (strongAuthenticatableResource instanceof InitiatedPayment) {
InitiatedPayment payment = (InitiatedPayment) strongAuthenticatableResource;
sca = payment.getSca();
scope = "PIS:" + payment.getPaymentId();
serviceRealm = ServiceRealm.PAYMENT;
} else {
return null;
}
switch(sca.getApproach()) {
case DECOUPLED:
break;
case EMBEDDED:
break;
case OAUTH2:
String link;
if (isLinkBuilt(strongAuthenticatableResource.getLinks().getScaOAuth())) {
link = strongAuthenticatableResource.getLinks().getScaOAuth().getUrl();
} else {
OAuthSession session = OAuthService.startSession(strongAuthenticatableResource, scope);
link = OAuthService.buildLink(session.getState(), strongAuthenticatableResource.getxRequestId(), serviceRealm);
}
scaMethod = new OAuth2(link);
break;
case REDIRECT:
scaMethod = new Redirect(strongAuthenticatableResource.getLinks().getScaRedirect().getUrl());
break;
case REQUIRE_AUTHORISATION_RESOURCE:
// Do nothing
break;
default:
throw new InvalidSCAMethodException("Found SCA Method is unsupported");
}
return scaMethod;
}
Aggregations