M
M
m1rvi2020-10-11 18:55:16
PHP
m1rvi, 2020-10-11 18:55:16

Sending money to qiwi api?

You need to send money through qiwi api.
There is this help:

spoiler

class Qiwi {
    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,
            'Host: edge.qiwi.com'
        ]); 
        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/v2/persons/' . $this->_phone . '/payments', $params);
    }
    public function getPaymentsStats(Array $params = []) {
        return $this->sendRequest('payment-history/v2/persons/' . $this->_phone . '/payments/total', $params);
    }
    public function getTxn($txnId, Array $params = []) {
        return $this->sendRequest('payment-history/v2/transactions/' . $txnId .'/', $params);
    }
    public function getCheck($txnId, Array $params = []) {
  return $this->sendRequest('payment-history/v1/transactions/' . $txnId .'/cheque/file', $params);
    } 
    public function getBalance() {
        return $this->sendRequest('funding-sources/v2/persons/' . $this->_phone . '/accounts');
    }
    public function getTax($providerId) {
        return $this->sendRequest('sinap/providers/'. $providerId .'/form');
    } 
    public function sendMoneyToQiwi(Array $params = []) {
        return $this->sendRequest('sinap/api/v2/terms/99/payments', $params, 1);
    }
    public function sendMoneyToProvider($providerId, Array $params = []) {
        return $this->sendRequest('sinap/api/v2/terms/'. $providerId .'/payments', $params, 1);
    }
    public function sendMoneyToOther(Array $params = []) {
        return $this->sendRequest('sinap/api/v2/terms/1717/payments', $params, 1);
    }
}


of which sendMoneyToProvider() is needed;
making a request:
spoiler

if(isset($_POST['goPay'])) {
$qiwi = new Qiwi('+79649911177', 'токен нельзя палить');
$sendMoney = $qiwi->sendMoneyToProvider([
  "id" => "21131343",
  "sum" => [
        "amount" => 8,
        "currency" => "643"
  ],
  "paymentMethod"  =>  [
      "type" => "Account",
      "accountId" => "643"
  ],
  
  "fields" => [
        "account" => "+79114353887"
  ]
  ]);
  var_dump($sendMoney);
}



gives out for some reason NULL and nothing is sent by

the moderator

, the tags are correct, do not delete the question : |

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kqlek, 2020-10-11
@m1rvi

Try it without help, like this:

$token = 'токен нельзя палить';

$paramGet = [
    "id" => (string)(1000 * time()),
    "sum" => [
        "amount" => 8,
        "currency" => "643"
    ],
    "paymentMethod" => [
        "type" => "Account",
        "accountId" => "643"
    ],
    "comment" => "Testing",
    "fields" => [
        "account" => "+79114353887"
    ]
];
$dataPostParam = json_encode($paramGet, JSON_UNESCAPED_UNICODE);

$ch = curl_init("https://edge.qiwi.com/sinap/api/v2/terms/__idPROVIVER__/payments");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Accept: application/json',
        'Authorization: Bearer ' . $token
    )
);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataPostParam);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$sResponse = curl_exec($ch);

Where __idPROVIVER__ is a provider ID, see the documentation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question