use of net.petafuel.styx.api.v1.payment.entity.PaymentResponse 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.PaymentResponse 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.PaymentResponse in project styx by petafuel.
the class FetchSinglePaymentResourceTest method fetchPeriodicPayment.
@Test
@Category(IntegrationTest.class)
public void fetchPeriodicPayment() throws IOException {
Invocation.Builder invocationBuilder = target("/v1/periodic-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();
PeriodicPaymentInitiation periodicPaymentInitiation = jsonb.fromJson("{\"startDate\":\"" + currentDate + "\",\"dayOfExecution\":31,\"frequency\":\"MNTH\",\"executionRule\":\"following\",\"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 + "\"}]}", PeriodicPaymentInitiation.class);
Invocation invocation = invocationBuilder.buildPost(Entity.entity(periodicPaymentInitiation, 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/periodic-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());
}
use of net.petafuel.styx.api.v1.payment.entity.PaymentResponse in project styx by petafuel.
the class FetchSinglePaymentResourceTest method fetchBulkPayment.
@Test
@Category(IntegrationTest.class)
public void fetchBulkPayment() throws IOException {
Invocation.Builder invocationBuilder = target("/v1/bulk-payments/sepa-credit-transfers").request();
invocationBuilder.header("token", pisAccessToken);
invocationBuilder.header("PSU-ID", "PSU-1234");
invocationBuilder.header("PSU-BIC", "GENODEF1M03");
invocationBuilder.header("PSU-IP-Address", "192.168.8.78");
invocationBuilder.header("redirectPreferred", true);
Jsonb jsonb = JsonbBuilder.create();
BulkPaymentInitiation bulkPaymentInitiation = jsonb.fromJson("{\"debtorAccount\":{\"currency\":\"EUR\",\"iban\":\"DE87200500001234567890\"},\"payments\":[{\"instructedAmount\":{\"currency\":\"EUR\",\"amount\":\"520.00\"},\"creditorAccount\":{\"currency\":\"EUR\",\"iban\":\"DE23100120020123456789\"},\"creditorName\":\"WBG\",\"remittanceInformationUnstructured\":\"Ref.NumberWBG-1222\"},{\"debtorAccount\":{\"currency\":\"EUR\",\"iban\":\"DE87200500001234567890\"},\"instructedAmount\":{\"currency\":\"EUR\",\"amount\":\"32.00\"},\"creditorAccount\":{\"currency\":\"EUR\",\"iban\":\"DE23100120020123456789\"},\"creditorName\":\"Gimmeyourmoney\",\"remittanceInformationUnstructured\":\"Myothervwz\"}]}", BulkPaymentInitiation.class);
Invocation invocation = invocationBuilder.buildPost(Entity.entity(bulkPaymentInitiation, 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/bulk-payments/sepa-credit-transfers/" + paymentResponse.getPaymentId()).request().header("token", pisAccessToken).header("PSU-ID", "PSU-1234").header("PSU-BIC", "GENODEF1M03").header("PSU-IP-Address", "192.168.8.78").header("redirectPreferred", true).buildGet();
response = getPayment.invoke(Response.class);
Assertions.assertEquals(200, response.getStatus());
}
use of net.petafuel.styx.api.v1.payment.entity.PaymentResponse in project styx by petafuel.
the class SinglePaymentStatusResourceTest method getSparkasseBulkPaymentId.
private String getSparkasseBulkPaymentId() {
if (sparkasseBulkPaymentId == null) {
Invocation.Builder invocationBuilder = target("/v1/bulk-payments/sepa-credit-transfers").request();
invocationBuilder.header("token", pisAccessToken);
invocationBuilder.header("PSU-ID", "PSU-Successful");
invocationBuilder.header("PSU-BIC", SPARKASSE_BIC);
invocationBuilder.header("PSU-IP-Address", "192.168.8.78");
invocationBuilder.header("redirectPreferred", true);
Jsonb jsonb = JsonbBuilder.create();
BulkPaymentInitiation bulkPaymentInitiation = jsonb.fromJson("{\"debtorAccount\":{\"currency\":\"EUR\",\"iban\":\"DE86999999990000001000\", \"name\":\"NOTPROVIDED\"},\"payments\":[{\"endToEndIdentification\": \"endToEndId\", \"instructedAmount\":{\"currency\":\"EUR\",\"amount\":\"520.00\"},\"creditorAccount\":{\"currency\":\"EUR\",\"iban\":\"DE75999999990000001004\"},\"creditorName\":\"WBG\",\"remittanceInformationUnstructured\":\"Ref.NumberWBG-1222\"},{\"endToEndIdentification\": \"endToEndId\", \"debtorAccount\":{\"currency\":\"EUR\",\"iban\":\"DE86999999990000001000\"},\"instructedAmount\":{\"currency\":\"EUR\",\"amount\":\"32.00\"},\"creditorAccount\":{\"currency\":\"EUR\",\"iban\":\"DE75999999990000001004\"},\"creditorName\":\"Gimmeyourmoney\",\"remittanceInformationUnstructured\":\"Myothervwz\"}]}", BulkPaymentInitiation.class);
Invocation invocation = invocationBuilder.buildPost(Entity.entity(bulkPaymentInitiation, MediaType.APPLICATION_JSON));
Response response = invocation.invoke(Response.class);
try {
PaymentResponse paymentResponse = jsonb.fromJson(IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8), PaymentResponse.class);
sparkasseBulkPaymentId = paymentResponse.getPaymentId();
} catch (IOException e) {
return "";
}
}
return sparkasseBulkPaymentId;
}
Aggregations