Search in sources :

Example 1 with ReportConverter

use of net.petafuel.jsepa.facades.ReportConverter 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)

Aggregations

IOException (java.io.IOException)1 Jsonb (javax.json.bind.Jsonb)1 SEPAParsingException (net.petafuel.jsepa.exception.SEPAParsingException)1 ReportConverter (net.petafuel.jsepa.facades.ReportConverter)1 TransactionReport (net.petafuel.jsepa.model.pain002.TransactionReport)1 PaymentStatus (net.petafuel.styx.core.xs2a.entities.PaymentStatus)1 BankRequestFailedException (net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)1 SerializerException (net.petafuel.styx.core.xs2a.exceptions.SerializerException)1 Response (okhttp3.Response)1