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

com.paypal.core.request.AccessTokenRequest Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package com.paypal.core.request;

import com.paypal.http.Headers;
import com.paypal.http.HttpRequest;
import com.paypal.core.PayPalEnvironment;
import com.paypal.core.object.AccessToken;

import java.util.HashMap;
import java.util.Map;

public class AccessTokenRequest extends HttpRequest {

	@SuppressWarnings("unchecked")
	public AccessTokenRequest(PayPalEnvironment environment) {
		super("/v1/oauth2/token", "POST", AccessToken.class);
		header(Headers.CONTENT_TYPE, "application/x-www-form-urlencoded");
		header(Headers.AUTHORIZATION, environment.authorizationString());

		Map body = new HashMap() {{
			put("grant_type", "client_credentials");
		}};

		super.requestBody(body);
	}

	public AccessTokenRequest(PayPalEnvironment credentials, String refreshToken) {
		this(credentials);

		Map body = new HashMap() {{
			put("grant_type", "refresh_token");
			put("refresh_token", refreshToken);
		}};

		super.requestBody(body);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy