Search in sources :

Example 1 with PaymentStatus

use of net.petafuel.styx.core.xs2a.entities.PaymentStatus in project styx by petafuel.

the class BerlinGroupPIS method getPaymentStatus.

@Override
public PaymentStatus getPaymentStatus(PISRequest xs2AGetRequest) throws BankRequestFailedException {
    this.setUrl(this.url + xs2AGetRequest.getServicePath());
    this.createBody(RequestType.GET);
    if (xs2AGetRequest.getPaymentProduct().isXml()) {
        xs2AGetRequest.addHeader(XS2AHeader.ACCEPT, XML.toString());
    } else {
        xs2AGetRequest.addHeader(XS2AHeader.ACCEPT, JSON.toString());
    }
    this.createHeaders(xs2AGetRequest);
    try (Response response = this.execute();
        Jsonb jsonb = JsonbBuilder.create()) {
        String contentType;
        if ((contentType = response.headers().get("content-type")) == null) {
            throw new BankRequestFailedException("Content-Type Header is not set, parsing of json or xml is not possible", response.code());
        }
        String responseBody = extractResponseBody(response, 200);
        if (contentType.contains(MediaType.APPLICATION_JSON)) {
            return jsonb.fromJson(responseBody, PaymentStatus.class);
        } else {
            ReportConverter converter = new ReportConverter();
            TransactionReport report = converter.processReport(responseBody);
            return new PaymentStatus(TransactionStatus.valueOf(report.getStatus()), null);
        }
    } catch (IOException | SEPAParsingException e) {
        throw new BankRequestFailedException(e.getMessage(), e);
    } catch (Exception e) {
        throw new SerializerException("Unable to deserialize json to PaymentStatus", e);
    }
}
Also used : Response(okhttp3.Response) Jsonb(javax.json.bind.Jsonb) ReportConverter(net.petafuel.jsepa.facades.ReportConverter) SEPAParsingException(net.petafuel.jsepa.exception.SEPAParsingException) TransactionReport(net.petafuel.jsepa.model.pain002.TransactionReport) IOException(java.io.IOException) SerializerException(net.petafuel.styx.core.xs2a.exceptions.SerializerException) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException) PaymentStatus(net.petafuel.styx.core.xs2a.entities.PaymentStatus) SerializerException(net.petafuel.styx.core.xs2a.exceptions.SerializerException) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException) SEPAParsingException(net.petafuel.jsepa.exception.SEPAParsingException) IOException(java.io.IOException)

Example 2 with PaymentStatus

use of net.petafuel.styx.core.xs2a.entities.PaymentStatus in project styx by petafuel.

the class UniCreditPISIntegrationTest method getSinglePaymentStatus.

@Test
@Category(IntegrationTest.class)
public void getSinglePaymentStatus() throws IOException {
    for (Map<String, String> testEntry : testData) {
        String singlePaymentId = testEntry.get("paymentId");
        String bic = testEntry.get("bic");
        Invocation invocation = target("/v1/payments/sepa-credit-transfers/" + singlePaymentId + "/status").request().header("token", pisAccessToken).header("PSU-ID", "bgdemo").header("PSU-BIC", bic).buildGet();
        Response response = invocation.invoke(Response.class);
        Assertions.assertEquals(200, response.getStatus());
        Jsonb jsonb = JsonbBuilder.create();
        PaymentStatus paymentStatus = jsonb.fromJson(IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8), PaymentStatus.class);
        Assertions.assertEquals(TransactionStatus.RCVD.getName(), paymentStatus.getTransactionStatus().getName());
    }
}
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) PaymentStatus(net.petafuel.styx.core.xs2a.entities.PaymentStatus) Category(org.junit.experimental.categories.Category) StyxRESTTest(net.petafuel.styx.api.StyxRESTTest) IntegrationTest(net.petafuel.styx.api.IntegrationTest) Test(org.junit.Test)

Example 3 with PaymentStatus

use of net.petafuel.styx.core.xs2a.entities.PaymentStatus in project styx by petafuel.

the class PaymentStatusPoll method poll.

