use of net.petafuel.jsepa.model.pain002.TransactionReport 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);
}
}
Aggregations