D
D
Delonixer2017-10-25 13:41:50
PHP
Delonixer, 2017-10-25 13:41:50

Make a QIWI API request in PHP?

QIWI made a new API not so long ago https://developer.qiwi.com/en/qiwi-wallet-personal...
How to make an authorization and a simple request through PHP?
Some headers are needed there, I entered them, but I don’t know if it’s correct, and how to make a request to the API for certain parameters? My go*nocode is this:


<?php
header('Accept: application/json');
header('Content-Type: application/json');
header('Authorization: Bearer (user token here)');
$qiwi_page = file_get_contents(' https://edge.qiwi.com/person-profile/v1/profile/cu... <parameter here>');
echo $qiwi_page;
?>

My code is not working.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Kostyukevich, 2017-10-25
@Delonixer

Here is an example wrapper for api

class QiwiApi {
    private $_phone;
    private $_token;
    private $_url;
 
    function __construct($phone, $token) {
        $this->_phone = $phone;
        $this->_token = $token;
        $this->_url   = 'https://edge.qiwi.com/';
    }
    private function sendRequest($method, array $content = [], $post = false) {
        $ch = curl_init();
        if ($post) {
            curl_setopt($ch, CURLOPT_URL, $this->_url . $method);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($content));
        } else {
            curl_setopt($ch, CURLOPT_URL, $this->_url . $method . '/?' . http_build_query($content));
        }
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            'Accept: application/json',
            'Content-Type: application/json',
            'Authorization: Bearer ' . $this->_token
        ]); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $result = curl_exec($ch);
        curl_close($ch);
        return json_decode($result, 1);
    }
    public function getAccount(Array $params = []) {
        return $this->sendRequest('person-profile/v1/profile/current', $params);
    }
    public function getPaymentsHistory(Array $params = []) {
        return $this->sendRequest('payment-history/v1/persons/' . $this->_phone . '/payments', $params);
    }
    public function getPaymentsStats(Array $params = []) {
        return $this->sendRequest('payment-history/v1/persons/' . $this->_phone . '/payments/total', $params);
    }
    public function getBalance() {
        return $this->sendRequest('funding-sources/v1/accounts/current')['accounts'];
    }
    public function getTax($providerId) {
        return $this->sendRequest('sinap/providers/'. $providerId .'/form');
    }  
    public function sendMoneyToQiwi(Array $params = []) {
        return $this->sendRequest('sinap/terms/99/payments', $params, 1);
    }
    public function sendMoneyToProvider($providerId, Array $params = []) {
        return $this->sendRequest('sinap/terms/'. $providerId .'/payments', $params, 1);
    }
}

V
Vadim Volkhin, 2018-06-05
@mrShnapik

Qiwi api class php: https://culabra.ru/qiwi-api-class-php-klass-dlya-r... Examples of working with it, connection instructions, etc. It's on the git and on my website. The version is updated as needed. If you have any suggestions or questions, write, we will solve everything :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question