private void poll() {
    if (((new Date().getTime()) - startTimestamp) >= maxExecutionTime) {
        throw new TaskFinalFailureException(String.format("Max execution time of %s was reached", maxExecutionTime), TaskFinalFailureCode.EXCEEDED_MAX_EXECUTION_TIME);
    } else if (maxRequestFailures != 0 && currentRequestFailures >= maxRequestFailures) {
        throw new TaskFinalFailureException(String.format("Max xs2a request failures reached %s out of %s", currentRequestFailures, maxRequestFailures), TaskFinalFailureCode.EXCEEDED_MAX_XS2A_REQUEST_FAILURES);
    }
    HookStatus hookStatus;
    PaymentStatus paymentStatus;
    try {
        String authorisationHeader = this.checkAccessToken(xRequestId);
        paymentStatusRequest.setAuthorization(authorisationHeader);
        this.ioProcessor.modifyRequest(paymentStatusRequest, xs2aFactoryInput);
        paymentStatus = xs2AStandard.getPis().getPaymentStatus(paymentStatusRequest);
        this.ioProcessor.modifyResponse(paymentStatus, xs2aFactoryInput);
        hookStatus = hookImpl.onStatusUpdate(paymentStatus);
    } catch (BankRequestFailedException e) {
        currentRequestFailures += 1;
        LOG.warn("Request towards the ASPSP failed. maxRequestFailures={}, currentRequestFailures={}", maxRequestFailures, currentRequestFailures, e);
        return;
    }
    if (hookStatus == HookStatus.SUCCESS) {
        LOG.info("PaymentStatus Hook was successful, calling Service Provider onSuccess and cancel task execution");
        hookImpl.onSuccess(payment);
        future.cancel(true);
    } else if (hookStatus == HookStatus.FAILURE) {
        LOG.info("PaymentStatus Hook failed, calling Service Provider onFailure and cancel task execution");
        hookImpl.onFailure(payment);
        future.cancel(true);
    }
}
Also used : HookStatus(net.petafuel.styx.spi.paymentstatushook.api.HookStatus) TaskFinalFailureException(net.petafuel.styx.keepalive.entities.TaskFinalFailureException) Date(java.util.Date) PaymentStatus(net.petafuel.styx.core.xs2a.entities.PaymentStatus) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)

Example 4 with PaymentStatus

use of net.petafuel.styx.core.xs2a.entities.PaymentStatus in project styx by petafuel.

the class PaymentStatusResource method getSinglePaymentStatus.

/**
 * Returns the status of a payment
 *
 * @param paymentTypeBean payment-service and payment-product
 * @param paymentId       id of the target payment
 * @return a PaymentStatus object
 * @throws BankRequestFailedException if something went wrong between the core service and the aspsp
 */
@AcceptsPreStepAuth
@GET
@Path("/{paymentService}/{paymentProduct}/{paymentId}/status")
public Response getSinglePaymentStatus(@BeanParam PaymentTypeBean paymentTypeBean, @PathParam("paymentId") @NotEmpty @NotBlank String paymentId) throws BankRequestFailedException {
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setPaymentService(paymentTypeBean.getPaymentService());
    xs2AFactoryInput.setPaymentProduct(paymentTypeBean.getPaymentProduct());
    xs2AFactoryInput.setPaymentId(paymentId);
    xs2AFactoryInput.setPsu(getPsu());
    IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
    ioProcessor.modifyInput(xs2AFactoryInput);
    PISRequest readPaymentStatusRequest = new PISRequestFactory().create(getXS2AStandard().getRequestClassProvider().paymentStatus(), xs2AFactoryInput);
    readPaymentStatusRequest.getHeaders().putAll(getAdditionalHeaders());
    ioProcessor.modifyRequest(readPaymentStatusRequest, xs2AFactoryInput);
    PaymentStatus status = getXS2AStandard().getPis().getPaymentStatus(readPaymentStatusRequest);
    if (PersistentPayment.getByPaymentId(paymentId) == null) {
        PersistentPayment.create(ThreadContext.get("requestUUID"), paymentId, (String) getContainerRequestContext().getProperty(AbstractTokenFilter.class.getName()), getXS2AStandard().getAspsp().getBic(), status.getTransactionStatus(), paymentTypeBean.getPaymentService(), paymentTypeBean.getPaymentProduct());
    } else {
        PersistentPayment.updateStatusByPaymentId(paymentId, status.getTransactionStatus());
    }
    LOG.info("Successfully read the payment status entity for bic={}, paymentId={}", getXS2AStandard().getAspsp().getBic(), paymentId);
    return Response.status(200).entity(status).build();
}
Also used : 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) IOProcessor(net.petafuel.styx.core.ioprocessing.IOProcessor) PaymentStatus(net.petafuel.styx.core.xs2a.entities.PaymentStatus) AcceptsPreStepAuth(net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

PaymentStatus (net.petafuel.styx.core.xs2a.entities.PaymentStatus)4 Jsonb (javax.json.bind.Jsonb)2 BankRequestFailedException (net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Invocation (javax.ws.rs.client.Invocation)1 Response (javax.ws.rs.core.Response)1 SEPAParsingException (net.petafuel.jsepa.exception.SEPAParsingException)1 ReportConverter (net.petafuel.jsepa.facades.ReportConverter)1 TransactionReport (net.petafuel.jsepa.model.pain002.TransactionReport)1 IntegrationTest (net.petafuel.styx.api.IntegrationTest)1 StyxRESTTest (net.petafuel.styx.api.StyxRESTTest)1 AcceptsPreStepAuth (net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth)1 AbstractTokenFilter (net.petafuel.styx.api.filter.authentication.control.AbstractTokenFilter)1 PaymentResponse (net.petafuel.styx.api.v1.payment.entity.PaymentResponse)1 IOProcessor (net.petafuel.styx.core.ioprocessing.IOProcessor)1 PISRequest (net.petafuel.styx.core.xs2a.contracts.PISRequest)1