public static function YM_transaction()
 {
     if (isset($_GET['error']) && $_GET['error'] == 'access_denied') {
         header('Location: /usr/mypage?err=1');
         exit;
     }
     $ym = new YandexMoney(YM_ACCESSTOKEN);
     $usr = usr::getCurrentUser(1);
     if ($usr == null) {
         header('Location: /');
         exit;
     }
     $purseList = Purse::findBy(array('UID' => $usr->getId(), 'CurId' => 4));
     if (empty($purseList)) {
         header('Location: /usr/mypage?err=1');
         exit;
     }
     $purse = $purseList[0];
     if (!isset($_GET['code'])) {
         if (empty($purse['Additional_ID'])) {
             $scope = "account-info " . "operation-history " . "operation-details " . "payment.to-account(\"410012112526562\",\"account\") ";
             $authUri = YandexMoney::authorizeUri(YM_ACCESSTOKEN, YM_REDIRECTPAGE, $scope);
             header('Location: ' . $authUri);
             exit;
         }
         if (!isset($_GET['value']) || !is_numeric($_GET['value'])) {
             header('Location: /usr/mypage?err=2');
             exit;
         }
         $value = $_GET['value'];
         $token = $purse['Additional_ID'];
     } else {
         //Save new code
         $code = $_GET['code'];
         $receiveTokenResp = $ym->receiveOAuthToken($code, YM_REDIRECTPAGE, YM_SECRETTOKEN);
         if (!$receiveTokenResp->isSuccess()) {
             header('Location: /usr/mypage?err=1');
             exit;
         }
         $token = $receiveTokenResp->getAccessToken();
         $prsUpd = new Purse();
         $prsUpd->findById($purse['id']);
         $prsUpd->update(array('Additional_ID' => $token));
         header('Location: /usr/mypage?err=4');
         exit;
     }
     /* ------------ */
     $resp = $ym->requestPaymentP2P($token, "410012112526562", $value);
     if (!$resp->isSuccess()) {
         header('Location: /usr/mypage?err=2');
         exit;
     }
     $requestId = $resp->getRequestId();
     $resp = $ym->processPaymentByWallet($token, $requestId);
     if (!$resp->isSuccess()) {
         header('Location: /usr/mypage?err=3');
         exit;
     }
     $prsUpd = new Purse();
     $prsUpd->findById($purse['id']);
     $prsUpd->update(array('Value' => $purse['Value'] + $value));
     header('Location: /usr/mypage?err=0');
 }
    // when we recieved a temporary code on redirect
    ?>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" type="text/css" href="styles.css">
    <title>Yandex.Money PHP SDK sample app</title>
</head>
<body>
<div id="main">
    <h3 id="header">Yandex.Money PHP SDK sample app</h3>

    <?php 
    $ym = new YandexMoney(CLIENT_ID, './ym.log');
    $receiveTokenResp = $ym->receiveOAuthToken($code, REDIRECT_URI, CLIENT_SECRET);
    print "<p class=\"output\">";
    if ($receiveTokenResp->isSuccess()) {
        $token = $receiveTokenResp->getAccessToken();
        print "Received token: " . $token;
    } else {
        print "Error: " . $receiveTokenResp->getError();
        die;
    }
    print "</p>";
    print "<p>Notice: after you received access_token you should store it to your app's storage</p>";
    $resp = $ym->accountInfo($token);
    print "<p class=\"output\">";
    if ($resp->isSuccess()) {
        var_dump($resp);
    } else {