@m1rvi

Отправка денег на qiwi api?

Нужно отравить деньги через qiwi api.
Есть вот такая помогашка:
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);
    }
}


из них нужен sendMoneyToProvider();
делаю запрос:
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);
}



выдает почему-то NULL и ничего не отправляет

отрывок документации

модератор, теги указаны правильно, не удаляй вопрос : |
  • Вопрос задан
  • 485 просмотров
Решения вопроса 1
@kqlek
Попробуйте без помогашки, вот так:
$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);

Там где __idPROVIVER__ это идентификатор провайдера, см документацию.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы