YandexMoney\API::getAccessToken PHP Method

getAccessToken() public static method

Exchanges temporary authorization code for an access_token.
See also: http://api.yandex.com/money/doc/dg/reference/obtain-access-token.xml
See also: https://tech.yandex.ru/money/doc/dg/reference/obtain-access-token-docpage/
public static getAccessToken ( string $client_id, string $code, string $redirect_uri, string $client_secret = NULL ) : response
$client_id string The client_id that was assigned to the application.
$code string Temporary token.
$redirect_uri string URI that the OAuth server sends the authorization result to. The value must exactly match the `redirect_uri` value from the previous "authorize" call.
$client_secret string A secret word for verifying the application's authenticity. Specified if the service is registered with the option to verify authenticity.
return response object
    public static function getAccessToken($client_id, $code, $redirect_uri, $client_secret = NULL)
    {
        $full_url = Config::$SP_MONEY_URL . "/oauth/token";
        return self::sendRequest($full_url, array("code" => $code, "client_id" => $client_id, "grant_type" => "authorization_code", "redirect_uri" => $redirect_uri, "client_secret" => $client_secret));
    }

Usage Example

 public function actionAuth()
 {
     /** @var \app\service\authclient\YandexMoney $client */
     $client = Yii::$app->authClientCollection->getClient('yandex_money');
     $code = self::getParam('code');
     $access_token_response = API::getAccessToken($client->clientId, $code, 'http://capitalov.localhost/yandexMoney', $client->clientSecret);
     if (property_exists($access_token_response, "error")) {
         // process error
     }
     $access_token = $access_token_response->access_token;
     VarDumper::dump($access_token);
 }
All Usage Examples Of YandexMoney\API::getAccessToken