Search in sources :

Example 1 with PaymentResponse

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();
}
Also used : OAuth2(net.petafuel.styx.core.xs2a.sca.OAuth2) SCAApproach(net.petafuel.styx.core.xs2a.sca.SCAApproach) AspspUrlMapper(net.petafuel.styx.api.util.AspspUrlMapper) SinglePayment(net.petafuel.styx.core.xs2a.entities.SinglePayment) StyxException(net.petafuel.styx.api.exception.StyxException) PaymentResponse(net.petafuel.styx.api.v1.payment.entity.PaymentResponse) ResponseEntity(net.petafuel.styx.api.exception.ResponseEntity) PISRequest(net.petafuel.styx.core.xs2a.contracts.PISRequest) PISRequestFactory(net.petafuel.styx.core.xs2a.factory.PISRequestFactory) AbstractTokenFilter(net.petafuel.styx.api.filter.authentication.control.AbstractTokenFilter) XS2AFactoryInput(net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput) InitiatedPayment(net.petafuel.styx.core.xs2a.entities.InitiatedPayment) IOProcessor(net.petafuel.styx.core.ioprocessing.IOProcessor) Path(javax.ws.rs.Path) AcceptsPreStepAuth(net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth) RequiresMandatoryHeader(net.petafuel.styx.api.filter.input.boundary.RequiresMandatoryHeader) POST(javax.ws.rs.POST)

Example 2 with PaymentResponse

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();
}
Also used : SinglePaymentInitiation(net.petafuel.styx.api.v1.payment.entity.SinglePaymentInitiation) Jsonb(javax.json.bind.Jsonb) Invocation(javax.ws.rs.client.Invocation) PaymentResponse(net.petafuel.styx.api.v1.payment.entity.PaymentResponse) Category(org.junit.experimental.categories.Category) IntegrationTest(net.petafuel.styx.api.IntegrationTest) Test(org.junit.Test) StyxRESTTest(net.petafuel.styx.api.StyxRESTTest)

Example 3 with PaymentResponse

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());
}
Also used : PaymentResponse(net.petafuel.styx.api.v1.payment.entity.PaymentResponse) Response(javax.ws.rs.core.Response) Jsonb(javax.json.bind.Jsonb) Invocation(javax.ws.rs.client.Invocation) PeriodicPaymentInitiation(net.petafuel.styx.api.v1.payment.entity.PeriodicPaymentInitiation) InputStream(java.io.InputStream) PaymentResponse(net.petafuel.styx.api.v1.payment.entity.PaymentResponse) Category(org.junit.experimental.categories.Category) StyxRESTTest(net.petafuel.styx.api.StyxRESTTest) IntegrationTest(net.petafuel.styx.api.IntegrationTest) Test(org.junit.Test)

Example 4 with PaymentResponse

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());
}
Also used : PaymentResponse(net.petafuel.styx.api.v1.payment.entity.PaymentResponse) Response(javax.ws.rs.core.Response) Jsonb(javax.json.bind.Jsonb) Invocation(javax.ws.rs.client.Invocation) InputStream(java.io.InputStream) BulkPaymentInitiation(net.petafuel.styx.api.v1.payment.entity.BulkPaymentInitiation) PaymentResponse(net.petafuel.styx.api.v1.payment.entity.PaymentResponse) Category(org.junit.experimental.categories.Category) StyxRESTTest(net.petafuel.styx.api.StyxRESTTest) IntegrationTest(net.petafuel.styx.api.IntegrationTest) Test(org.junit.Test)

Example 5 with PaymentResponse

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;
}
Also used : PaymentResponse(net.petafuel.styx.api.v1.payment.entity.PaymentResponse) Response(javax.ws.rs.core.Response) Jsonb(javax.json.bind.Jsonb) Invocation(javax.ws.rs.client.Invocation) InputStream(java.io.InputStream) BulkPaymentInitiation(net.petafuel.styx.api.v1.payment.entity.BulkPaymentInitiation) IOException(java.io.IOException) PaymentResponse(net.petafuel.styx.api.v1.payment.entity.PaymentResponse)

Aggregations

PaymentResponse (net.petafuel.styx.api.v1.payment.entity.PaymentResponse)18 Jsonb (javax.json.bind.Jsonb)15 Invocation (javax.ws.rs.client.Invocation)15 InputStream (java.io.InputStream)10 Response (javax.ws.rs.core.Response)10 IntegrationTest (net.petafuel.styx.api.IntegrationTest)10 StyxRESTTest (net.petafuel.styx.api.StyxRESTTest)10 Test (org.junit.Test)10 Category (org.junit.experimental.categories.Category)10 SinglePaymentInitiation (net.petafuel.styx.api.v1.payment.entity.SinglePaymentInitiation)7 IOException (java.io.IOException)6 PeriodicPaymentInitiation (net.petafuel.styx.api.v1.payment.entity.PeriodicPaymentInitiation)5 SinglePayment (net.petafuel.styx.core.xs2a.entities.SinglePayment)4 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 ResponseEntity (net.petafuel.styx.api.exception.ResponseEntity)3 StyxException (net.petafuel.styx.api.exception.StyxException)3 AcceptsPreStepAuth (net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth)3 AbstractTokenFilter (net.petafuel.styx.api.filter.authentication.control.AbstractTokenFilter)3 RequiresMandatoryHeader (net.petafuel.styx.api.filter.input.boundary.RequiresMandatoryHeader)3