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

com.yandex.money.api.net.AuthorizationCodeResponse Maven / Gradle / Ivy

Go to download

This Java library contains classes that allows you to do payments using Yandex.Money public API.

The newest version!
package com.yandex.money.api.net;

import com.yandex.money.api.model.Error;
import com.yandex.money.api.utils.UrlEncodedUtils;

import java.net.URISyntaxException;
import java.util.Map;

/**
 * This is a convenience class to parse OAuth2 response after user authentication.
 *
 * @author Slava Yasevich ([email protected])
 * @see com.yandex.money.api.net.OAuth2Authorization
 */
public class AuthorizationCodeResponse {

    private final String code;
    private final Error error;
    private final String errorDescription;

    protected AuthorizationCodeResponse(String code, Error error, String errorDescription) {
        this.code = code;
        this.error = error;
        this.errorDescription = errorDescription;
    }

    /**
     * Parses redirect URL after OAuth2 authorization and retrieves its parameters.
     *
     * @param redirectUrl redirect url
     * @return response object
     * @throws URISyntaxException if provided url is malformed
     */
    public static AuthorizationCodeResponse parse(String redirectUrl) throws URISyntaxException {
        Map params = UrlEncodedUtils.parse(redirectUrl);
        return new AuthorizationCodeResponse(params.get("code"), Error.parse(params.get("error")),
                params.get("error_description"));
    }

    /**
     * @return temporary access token to request OAuth2 access token
     * @see com.yandex.money.api.methods.Token
     */
    public String getCode() {
        return code;
    }

    /**
     * @return error code
     */
    public Error getError() {
        return error;
    }

    /**
     * @return human understandable error description
     */
    public String getErrorDescription() {
        return errorDescription;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy