I
I
Ivan Efimov2019-02-15 18:07:28
Yii
Ivan Efimov, 2019-02-15 18:07:28

Why does PHP Yandex.Money API SDK return NULL when getting an access_token?

wrote a code to get an acces_token in pure php, it worked successfully, then the same code was slightly adapted for yii2
, as a result I get the code value, and the access_token returns NULL, I tested all the work on the local without https
for some reason no errors are displayed, although it should, do not tell me in which direction to dig? what could be the problem?

<?php

private
function yandexParams()
{
    $ya['scope'] = array("account-info operation-history operation-details payment-p2p");
    $ya['redirect_uri'] = '';
    $ya['client_id'] = '';
    return $ya;
}

// http://site.loc/frontend/web/site/send-yandex-money
public
function actionSendYandexMoney()
{

    function human_print($var)
    {
        echo '<pre>';
        print_r($var);
        echo '</pre>';
        echo '<hr>';
    }


    $yandex = $this->yandexParams();
    $code = Yii::$app->request->get('code', '');
    // echo 'res yandex money';

    if (!empty($code)) {


        print_r($yandex);
        echo '<hr>';
        var_dump('code', $code);
        echo '<hr>';

//                $access_token_response = API::getAccessToken($client_id, $code, $redirect_uri, $client_secret);
//                $access_token_response = API::getAccessToken($client_id, $code, $redirect_uri, $client_secret = NULL);
        // $access_token_response = API::getAccessToken($yandex['client_id'], $code, $yandex['redirect_uri'],$yandex['client_secret']);

        $access_token_response = API::getAccessToken($yandex['client_id'], $code, $yandex['redirect_uri'], $client_secret = NULL);

        var_dump('$access_token_response', $access_token_response);
        echo '<hr>';

        if (property_exists($access_token_response, "error")) {
            // process error
            echo $access_token_response->error;
        }
        $access_token = $access_token_response->access_token;


        var_dump('$access_token', $access_token);
        echo '<hr>';

    } else {


//            $auth_url = API::buildObtainTokenUrl($client_id, $yandex['redirect_uri'], $yandex['scope']);
        $auth_url = API::buildObtainTokenUrl($yandex['client_id'], $yandex['redirect_uri'], $yandex['scope']);
//            var_dump($auth_url);
//            echo '<hr>';
        return $this->render('yandex-auth.php', [
            'auth_url' => $auth_url,
        ]);
    }


    /*********** views ************/
?>
    <form id = "auto-send-yandex-money2" method = "POST" target = "_blank" action = "<?php echo $auth_url;?>" >
    <input type = "submit" value = "Авторизация через Яндекс" >
</form >

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2019-02-15
@dimonchik2013

dig into decomposition and iteration,
well, the first thing is to compare the data when it "worked" and "corrected a little"

Y
YourQuestion, 2020-01-28
@YourQuestion

The SDK is no longer supported by Yandex.
Error in old links - the request is sent to https://sp-money.yandex.ru, but should be sent to https://money.yandex.ru

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question