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

com.checkout.SdkAuthorization Maven / Gradle / Ivy

There is a newer version: 6.4.2
Show newest version
package com.checkout;

import java.util.Objects;

import static com.checkout.common.CheckoutUtils.validateParams;

public final class SdkAuthorization {

    private static final String BEARER = "Bearer ";
    private final PlatformType platformType;
    private final String credential;

    public SdkAuthorization(final PlatformType platformType, final String credential) {
        validateParams("platformType", platformType);
        this.platformType = platformType;
        this.credential = credential;
    }

    public String getAuthorizationHeader() {
        switch (platformType) {
            case PREVIOUS:
            case CUSTOM:
                return credential;
            case DEFAULT:
            case DEFAULT_OAUTH:
                return BEARER + credential;
            default:
                throw new CheckoutAuthorizationException("Invalid platform type");
        }
    }

    @Override
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        final SdkAuthorization that = (SdkAuthorization) o;
        return platformType == that.platformType &&
                credential.equals(that.credential);
    }

    @Override
    public int hashCode() {
        return Objects.hash(platformType, credential);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy