B
B
Brahner2014-09-23 16:13:36
PHP
Brahner, 2014-09-23 16:13:36

How to send your variables to Yandex.API?

I pay for services from the site using the API in this way

require_once(dirname(__FILE__) . '/lib/YandexMoney.php');
require_once(dirname(__FILE__) . '/consts.php');
require("../config.php");
require("../engine/functions.php");

$code = $_GET['code'];
if (!isset($code)) { // If we are just begginig OAuth
    $scope = "payment.to-account(\"410011*********\",\"account\").limit(,1)";
 //сюда вместо 1 надо подставить нужную мне сумму для получения разрешения 
    $authUri = YandexMoney::authorizeUri(CLIENT_ID, REDIRECT_URI, $scope);
    header('Location: ' . $authUri);

} else { 	// when we recieved a temporary code on redirect

        $ym = new YandexMoney(CLIENT_ID, './ym.log');
        $receiveTokenResp = $ym->receiveOAuthToken($code, REDIRECT_URI, CLIENT_SECRET);
        if ($receiveTokenResp->isSuccess()) {
            $token = $receiveTokenResp->getAccessToken();
        } else {
            die();
        }
    
        $resp = $ym->requestPaymentP2P($token, "410011*********", "1"); 
// сюда вместо 1 надо подставить нужную мне сумму для оплаты
        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()) {

      $q="UPDATE payment SET status=1,code='$code' WHERE id='$_GET[id_pay]'";
      mysql_query($q);
      
      header('location: ../success.php');
        } else {
      header('location: ../fail.php');
        }

If you call this script by passing the id_pay variable by the GET or POST method, then this variable is lost, because it redirects to the Yandex page, and then returns to the script page, where the GET or POST array is already missing. The ideal solution would be to pass this variable along with a request to make a payment, so that it would then return, as can be done with WebMoney. But I don't know if it's possible. It was not possible to save the desired variable in the session. Checked. How to be?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Entelis, 2014-09-23
@DmitriyEntelis

You are using some YandexMoney library.
Look at her code.
In general, of course, you can transfer your parameters in the API description.
api.yandex.ru/money/doc/dg/reference/request-payme...

$q="UPDATE payment SET status=1,code='$code' WHERE id='$_GET[id_pay]'";
      mysql_query($q);
It makes me want to kill to be honest.
ALWAYS handle variables. ALWAYS.
At least like this
and of course it is better to use mysqli_

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question