C
C
Chaly952019-09-29 10:48:26
PHP
Chaly95, 2019-09-29 10:48:26

What causes an Internal server error when trying to send a POST via CURL to pay in installments from Privat Bank?

Hello
When you try to make a Post request, an Internal server error occurs.
I send a post request using curl to receive a token for payment in installments from Privat Bank.
Here is the code created based on Api https://bw.gitbooks.io/api-oc/content/pay.html
Here is an example of using https://payparts2.privatbank.ua/ipp/sandbox#!create
Here is my code:

$curl = curl_init('https://payparts2.privatbank.ua/ipp/v2/payment/create');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS,
    json_encode(array(
        'storeId' => '4AAD1369CF734B64B70F',
        'orderId' => '12211212121',
        'amount' => 2,
        'partsCount' => 5,
        'merchantType' => 'PP',
        'scheme' => 1111,
        'products' => array(
            array(
                'name' => 'test',
                'count' => 1,
                'price' => 2
            )
        ),
        'recipientId'=> 'qwerty1234',
        'responseUrl'=> 'https://adsasd',
        'redirectUrl'=> 'https://saddsa',
    'signature' => base64_encode ( SHA1 ( '75bef16bfdce4d0e9c0ad5a19b9940df'.'4AAD1369CF734B64B70F'.'12211212121'.' 200'.' 5'.' PP'.'https://adsasd'.'https://saddsa'.' test1200'.' 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);
//execute curl
$response = curl_exec($curl);

//get execute result
$curl_errno = curl_errno($curl);
$curl_error = curl_error($curl);
$aInfo = @curl_getinfo($curl);
//close curl
curl_close($curl);



$response =  json_decode($response,true);
print_r($response);

I can’t understand why, when requesting to the private bank sandbox, everything works, but when sending from my server, an Internal server error occurs.
My script on the server https://wp.pipl.ua/test.php.
I would be grateful for any help!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Nikolaev, 2019-09-29
@chaly95

OK.
The minimum amount is 300, so you have 2.
Next, do you want 2 to be divided by 5 in some way?
Do I understand correctly that you want the user to make 5 transactions of 40 kopecks each?
In addition, you also have an error in the signature:
If you look carefully, you have spaces before 200, 5 and PP.
Further: you have a 'recipientId' parameter that you pass, but it is missing in the hash sum, but according to the rules it should be. Either remove or add to the formation.
Do what you need and get another error:

Array
(
    [orderId] => 12211212121
    [signature] => +JYghcAp9oIQq3xR/Zn1PftEvQ8=
    [state] => FAIL
    [message] => bad value: Scheme not found for given store
    [storeId] => 4AAD1369CF734B64B70F
)

But this is all because scheme is a Scheme Identifier. Allocated by the Bank. Not transmitted by default.
You delete it and you get the coveted:
Array
(
    [orderId] => 12211212121
    [signature] => S4cN/oBUIIJeHlcJgTTM+gcZddQ=
    [state] => FAIL
    [message] => bad value: Payment with sent orderId already exists
    [storeId] => 4AAD1369CF734B64B70F
)

And this is because someone has already run your request through api or through a web face. You change the orderid and get the coveted:
Array
(
    [orderId] => fdsa1
    [signature] => x2m4GaLFv3ptcxZLynRzwuy/t5g=
    [token] => ADFEDB2FB0C7485CB968148D4BFD6B5A
    [state] => SUCCESS
    [storeId] => 4AAD1369CF734B64B70F
)

R
Randewoo, 2019-09-29
@Randewoo

You crash their server.
500 Internal Server Error is purely a server error, it cannot process your request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question