function main() { ob_start(); print_r($_POST); $message = ob_get_contents(); ob_end_clean(); mail('*****@*****.**', 'Notification details', $message); if ($_POST['codepro'] != 'false') { return mail('*****@*****.**', 'Мы получили YM с кодом протекции', "Мы не можем автоматически получаете этот платеж.\n\n {$message}"); } $str = $_POST['notification_type'] . '&' . $_POST['operation_id'] . '&' . $_POST['amount'] . '&' . $_POST['currency'] . '&' . $_POST['datetime'] . '&' . $_POST['sender'] . '&' . $_POST['codepro'] . '&секретный код со страницы https://sp-money.yandex.ru/myservices/online.xml&' . $_POST['label']; if (sha1($str) != $_POST['sha1_hash']) { return mail('*****@*****.**', 'Поддельные уведомления', $message); } $ym = new YandexMoney(CLIENT_ID); $token = '410012153352644.6B26694E0A15363B88E95E5777D2DEDCB70346A4A0B20B6FE002AACF8AE2FC4B439DC118C7D158A056048824556B2A7F718FB1FB2B89F719072A141DAA2899E66BD810A2C71D0562BC4B8469787A590B6F95B0F864621A09502BAB53F7D4B5832EE3E0D5D67AD77BCC9744E906E13F796799C4A0C78574D17BD75A80A2EDC123'; $resp = $ym->operationDetail($token, $_POST['operation_id']); var_dump($resp); $message .= "\r\n" . var_export($_POST, 1) . var_export($resp); if ($resp->isSuccess()) { mail('*****@*****.**', 'Мы получили платеж', $message); } else { mail('*****@*****.**', 'Мы не получили оплату ... Хм ... Почему?', $message); } $operation_id = $_POST['operation_id']; $sender = $_POST['sender']; $amount = $_POST['amount']; $datetime = $_POST['datetime']; preg_match('/i(\\d+);/', $resp->getMessage(), $m); $invoice_id = $m[1]; $nZakaz = $_POST['label']; $r = mysql_query("INSERT INTO it_payment_ym (`id`, `operation_id`, `sender`, `amount`, `datetime`, `invoice_id`, `zakaz_id`) VALUES (NULL,'{$operation_id}', '{$sender}', '{$amount}', '{$datetime}', '{$invoice_id}', '{$nZakaz}')"); if (!$r) { mail('*****@*****.**', 'Проблема для вставки it_payment_ym', $message . mysql_error()); } }
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'); }
} else { // 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);
public static function addNewYMWallet() { $number = Core::validate(self::getVar('number')); $client_id = Core::validate(self::getVar('client_id')); $secret_id = Core::validate(self::getVar('secret_id')); $redirectPage = 'http://emonex.info/money/YM_transaction'; $scope = "account-info " . "payment-p2p " . "payment-shop"; $authUri = YandexMoney::authorizeUri($client_id, $redirectPage, $scope); header('Location: ' . $authUri); exit; }