Search in sources :

Example 21 with BankRequestFailedException

use of net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException in project styx by petafuel.

the class BasicAuthorisationService method authoriseTransaction.

protected SCA authoriseTransaction(AuthoriseTransactionRequest authoriseTransactionRequest) throws BankRequestFailedException {
    this.setUrl(this.url + authoriseTransactionRequest.getServicePath());
    this.createBody(RequestType.PUT, JSON, authoriseTransactionRequest);
    this.createHeaders(authoriseTransactionRequest);
    try (Response response = this.execute();
        Jsonb jsonb = JsonbBuilder.create()) {
        String responseBody = extractResponseBody(response, 200);
        SCA sca = jsonb.fromJson(responseBody, SCA.class);
        SCAUtils.parseSCAApproach(sca, response);
        return sca;
    } catch (Exception e) {
        throw new BankRequestFailedException(e.getMessage(), e);
    }
}
Also used : GetAuthorisationResponse(net.petafuel.styx.core.xs2a.standards.berlingroup.v1_3.http.GetAuthorisationResponse) GetSCAStatusResponse(net.petafuel.styx.core.xs2a.standards.berlingroup.v1_3.http.GetSCAStatusResponse) Response(okhttp3.Response) SCA(net.petafuel.styx.core.xs2a.entities.SCA) Jsonb(javax.json.bind.Jsonb) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)

Example 22 with BankRequestFailedException

use of net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException in project styx by petafuel.

the class BasicAuthorisationService method getAuthorisations.

protected List<String> getAuthorisations(GetAuthorisationsRequest xs2ARequest) throws BankRequestFailedException {
    this.setUrl(this.url + xs2ARequest.getServicePath());
    this.createBody(RequestType.GET);
    this.createHeaders(xs2ARequest);
    try (Response response = this.execute();
        Jsonb jsonb = JsonbBuilder.create()) {
        String responseBody = extractResponseBody(response, 200);
        GetAuthorisationResponse getAuthorisationResponse = jsonb.fromJson(responseBody, GetAuthorisationResponse.class);
        return getAuthorisationResponse.getAuthorisationIds();
    } catch (Exception e) {
        throw new BankRequestFailedException(e.getMessage(), e);
    }
}
Also used : GetAuthorisationResponse(net.petafuel.styx.core.xs2a.standards.berlingroup.v1_3.http.GetAuthorisationResponse) GetSCAStatusResponse(net.petafuel.styx.core.xs2a.standards.berlingroup.v1_3.http.GetSCAStatusResponse) Response(okhttp3.Response) Jsonb(javax.json.bind.Jsonb) GetAuthorisationResponse(net.petafuel.styx.core.xs2a.standards.berlingroup.v1_3.http.GetAuthorisationResponse) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)

Example 23 with BankRequestFailedException

use of net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException in project styx by petafuel.

the class BasicAuthorisationService method updatePSUAuthentication.

protected SCA updatePSUAuthentication(UpdatePSUAuthenticationRequest updatePSUAuthenticationRequest) throws BankRequestFailedException {
    this.setUrl(this.url + updatePSUAuthenticationRequest.getServicePath());
    this.createBody(RequestType.PUT, JSON, updatePSUAuthenticationRequest);
    this.createHeaders(updatePSUAuthenticationRequest);
    try (Response response = this.execute();
        Jsonb jsonb = JsonbBuilder.create()) {
        String responseBody = extractResponseBody(response, 200);
        SCA sca = jsonb.fromJson(responseBody, SCA.class);
        SCAUtils.parseSCAApproach(sca, response);
        return sca;
    } catch (Exception e) {
        throw new BankRequestFailedException(e.getMessage(), e);
    }
}
Also used : GetAuthorisationResponse(net.petafuel.styx.core.xs2a.standards.berlingroup.v1_3.http.GetAuthorisationResponse) GetSCAStatusResponse(net.petafuel.styx.core.xs2a.standards.berlingroup.v1_3.http.GetSCAStatusResponse) Response(okhttp3.Response) SCA(net.petafuel.styx.core.xs2a.entities.SCA) Jsonb(javax.json.bind.Jsonb) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)

