All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.truelayer.java.payments.entities.AuthorizationFlowResponse Maven / Gradle / Ivy

There is a newer version: 16.0.0
Show newest version
package com.truelayer.java.payments.entities;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.truelayer.java.TrueLayerException;
import com.truelayer.java.payments.entities.paymentdetail.Status;
import lombok.EqualsAndHashCode;
import lombok.ToString;

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "status", defaultImpl = AuthorizationFlowAuthorizing.class)
@JsonSubTypes({
    @JsonSubTypes.Type(value = AuthorizationFlowAuthorizing.class, name = "authorizing"),
    @JsonSubTypes.Type(value = AuthorizationFlowAuthorizationFailed.class, name = "failed")
})
@ToString
@EqualsAndHashCode
public abstract class AuthorizationFlowResponse {

    @JsonIgnore
    public abstract Status getStatus();

    @JsonIgnore
    public boolean isAuthorizing() {
        return this instanceof AuthorizationFlowAuthorizing;
    }

    @JsonIgnore
    public boolean isAuthorizationFailed() {
        return this instanceof AuthorizationFlowAuthorizationFailed;
    }

    @JsonIgnore
    public AuthorizationFlowAuthorizing asAuthorizing() {
        if (!isAuthorizing()) {
            throw new TrueLayerException(buildErrorMessage());
        }
        return (AuthorizationFlowAuthorizing) this;
    }

    @JsonIgnore
    public AuthorizationFlowAuthorizationFailed asAuthorizationFailed() {
        if (!isAuthorizationFailed()) {
            throw new TrueLayerException(buildErrorMessage());
        }
        return (AuthorizationFlowAuthorizationFailed) this;
    }

    private String buildErrorMessage() {
        return String.format("Response is of type %s.", this.getClass().getSimpleName());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy