· 5 years ago · Feb 04, 2020, 03:24 PM
1<?php
2
3include 'vendor/autoload.php';
4
5use Qiwi\Api\BillPaymentsException;
6use Qiwi\Api\TestCase;
7use Qiwi\Api\BillPayments;
8use Curl\Curl;
9
10class QiwiDonate{
11
12 public $publicKey = 'публичный ключ qiwi p2p';
13 public $secretKey = секретный ключ qiwi p2p';
14 public $access_token = 'токен киви';
15 public $phone = 'телефон';
16 public $url = 'https://edge.qiwi.com/';
17
18 public function buildPayUrl($amount, $id, $sell){
19
20 $params = [
21 'publicKey' => $this->publicKey,
22 'amount' => $amount,
23 'comment' => 'BrawlBot_'.$sell.'_'.$id
24 ];
25
26 $billPayments = new BillPayments;
27 return $billPayments->createPaymentForm($params);
28
29 }
30
31 public function sendRequest($method, array $content = [], $post = false){
32
33 $ch = curl_init();
34 if ($post) {
35 curl_setopt($ch, CURLOPT_URL, $this->url.$method);
36 curl_setopt($ch, CURLOPT_POST, 1);
37 curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($content));
38 } else {
39 curl_setopt($ch, CURLOPT_URL, $this->url.$method.'/?'.http_build_query($content));
40 }
41 curl_setopt($ch, CURLOPT_HTTPHEADER, [
42 'Accept: application/json',
43 'Content-Type: application/json',
44 'Authorization: Bearer '.$this->access_token,
45 'Host: edge.qiwi.com'
46 ]);
47 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
48 $result = curl_exec($ch);
49 curl_close($ch);
50 return json_decode($result, 1);
51
52 }
53
54 public function getAccount(Array $params = []) {
55 return $this->sendRequest('person-profile/v1/profile/current', $params);
56 }
57
58 public function getPaymentsHistory(Array $params = []) {
59 return $this->sendRequest('payment-history/v2/persons/'.$this->phone.'/payments', $params);
60 }
61
62 public function getPaymentsStats(Array $params = []) {
63 return $this->sendRequest('payment-history/v2/persons/'.$this->phone.'/payments/total', $params);
64 }
65
66 public function sendMoneyToQiwi(Array $params = []) {
67 return $this->sendRequest('sinap/api/v2/terms/99/payments', $params, 1);
68 }
69
70}