Search in sources :

Example 26 with BankRequestFailedException

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);
    }
}
Also used : Response(okhttp3.Response) PaymentProduct(net.petafuel.styx.core.xs2a.entities.PaymentProduct) Jsonb(javax.json.bind.Jsonb) InitiatedPayment(net.petafuel.styx.core.xs2a.entities.InitiatedPayment) 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) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)

Example 27 with BankRequestFailedException

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);
    }
}
Also used : Response(okhttp3.Response) SCA(net.petafuel.styx.core.xs2a.entities.SCA) Jsonb(javax.json.bind.Jsonb) LinkType(net.petafuel.styx.core.xs2a.entities.LinkType) Map(java.util.Map) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)

Example 28 with BankRequestFailedException

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);
    }
}
Also used : RefreshTokenRequest(net.petafuel.styx.core.xs2a.oauth.http.RefreshTokenRequest) OAuthTokenExpiredException(net.petafuel.styx.core.xs2a.exceptions.OAuthTokenExpiredException) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)

Aggregations

BankRequestFailedException (net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)28 Jsonb (javax.json.bind.Jsonb)22 Response (okhttp3.Response)22 SerializerException (net.petafuel.styx.core.xs2a.exceptions.SerializerException)8 IOException (java.io.IOException)7 SCA (net.petafuel.styx.core.xs2a.entities.SCA)7 GetAuthorisationResponse (net.petafuel.styx.core.xs2a.standards.berlingroup.v1_3.http.GetAuthorisationResponse)7 GetSCAStatusResponse (net.petafuel.styx.core.xs2a.standards.berlingroup.v1_3.http.GetSCAStatusResponse)7 PersistentConsent (net.petafuel.styx.core.persistence.layers.PersistentConsent)5 Consent (net.petafuel.styx.core.xs2a.entities.Consent)5 ReadAccountDetailsResponse (net.petafuel.styx.core.xs2a.standards.berlingroup.v1_2.http.ReadAccountDetailsResponse)5 ReadAccountListResponse (net.petafuel.styx.core.xs2a.standards.berlingroup.v1_2.http.ReadAccountListResponse)5 ReadTransactionDetailsResponse (net.petafuel.styx.core.xs2a.standards.berlingroup.v1_2.http.ReadTransactionDetailsResponse)5 SEPAParsingException (net.petafuel.jsepa.exception.SEPAParsingException)3 Map (java.util.Map)2 LinkType (net.petafuel.styx.core.xs2a.entities.LinkType)2 PaymentStatus (net.petafuel.styx.core.xs2a.entities.PaymentStatus)2 OAuthTokenExpiredException (net.petafuel.styx.core.xs2a.exceptions.OAuthTokenExpiredException)2 RefreshTokenRequest (net.petafuel.styx.core.xs2a.oauth.http.RefreshTokenRequest)2 TaskFinalFailureException (net.petafuel.styx.keepalive.entities.TaskFinalFailureException)2