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, ''); } }
} else { $process_payment_info = sprintf("You send %g to %s wallet", $process_payment->credit_amount, $process_payment->payee); } $template_meta = function ($method, $index) { $method['includes'] = array(array("is_collapsed" => false, "title" => "Source code", "id" => $index, "body" => $method['code']), array("is_collapsed" => true, "title" => "Response", "id" => $index + 100, "body" => json_encode($method['response'], JSON_OPTIONS))); return $method; }; $methods = array(array("info" => sprintf("You wallet balance is %s RUB", $account_info->balance), "code" => read_sample("account_info.txt"), "name" => "Account-info", "response" => $account_info), array("info" => $operation_history_info, "code" => read_sample("operation_history.txt"), "name" => "Operation-history", "response" => $operation_history), array("info" => $request_payment_info, "code" => read_sample("request_payment.txt"), "name" => "Request-payment", "response" => $request_payment), array("info" => $process_payment_info, "code" => read_sample("process_payment.txt"), "name" => "Process-payment", "response" => $process_payment, "is_error" => $is_process_error, "message" => "Call process_payment method isn't possible." . " See request_payment JSON for information")); return $app->render("auth.html", array("methods" => array_map($template_meta, $methods, array_keys($methods)), "home" => substr_replace($home, "", -1), "lang" => "PHP")); } $app->get(build_relative_url(REDIRECT_URI, $app->environment['SCRIPT_NAME']), function () use($app) { $code = $app->request->get('code'); $result = API::getAccessToken(CLIENT_ID, $code, REDIRECT_URI, CLIENT_SECRET); $script_name = $app->environment['SCRIPT_NAME']; $home = $app->environment['SCRIPT_NAME'] . "/"; if (property_exists($result, "error")) { $script_name = $app->environment['SCRIPT_NAME']; $params = array("text" => json_encode($result, JSON_OPTIONS), "home" => $home); return show_error($params, $app); } $api = new API($result->access_token); $account_info = $api->accountInfo(); $operation_history = $api->operationHistory(array("records" => 3)); $request_payment = $api->requestPayment(array("pattern_id" => "p2p", "to" => "410011161616877", "amount_due" => "0.02", "comment" => "test payment comment from yandex-money-php", "message" => "test payment message from yandex-money-php", "label" => "testPayment", "test_payment" => "true", "test_result" => "success")); if ($request_payment->status !== "success") { $process_payment = array(); } else { $process_payment = $api->processPayment(array("request_id" => $request_payment->request_id, "test_payment" => "true", "test_result" => "success")); } return build_response($app, $account_info, $operation_history, $request_payment, $process_payment, $home); });
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); }
function testRevokeToken() { $this->assertObjectHasAttribute("aux_token", $this->token_response); \YandexMoney\API::revokeToken($this->token_response->aux_token); }
<?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); });
/** * Попытка сгенерировать 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]); }
public function init() { if (!$this->client_id) { throw new InvalidConfigException("Client_id can't be empty!"); } if (!$this->code) { throw new InvalidConfigException("Code can't be empty!"); } if (!$this->redirect_uri) { throw new InvalidConfigException("Redirect_uri can't be empty!"); } $access_token = API::getAccessToken($this->client_id, $this->code, $this->redirect_uri, $this->client_secret); $this->api = new API($access_token); }