use of net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException in project styx by petafuel.
the class BerlinGroupPIS method initiatePayment.
@Override
public InitiatedPayment initiatePayment(PISRequest xs2ARequest) throws BankRequestFailedException {
PaymentProduct product = xs2ARequest.getPaymentProduct();
if (product.isXml()) {
if (xs2ARequest.getPaymentService().equals(PaymentService.PERIODIC_PAYMENTS)) {
// in case of multipart http message get boundary from request
okhttp3.MediaType mt = okhttp3.MediaType.get("multipart/form-data; boundary=" + xs2ARequest.getMultipartBoundary());
this.createBody(RequestType.POST, mt, xs2ARequest);
} else {
this.createBody(RequestType.POST, XML, xs2ARequest);
xs2ARequest.setContentType("application/xml");
}
} else {
this.createBody(RequestType.POST, JSON, xs2ARequest);
xs2ARequest.setContentType(BasicService.JSON.toString());
xs2ARequest.setAccept(BasicService.JSON.toString());
}
this.setUrl(this.url + xs2ARequest.getServicePath());
this.createHeaders(xs2ARequest);
try (Response response = this.execute();
Jsonb jsonb = JsonbBuilder.create()) {
String body = extractResponseBody(response, 201);
InitiatedPayment payment = jsonb.fromJson(body, InitiatedPayment.class);
payment.setxRequestId(UUID.fromString(xs2ARequest.getHeaders().get("x-request-id")));
payment.getSca().setApproach(SCAUtils.parseSCAApproach(payment.getLinks(), response));
return payment;
} catch (Exception e) {
throw new BankRequestFailedException(e.getMessage(), e);
}
}
use of net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException in project styx by petafuel.
the class BerlinGroupCS method startAuthorisation.
@Override
public /*
* BerlinGroup 1.2: the authorisationId of an Authorisation Resource is not a json key in the start SCA Request
* Therefore we take it out of an authorisation link that contains this id
*/
SCA startAuthorisation(SCARequest xs2ARequest) throws BankRequestFailedException {
this.setUrl(this.url + xs2ARequest.getServicePath());
this.createBody(RequestType.POST, JSON, xs2ARequest);
this.createHeaders(xs2ARequest);
try (Response response = this.execute();
Jsonb jsonb = JsonbBuilder.create()) {
String responseBody = extractResponseBody(response, 201);
SCA sca = jsonb.fromJson(responseBody, SCA.class);
SCAUtils.parseSCAApproach(sca, response);
// extract the authorisation id out of an Href Object that contains the authorisations/... route
for (Map.Entry<LinkType, Links.Href> entry : sca.getLinks().getUrlMapping().entrySet()) {
if (entry.getValue().getUrl().contains("authorisations/")) {
String[] routeParts = entry.getValue().getUrl().split("/");
sca.setAuthorisationId(routeParts[routeParts.length - 1]);
break;
}
}
return sca;
} catch (Exception e) {
throw new BankRequestFailedException(e.getMessage(), e);
}
}
use of net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException in project styx by petafuel.
the class OAuthService method refreshToken.
public static OAuthSession refreshToken(OAuthSession oAuthSession) throws OAuthTokenExpiredException {
String state = oAuthSession.getState();
RefreshTokenRequest request = new RefreshTokenRequest(oAuthSession.getRefreshToken());
OAuthService service = new OAuthService();
try {
oAuthSession = service.tokenRequest(oAuthSession.getTokenEndpoint(), request);
oAuthSession.setState(state);
PersistentOAuthSession.update(oAuthSession);
return oAuthSession;
} catch (BankRequestFailedException expiredToken) {
throw new OAuthTokenExpiredException(OAuthTokenExpiredException.MESSAGE);
}
}
Aggregations