Search in sources :

Example 6 with PeriodicPaymentInitiation

use of net.petafuel.styx.api.v1.payment.entity.PeriodicPaymentInitiation in project styx by petafuel.

the class SinglePaymentInitiationResourceTest method initiatePeriodicPayment_Fiducia.

@Test
@Category(IntegrationTest.class)
public void initiatePeriodicPayment_Fiducia() {
    Jsonb jsonb = JsonbBuilder.create();
    PeriodicPaymentInitiation periodicPaymentInitiation = jsonb.fromJson("{\"startDate\":\"" + currentDate + "\",\"dayOfExecution\":31,\"frequency\":\"MNTH\",\"executionRule\":\"following\",\"payments\":[{\"debtorAccount\":{\"currency\":\"EUR\",\"iban\":\"DE87200500001234567890\"},\"instructedAmount\":{\"currency\":\"EUR\",\"amount\":\"520.00\"},\"creditorAccount\":{\"currency\":\"EUR\",\"iban\":\"DE23100120020123456789\"},\"creditorName\":\"WBG\",\"remittanceInformationUnstructured\":\"Ref.NumberWBG-1222\"}]}", PeriodicPaymentInitiation.class);
    Invocation.Builder invocationBuilder = target("/v1/periodic-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);
    Invocation invocation = invocationBuilder.buildPost(Entity.entity(periodicPaymentInitiation, MediaType.APPLICATION_JSON));
    Response response = invocation.invoke(Response.class);
    Assert.assertEquals(201, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) Jsonb(javax.json.bind.Jsonb) PeriodicPaymentInitiation(net.petafuel.styx.api.v1.payment.entity.PeriodicPaymentInitiation) Invocation(javax.ws.rs.client.Invocation) Category(org.junit.experimental.categories.Category) IntegrationTest(net.petafuel.styx.api.IntegrationTest) Test(org.junit.Test) StyxRESTTest(net.petafuel.styx.api.StyxRESTTest)

Example 7 with PeriodicPaymentInitiation

use of net.petafuel.styx.api.v1.payment.entity.PeriodicPaymentInitiation in project styx by petafuel.

the class SinglePaymentStatusResourceTest method getConsorsPeriodicPaymentId.

private String getConsorsPeriodicPaymentId() {
    if (consorsPeriodicPaymentId == null) {
        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.Builder invocationBuilder = target("/v1/periodic-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);
        Invocation invocation = invocationBuilder.buildPost(Entity.entity(periodicPaymentInitiation, MediaType.APPLICATION_JSON));
        Response response = invocation.invoke(Response.class);
        try {
            PaymentResponse paymentResponse = jsonb.fromJson(IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8), PaymentResponse.class);
            consorsPeriodicPaymentId = paymentResponse.getPaymentId();
        } catch (IOException e) {
            return "";
        }
    }
    return consorsPeriodicPaymentId;
}
Also used : PaymentResponse(net.petafuel.styx.api.v1.payment.entity.PaymentResponse) Response(javax.ws.rs.core.Response) Jsonb(javax.json.bind.Jsonb) PeriodicPaymentInitiation(net.petafuel.styx.api.v1.payment.entity.PeriodicPaymentInitiation) Invocation(javax.ws.rs.client.Invocation) InputStream(java.io.InputStream) IOException(java.io.IOException) PaymentResponse(net.petafuel.styx.api.v1.payment.entity.PaymentResponse)

Example 8 with PeriodicPaymentInitiation

use of net.petafuel.styx.api.v1.payment.entity.PeriodicPaymentInitiation in project styx by petafuel.

the class PeriodicPaymentResourceSparkasseTest method A_initiatePeriodicPayment.

@Test
@Category(IntegrationTest.class)
public void A_initiatePeriodicPayment() {
    Invocation.Builder invocationBuilder = target("/v1/periodic-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();
    String requestBody = "{\"startDate\":\"" + currentDate + "\",\"dayOfExecution\":31,\"frequency\":\"MNTH\",\"executionRule\":\"following\",\"payments\":[{\"debtorAccount\":{\"currency\":\"EUR\",\"iban\":\"DE86999999990000001000\"},\"instructedAmount\":{\"currency\":\"EUR\",\"amount\":\"1.00\"},\"creditorAccount\":{\"currency\":\"EUR\",\"iban\":\"DE98999999990000009999\"},\"creditorName\":\"WBG\",\"remittanceInformationUnstructured\":\"Test\",\"requestedExecutionDate\":\"" + currentDate + "\"}]}";
    PeriodicPaymentInitiation periodicPaymentInitiation = jsonb.fromJson(requestBody, PeriodicPaymentInitiation.class);
    Invocation invocation = invocationBuilder.buildPost(Entity.entity(periodicPaymentInitiation, MediaType.APPLICATION_JSON));
    PaymentResponse response = invocation.invoke(PaymentResponse.class);
    Assertions.assertNotNull(response.getPaymentId());
    paymentId = response.getPaymentId();
}
Also used : Jsonb(javax.json.bind.Jsonb) Invocation(javax.ws.rs.client.Invocation) PeriodicPaymentInitiation(net.petafuel.styx.api.v1.payment.entity.PeriodicPaymentInitiation) 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 9 with PeriodicPaymentInitiation

use of net.petafuel.styx.api.v1.payment.entity.PeriodicPaymentInitiation 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();
}
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) PeriodicPayment(net.petafuel.styx.core.xs2a.entities.PeriodicPayment) 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)

Aggregations

Jsonb (javax.json.bind.Jsonb)8 Invocation (javax.ws.rs.client.Invocation)8 PeriodicPaymentInitiation (net.petafuel.styx.api.v1.payment.entity.PeriodicPaymentInitiation)8 Response (javax.ws.rs.core.Response)6 IntegrationTest (net.petafuel.styx.api.IntegrationTest)6 StyxRESTTest (net.petafuel.styx.api.StyxRESTTest)6 PaymentResponse (net.petafuel.styx.api.v1.payment.entity.PaymentResponse)6 Test (org.junit.Test)6 Category (org.junit.experimental.categories.Category)6 InputStream (java.io.InputStream)3 IOException (java.io.IOException)2 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 ResponseEntity (net.petafuel.styx.api.exception.ResponseEntity)1 StyxException (net.petafuel.styx.api.exception.StyxException)1 AcceptsPreStepAuth (net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth)1 AbstractTokenFilter (net.petafuel.styx.api.filter.authentication.control.AbstractTokenFilter)1 RequiresMandatoryHeader (net.petafuel.styx.api.filter.input.boundary.RequiresMandatoryHeader)1 AspspUrlMapper (net.petafuel.styx.api.util.AspspUrlMapper)1 IOProcessor (net.petafuel.styx.core.ioprocessing.IOProcessor)1