use of net.petafuel.styx.api.v1.payment.entity.SinglePaymentInitiation 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.api.v1.payment.entity.SinglePaymentInitiation in project styx by petafuel.
the class SinglePaymentAuthorisationResourceSparkasseTest method A_initiateSinglePayment.
@Test
@Category(IntegrationTest.class)
public void A_initiateSinglePayment() {
Invocation.Builder invocationBuilder = target("/v1/payments/sepa-credit-transfers").request();
invocationBuilder.header("token", pisAccessToken);
invocationBuilder.header("PSU-ID", PSU_ID);
invocationBuilder.header("PSU-BIC", BIC);
invocationBuilder.header("PSU-IP-Address", "192.168.8.78");
invocationBuilder.header("redirectPreferred", true);
Jsonb jsonb = JsonbBuilder.create();
SinglePaymentInitiation singlePaymentInitiation = jsonb.fromJson("{\"payments\":[{\"debtorAccount\":{\"currency\":\"EUR\",\"iban\":\"DE86999999990000001000\"},\"instructedAmount\":{\"currency\":\"EUR\",\"amount\":\"520.00\"},\"creditorAccount\":{\"currency\":\"EUR\",\"iban\":\"DE86999999990000001000\"},\"creditorName\":\"WBG\",\"remittanceInformationUnstructured\":\"Styx TEST\",\"requestedExecutionDate\":\"" + currentDate + "\"}]}", SinglePaymentInitiation.class);
Invocation invocation = invocationBuilder.buildPost(Entity.entity(singlePaymentInitiation, MediaType.APPLICATION_JSON));
PaymentResponse response = invocation.invoke(PaymentResponse.class);
Assertions.assertNotNull(response.getPaymentId());
paymentId = response.getPaymentId();
}
use of net.petafuel.styx.api.v1.payment.entity.SinglePaymentInitiation in project styx by petafuel.
the class SinglePaymentStatusResourceTest method getConsorsSinglePaymentId.
private String getConsorsSinglePaymentId() {
if (consorsSinglePaymentId == null) {
Invocation.Builder invocationBuilder = target("/v1/payments/sepa-credit-transfers").request();
invocationBuilder.header("token", pisAccessToken);
invocationBuilder.header("PSU-ID", "PSU-Successful");
invocationBuilder.header("PSU-BIC", CONSORS_BIC);
invocationBuilder.header("PSU-IP-Address", "192.168.8.78");
invocationBuilder.header("redirectPreferred", true);
Jsonb jsonb = JsonbBuilder.create();
SinglePaymentInitiation singlePaymentInitiation = jsonb.fromJson("{\"payments\":[{\"debtorAccount\":{\"currency\":\"EUR\",\"iban\":\"DE60760300800500123456\"},\"instructedAmount\":{\"currency\":\"EUR\",\"amount\":\"520.00\"},\"creditorAccount\":{\"currency\":\"EUR\",\"iban\":\"DE15500105172295759744\"},\"creditorName\":\"WBG\",\"remittanceInformationUnstructured\":\"Ref.NumberWBG-1222\",\"requestedExecutionDate\":\"" + currentDate + "\"}]}", SinglePaymentInitiation.class);
Invocation invocation = invocationBuilder.buildPost(Entity.entity(singlePaymentInitiation, MediaType.APPLICATION_JSON));
Response response = invocation.invoke(Response.class);
try {
PaymentResponse paymentResponse = jsonb.fromJson(IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8), PaymentResponse.class);
consorsSinglePaymentId = paymentResponse.getPaymentId();
} catch (IOException e) {
return "";
}
}
return consorsSinglePaymentId;
}
use of net.petafuel.styx.api.v1.payment.entity.SinglePaymentInitiation in project styx by petafuel.
the class SinglePaymentAuthorisationResourceFiduciaTest method A_initiateSinglePayment.
@Test
@Category(IntegrationTest.class)
public void A_initiateSinglePayment() {
Invocation.Builder invocationBuilder = target("/v1/payments/sepa-credit-transfers").request();
invocationBuilder.header("token", pisAccessToken);
invocationBuilder.header("PSU-ID", PSU_ID);
invocationBuilder.header("PSU-BIC", BIC);
invocationBuilder.header("PSU-IP-Address", "192.168.8.78");
invocationBuilder.header("redirectPreferred", true);
Jsonb jsonb = JsonbBuilder.create();
SinglePaymentInitiation singlePaymentInitiation = jsonb.fromJson("{\"payments\":[{\"debtorAccount\":{\"currency\":\"EUR\",\"iban\":\"DE39499999600000005111\"},\"instructedAmount\":{\"currency\":\"EUR\",\"amount\":\"520.00\"},\"creditorAccount\":{\"currency\":\"EUR\",\"iban\":\"DE18499999600000005101\"},\"creditorName\":\"WBG\",\"remittanceInformationUnstructured\":\"Ref.NumberWBG-1222\",\"requestedExecutionDate\":\"" + currentDate + "\"}]}", SinglePaymentInitiation.class);
Invocation invocation = invocationBuilder.buildPost(Entity.entity(singlePaymentInitiation, MediaType.APPLICATION_JSON));
PaymentResponse response = invocation.invoke(PaymentResponse.class);
Assertions.assertNotNull(response.getPaymentId());
paymentId = response.getPaymentId();
}
use of net.petafuel.styx.api.v1.payment.entity.SinglePaymentInitiation in project styx by petafuel.
the class FetchSinglePaymentResourceTest method fetchSinglePayment.
@Test
@Category(IntegrationTest.class)
public void fetchSinglePayment() throws IOException {
Invocation.Builder invocationBuilder = target("/v1/payments/sepa-credit-transfers").request();
invocationBuilder.header("token", pisAccessToken);
invocationBuilder.header("PSU-ID", "PSU-Successful");
invocationBuilder.header("PSU-BIC", "CSDBDE71");
invocationBuilder.header("PSU-IP-Address", "192.168.8.78");
invocationBuilder.header("redirectPreferred", true);
Jsonb jsonb = JsonbBuilder.create();
SinglePaymentInitiation singlePaymentInitiation = jsonb.fromJson("{\"payments\":[{\"debtorAccount\":{\"currency\":\"EUR\",\"iban\":\"DE60760300800500123456\"},\"instructedAmount\":{\"currency\":\"EUR\",\"amount\":\"520.00\"},\"creditorAccount\":{\"currency\":\"EUR\",\"iban\":\"DE15500105172295759744\"},\"creditorName\":\"WBG\",\"remittanceInformationUnstructured\":\"Ref.NumberWBG-1222\",\"requestedExecutionDate\":\"" + currentDate + "\"}]}", SinglePaymentInitiation.class);
Invocation invocation = invocationBuilder.buildPost(Entity.entity(singlePaymentInitiation, MediaType.APPLICATION_JSON));
Response response = invocation.invoke(Response.class);
Assertions.assertEquals(201, response.getStatus());
PaymentResponse paymentResponse = jsonb.fromJson(IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8), PaymentResponse.class);
Invocation getPayment = target("/v1/payments/sepa-credit-transfers/" + paymentResponse.getPaymentId()).request().header("token", pisAccessToken).header("PSU-ID", "PSU-Successful").header("PSU-BIC", "CSDBDE71").header("PSU-IP-Address", "192.168.8.78").header("redirectPreferred", true).buildGet();
response = getPayment.invoke(Response.class);
Assertions.assertEquals(200, response.getStatus());
}
Aggregations