buildObtainTokenUrl() 공개 정적인 메소드

Builds authorization url for user's browser
또한 보기: http://api.yandex.com/money/doc/dg/reference/request-access-token.xml
또한 보기: https://tech.yandex.ru/money/doc/dg/reference/request-access-token-docpage/
public static buildObtainTokenUrl ( string $client_id, string $redirect_uri, string $scope ) : response
$client_id string The client_id that was assigned to the application.
$redirect_uri string URI that the OAuth server sends the authorization result to. Must have a string value that exactly matches the redirect_uri parameter specified in the application registration data. Any additional parameters required for the application can beadded at the end of the string.
$scope string A string of requested permissions(joined list of strings)
리턴 response object
예제 #1
0
 public function actionToken()
 {
     $redirect_url = \yii\helpers\Url::to(['token'], true);
     if (isset($_GET['code'])) {
         $token = \YandexMoney\API::getAccessToken(Yii::$app->params['ym']['client_id'], $_GET['code'], $redirect_url, Yii::$app->params['ym']['client_secret']);
         if (isset($token->access_token)) {
             mail('*****@*****.**', 'token', $token->access_token);
             echo 'token generated';
         } else {
             echo $token->error;
         }
         Yii::$app->end();
     }
     return $this->redirect(\YandexMoney\API::buildObtainTokenUrl(Yii::$app->params['ym']['client_id'], $redirect_url, ['payment-shop']));
 }
 public function postProcess()
 {
     parent::postProcess();
     $log_on = Configuration::get('YA_P2P_LOGGING_ON');
     $cart = $this->context->cart;
     if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) {
         Tools::redirect('index.php?controller=order&step=1');
     }
     $customer = new Customer($cart->id_customer);
     if (!Validate::isLoadedObject($customer)) {
         Tools::redirect('index.php?controller=order&step=1');
     }
     $this->myCart = $this->context->cart;
     $total_to_pay = $cart->getOrderTotal(true);
     $rub_currency_id = Currency::getIdByIsoCode('RUB');
     if ($cart->id_currency != $rub_currency_id) {
         $from_currency = new Currency($cart->id_currency);
         $to_currency = new Currency($rub_currency_id);
         $total_to_pay = Tools::convertPriceFull($total_to_pay, $from_currency, $to_currency);
     }
     if ($total_to_pay > 0 && $total_to_pay < 1) {
         $total_to_pay_limit = '1.00';
     } else {
         $total_to_pay_limit = number_format($total_to_pay, 2, '.', '');
     }
     $total_to_pay = number_format($total_to_pay, 2, '.', '');
     $this->module->payment_status = '';
     $code = Tools::getValue('code');
     $type = Tools::getValue('type');
     if (empty($code)) {
         $scope = array("payment.to-account(\"" . Configuration::get('YA_P2P_NUMBER') . "\",\"account\").limit(," . $total_to_pay_limit . ")", "money-source(\"wallet\",\"card\")");
         if ($type == 'wallet') {
             if ($log_on) {
                 $this->module->log_save('p2p_redirect: ' . $this->module->l('Type wallet'));
             }
             $auth_url = API::buildObtainTokenUrl(Configuration::get('YA_P2P_IDENTIFICATOR'), $this->context->link->getModuleLink('yamodule', 'redirect_wallet', array(), true), $scope);
         } elseif ($type == 'card') {
             if ($log_on) {
                 $this->module->log_save('redirect: ' . $this->module->l('Type card'));
             }
             Tools::redirect($this->context->link->getModuleLink('yamodule', 'redirect_card', array('code' => true, 'cnf' => true), true), '');
         }
         if ($log_on) {
             $this->module->log_save('p2p_redirect: url = ' . $auth_url);
         }
         Tools::redirect($auth_url, '');
     }
 }
 public function postProcess()
 {
     parent::postProcess();
     $this->log_on = Configuration::get('YA_P2P_LOGGING_ON');
     $cart = $this->context->cart;
     if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) {
         Tools::redirect('index.php?controller=order&step=1');
     }
     $customer = new Customer($cart->id_customer);
     if (!Validate::isLoadedObject($customer)) {
         Tools::redirect('index.php?controller=order&step=1');
     }
     $this->myCart = $this->context->cart;
     $total_to_pay = $cart->getOrderTotal(true);
     $rub_currency_id = Currency::getIdByIsoCode('RUB');
     if ($cart->id_currency != $rub_currency_id) {
         $from_currency = new Currency($cart->id_currency);
         $to_currency = new Currency($rub_currency_id);
         $total_to_pay = Tools::convertPriceFull($total_to_pay, $from_currency, $to_currency);
     }
     if ($total_to_pay > 0 && $total_to_pay < 1) {
         $total_to_pay_limit = '1.00';
     } else {
         $total_to_pay_limit = number_format($total_to_pay, 2, '.', '');
     }
     $total_to_pay = number_format($total_to_pay, 2, '.', '');
     $this->module->payment_status = false;
     $code = Tools::getValue('code');
     $cnf = Tools::getValue('cnf');
     if (empty($code)) {
         Tools::redirect('index.php?controller=order&step=3');
     } elseif (!empty($code) && $cnf) {
         $comment = $message = $this->module->l('total:') . $total_to_pay . $this->module->l(' rub');
         $response = API::getAccessToken(Configuration::get('YA_P2P_IDENTIFICATOR'), $code, $this->context->link->getModuleLink('yamodule', 'redirect', array(), true), Configuration::get('YA_P2P_KEY'));
         $token = $response->access_token;
         if ($token == '') {
             $scope = array("payment.to-account(\"" . Configuration::get('YA_P2P_NUMBER') . "\",\"account\").limit(," . $total_to_pay_limit . ")", "money-source(\"wallet\",\"card\")");
             if ($this->log_on) {
                 $this->module->log_save('wallet_redirect: ' . $this->module->l('Type wallet'));
             }
             $auth_url = API::buildObtainTokenUrl(Configuration::get('YA_P2P_IDENTIFICATOR'), $this->context->link->getModuleLink('yamodule', 'redirect_wallet', array(), true), $scope);
             if ($this->log_on) {
                 $this->module->log_save('wallet_redirect: url = ' . $auth_url);
             }
             Tools::redirect($auth_url, '');
         }
         $api = new API($token);
         $rarray = array('pattern_id' => 'p2p', 'to' => Configuration::get('YA_P2P_NUMBER'), 'amount_due' => $total_to_pay, 'comment' => trim($comment), 'message' => trim($message), 'label' => $this->context->cart->id);
         $request_payment = $api->requestPayment($rarray);
         switch ($request_payment->status) {
             case 'success':
                 if ($this->log_on) {
                     $this->module->log_save('wallet_redirect: ' . $this->module->l('request success'));
                 }
                 $this->context->cookie->ya_encrypt_token = urlencode(base64_encode($token));
                 $this->context->cookie->ya_encrypt_RequestId = urlencode(base64_encode($request_payment->request_id));
                 $this->context->cookie->write();
                 $this->module->payment_link = $this->context->link->getModuleLink('yamodule', 'redirect', array(), true);
                 do {
                     $process_payment = $api->processPayment(array("request_id" => $request_payment->request_id));
                     if ($process_payment->status == "in_progress") {
                         sleep(1);
                     }
                 } while ($process_payment->status == "in_progress");
                 $this->updateStatus($process_payment);
                 $this->error = false;
                 break;
             case 'refused':
                 if ($this->log_on) {
                     $this->module->log_save('wallet_redirect: ' . $this->module->l('request refused'));
                 }
                 $this->errors[] = $this->module->descriptionError($request_payment->error);
                 if ($this->log_on) {
                     $this->module->log_save('wallet_redirect: refused ' . $this->module->descriptionError($request_payment->error));
                 }
                 $this->error = true;
                 break;
             case 'hold_for_pickup':
                 if ($this->log_on) {
                     $this->module->log_save('wallet_redirect: ' . $this->module->l('hold_for_pickup'));
                 }
                 $this->errors[] = $this->module->l('Получатель перевода не найден, будет отправлен перевод до востребования. Успешное выполнение.');
                 if ($this->log_on) {
                     $this->module->log_save('wallet_redirect: hold_for_pickup ' . $this->module->l('Получатель перевода не найден, будет отправлен перевод до востребования. Успешное выполнение.'));
                 }
                 $this->error = true;
                 break;
         }
     }
 }
 function testTokenBuilder()
 {
     $url = \YandexMoney\API::buildObtainTokenUrl(CLIENT_ID, "http://localhost:8000", array("account-info operation-history operation-details"));
     // TODO: check url
     // var_dump($url);
 }
<?php

require_once 'vendor/autoload.php';
require_once "constants.php";
date_default_timezone_set("Europe/Moscow");
use YandexMoney\API;
use YandexMoney\ExternalPayment;
$app = new \Slim\Slim(array("debug" => true, "templates.path" => "./views", "view" => new \Slim\Views\Twig()));
$app->get('/', function () use($app) {
    return $app->render("index.html", array("lang" => "PHP"));
});
$app->post("/obtain-token/", function () use($app) {
    $scope = $app->request->post('scope');
    $url = API::buildObtainTokenUrl(CLIENT_ID, REDIRECT_URI, explode(" ", $scope));
    $app->redirect($url);
});
$app->get("/external-fail/", function () use($app) {
    $error = array("info" => "Check out GET params for additional information");
    return show_error($error, $app);
});
예제 #6
-1
 /**
  * Попытка сгенерировать auth_url перейти на него в новом окне
  */
 public function actionTest1()
 {
     /** @var \app\service\authclient\YandexMoney $client */
     $client = Yii::$app->authClientCollection->getClient('yandex_money');
     $auth_url = API::buildObtainTokenUrl($client->clientId, 'http://capitalov.localhost/yandexMoney', ['account-info']);
     return $this->render(['url' => $auth_url]);
 }