C
C
Chaly952019-09-26 18:49:45
PHP
Chaly95, 2019-09-26 18:49:45

What causes the Unrecognized token 'storeId': was expecting ('true', 'false' or 'null') error when trying to send a POST request via CURL?

Hello
, I don’t understand why an error can occur when trying to send a POST request.
When trying to send a POST request, the following error occurs:
Array ( [state] => FAIL [message] => Unrecognized token 'storeId': was expecting ('true', 'false' or 'null') at [Source: java.io [email protected]; line: 1, column: 9] )
Here is the code I use to send the request:

$curl = curl_init('https://payparts2.privatbank.ua/ipp/v2/payment/create');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS,
    http_build_query(array(
        'storeId' => '4AAD1369CF734B64B70F',
        'orderId' => '12345',
        'amount' => 400,
        'partsCount' => 6,
        'merchantType' => 'II',
        'scheme' => 1111,
        'products' => array(
            array(
                'name' => 'Телевизор',
                'count' => 2,
                'price' => 200
            )
        ),
        'recipientId'=> 'qwerty1234',
        'responseUrl'=> 'http://shop.com/response',
        'redirectUrl'=> 'http://shop.com/redirect',
    'signature' => base64_encode (SHA1('75bef16bfdce4d0e9c0ad5a19b9940df'.'4AAD1369CF734B64B70F'.'12345'.'400'.'II'.'http://shop.com/response'.'http://shop.com/redirect'.array(array('Телевизор'.'2'.'200')).'75bef16bfdce4d0e9c0ad5a19b9940df'))
    ))
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json','Accept-Encoding: UTF-8','Content-Type: application/json; charset=UTF-8'));
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$response = curl_exec($curl);


$curl_errno = curl_errno($curl);
$curl_error = curl_error($curl);
$aInfo = @curl_getinfo($curl);

curl_close($curl);

I would be grateful for any help)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SerJook, 2019-09-26
@chaly95

You specify Content-Type: application/json and send data in application/x-www-form-urlencoded format.
You need to use json_encode instead of http_build_query

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question