PHP code example of yandex-money / yandex-money-sdk-php

1. Go to this page and download the library: Download yandex-money/yandex-money-sdk-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yandex-money / yandex-money-sdk-php example snippets


    // For payments from the Yandex.Money wallet
    zation
    

    use \YandexMoney\API;

    $auth_url = API::buildObtainTokenUrl($client_id, $redirect_uri, $scope);
    

    $access_token_response = API::getAccessToken($client_id, $code, $redirect_uri, $client_secret=NULL);
    if(property_exists($access_token_response, "error")) {
        // process error
    }
    $access_token = $access_token_response->access_token;
    

    $api = new API($access_token);

    // get account info
    $acount_info = $api->accountInfo();

    // check status 

    // get operation history with last 3 records
    $operation_history = $api->operationHistory(array("records"=>3));

    // check status 

    // make request payment
    $request_payment = $api->requestPayment(array(
        "pattern_id" => "p2p",
        "to" => $money_wallet,
        "amount_due" => $amount_due,
        "comment" => $comment,
        "message" => $message,
        "label" => $label,
    ));

    // check status 

    // call process payment to finish payment
    $process_payment = $api->processPayment(array(
        "request_id" => $request_payment->request_id,
    ));
    

    use \YandexMoney\ExternalPayment;

    $response = ExternalPayment::getInstanceId($client_id);
    if($response->status == "success") {
        $instance_id = $response->instance_id;
    }
    else {
        // throw exception with $response->error message
    }
    

    // make instance
    $external_payment = ExternalPayment($instance_id);

    $payment_options = array(
        // pattern_id, etc..
    );
    $response = $external_payment->request($payment_options);
    if($response->status == "success") {
        $request_id = $response->request_id;
    }
    else {
        // throw exception with $response->message
    }
    

    $process_options = array(
        "request_id" => $request_id
        // other params..
    );
    $result = $external_payment->process($process_options);
    // process $result according to docs
    

API($access_token).requestPayment(array(
    test_payment => "true",
    // other params
));