Example 24 with BankRequestFailedException

use of net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException in project styx by petafuel.

the class BerlinGroupCS method getConsent.

@Override
public Consent getConsent(AISRequest consentGetRequest) throws BankRequestFailedException {
    this.setUrl(this.url + consentGetRequest.getServicePath());
    this.createBody(RequestType.GET);
    this.createHeaders(consentGetRequest);
    try (Response response = this.execute();
        Jsonb jsonb = JsonbBuilder.create()) {
        String responseBody = extractResponseBody(response, 200);
        Consent consentFromResponse = jsonb.fromJson(responseBody, Consent.class);
        consentFromResponse.setId(consentGetRequest.getConsentId());
        Consent consentFromDatabase = new PersistentConsent().get(consentFromResponse);
        consentFromDatabase.setAccess(consentFromResponse.getAccess());
        consentFromDatabase.setRecurringIndicator(consentFromResponse.isRecurringIndicator());
        consentFromDatabase.setValidUntil(consentFromResponse.getValidUntil());
        consentFromDatabase.setFrequencyPerDay(consentFromResponse.getFrequencyPerDay());
        consentFromDatabase.setState(consentFromResponse.getState());
        consentFromDatabase.setLastAction(consentFromResponse.getLastAction());
        return new PersistentConsent().update(consentFromDatabase);
    } catch (Exception e) {
        throw new BankRequestFailedException(e.getMessage(), e);
    }
}
Also used : Response(okhttp3.Response) Jsonb(javax.json.bind.Jsonb) Consent(net.petafuel.styx.core.xs2a.entities.Consent) PersistentConsent(net.petafuel.styx.core.persistence.layers.PersistentConsent) PersistentConsent(net.petafuel.styx.core.persistence.layers.PersistentConsent) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException) IOException(java.io.IOException) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)

Example 25 with BankRequestFailedException

use of net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException in project styx by petafuel.

the class BerlinGroupCS method createConsent.

public Consent createConsent(AISRequest consentRequest) throws BankRequestFailedException {
    this.setUrl(this.url + consentRequest.getServicePath());
    this.createBody(RequestType.POST, JSON, consentRequest);
    this.createHeaders(consentRequest);
    JsonbConfig config = new JsonbConfig().withPropertyNamingStrategy(PropertyNamingStrategy.CASE_INSENSITIVE);
    try (Response response = this.execute();
        Jsonb jsonb = JsonbBuilder.create(config)) {
        String responseBody = extractResponseBody(response, 201);
        Consent consent = jsonb.fromJson(responseBody, Consent.class);
        consent.setxRequestId(UUID.fromString(consentRequest.getHeaders().get("x-request-id")));
        consent.setPsu(consentRequest.getPsu());
        // if the sca method was not set by previously parsing the body, use the bank supplied header
        consent.getSca().setApproach(SCAUtils.parseSCAApproach(consent.getLinks(), response));
        consent.setAccess(consentRequest.getConsent().getAccess());
        new PersistentConsent().create(consent);
        return consent;
    } catch (BankRequestFailedException e) {
        throw e;
    } catch (Exception e) {
        throw new BankRequestFailedException(e.getMessage(), e);
    }
}
Also used : Response(okhttp3.Response) JsonbConfig(javax.json.bind.JsonbConfig) Jsonb(javax.json.bind.Jsonb) Consent(net.petafuel.styx.core.xs2a.entities.Consent) PersistentConsent(net.petafuel.styx.core.persistence.layers.PersistentConsent) PersistentConsent(net.petafuel.styx.core.persistence.layers.PersistentConsent) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException) IOException(java.io.IOException)

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