PHP code example of qiwi-gate / qg-api

1. Go to this page and download the library: Download qiwi-gate/qg-api 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/ */

    

qiwi-gate / qg-api example snippets


// file index.php


$purseAPIKey   = 'API токен кошелька';
$accountAPIKey = 'API токен аккаунта';

$qiwi = new QGA\QiwiGate($purseAPIKey, $accountAPIKey);

$qiwi->sendRequest($method, $options = [], $assoc = true);

/*
 * Обязательный аргумент
 */ 
// Имя метода
$method  = 'account.info.wallet';

/*
 * Не обязательные аргументы
 */
 // Массив с параметрами 
$options = [                      
    'phone_key' => $purseAPIKey
];
// По умолчанию = true в qiwi->response записывется ассициативный массив
// Если отпарвить false в qiwi->response запишется объект
$assoc = false; 

// Пример неуспешной обработки запроса qiwi->error === true
$qiwi->error = true || false;

// Ответ с сервера в виде ассициативного массива или объекта
$qiwi->response = [
    'status'   => 'success',
    'phone'    => '79000000000',
    'password' => 'xxx',
    'expire'   => 'dd.mm.yyyy',
    'pay'      => '1'
];
// ИЛИ
$qiwi->response->status    = 'success';
$qiwi->response->phone     = '79000000000';
$qiwi->response->password  = 'xxx';
$qiwi->response->expire    = 'dd.mm.yyyy';
$qiwi->response->pay       = '1';

// Ссылка которая была сформирована и по которой был отправлен запрос 
$qiwi->link = 'https://qiwigate.ru/api?key=API токен аккаунта&method=account.info.wallet?phone_key=API токен кошелька';

$purseAPIKey   = 'API токен кошелька';
$accountAPIKey = 'API токен аккаунта';

$qiwi = new QGA\QiwiGate($purseAPIKey, $accountAPIKey);

$options = [                      
    'start'    => '01.01.1970',
    'finish'   => '02.01.1970',
    'status'   => 'SUCCESS',
    'currency' => 'qiwi_RUB',
    'type'     => 'in'
];
$method  = 'qiwi.get.history';

$qiwi->sendRequest($method, $options, false);

if (!$qiwi->error){

    foreach ($qiwi->response->history as $payment) {
        if ($payment['comment'] === $myComment) {
            $db->writeToTheDatabase($payment);
        }
    }
    
} else {
    // Произошла ошибка
}