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');
 }
 $operations = $resp->getOperations();
 if (count($operations) > 0) {
     $requestId = $operations[0]->getOperationId();
     $resp = $ym->operationDetail($token, $requestId);
     print "<p class=\"output\">";
     if ($resp->isSuccess()) {
         var_dump($resp);
     } else {
         print "Error: " . $resp->getError();
         die;
     }
     print "</p>";
 } else {
     print "<p>You have no any history records at your account to request details.</p>";
 }
 $resp = $ym->requestPaymentP2P($token, "410011161616877", "0.02");
 print "<p class=\"output\">";
 if ($resp->isSuccess()) {
     var_dump($resp);
 } else {
     print "Error: " . $resp->getError();
     die;
 }
 print "</p>";
 $requestId = $resp->getRequestId();
 $resp = $ym->processPaymentByWallet($token, $requestId);
 print "<p class=\"output\">";
 if ($resp->isSuccess()) {
     var_dump($resp);
 } else {
     print "Error: " . $resp->getError();