D
D
dimaweyder2019-08-06 15:29:01
PHP
dimaweyder, 2019-08-06 15:29:01

Why does it say the array is empty?

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://cpay.tranzzo.com/api/v1/payment");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$headers = [
  'Content-Type: application/json',	
    'X-API-AUTH: CPAY 377e4982-4304-48ef-bacf-d100eb1e3949:UWtlaGo0R0FFMkljQWR0UWw5dU1WZUE3',
    'X-API-KEY: AIzaSyCH4mpFmGXPElJmYG_KIlU0ZvEnuTLyFnc'
];



$d = '{
  "pos_id":           "974a4a95-13f4-43ea-9670-bf0c1185ee83",
  "mode":              "hosted",
  "method":            "purchase",
  "amount":            1,
  "currency":          "RUB",
  "description":       "description_1",
  "order_id":         "123",
  "order_3ds_bypass":  "always",
  "server_url":        "https://localhost/callback.php",
  "result_url":        "https://localhost/result.php",
  "payload":         "sale=true"
}';



curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($d));

$server_output = curl_exec($ch);

curl_close ($ch);
echo $server_output;

Here's what it outputs. help me please
5d497276ea659686692782.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim Kot, 2019-08-06
@dimaweyder

json-encode() https://www.php.net/manual/ru/function.json-encode.php returns a json string, and you pass it there. If you want to make an array from a json string, use https://www.php.net/manual/ru/function.json-decode.php with the second $assoc parameter set to true.
But if you need to pass an array to CURLOPT_POSTFIELDS, then form an associative array in $d right away.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question