Answer the question
In order to leave comments, you need to log in
Why json_encode() and http_build_query() don't work on Qiwi API curl request?
$headers = array(
"Authorization: Bearer " . config('services.qiwi.key'),
"Accept: application/json",
"Content-Type: application/json"
);
$transactionId = '111111111111';
$amount = 10.55;
$currency = 643;
$sum = ['amount' => $amount, 'currency' => $currency];
$type = 'Account';
$accountId = 643;
$paymentMethod = ['type' => $type, 'accountId' => $accountId];
$comment = 'test comment';
$acc = "+22222"; // receive payments to
$fields = ['account' => $acc];
$request = [
'id' => $transactionId,
'sum' => $sum,
'paymentMethod' => $paymentMethod,
'fields' => $fields,
'comment' => $comment,
];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_POSTFIELDS => http_build_query($request),
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60, // seconds
CURLOPT_ENCODING => 'UTF-8'
));
$result = curl_exec($curl);
curl_close($curl);
return json_decode($result, true);
"message" => """
Invalid Json: Unrecognized token 'id': was expecting ('true', 'false' or 'null')\n
at [Source: [email protected]; line: 1, column: 4]
"""
http_build_query($request)
// на такое
$str = '{
"id":"11111111111111",
"sum": {
"amount":100,
"currency":"643"
},
"paymentMethod": {
"type":"Account",
"accountId":"643"
},
"comment":"test",
"fields": {
"account":"+79121112233"
}
}';
"account":"+ . $phoneNum . "
, somehow this is not correct, I think. "code" => "QWPRC-220"
"message" => "Недостаточно средств "
]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question