D
D
Darth Vader2017-03-22 10:42:45
PHP
Darth Vader, 2017-03-22 10:42:45

Why does Yandex send an incomprehensible response in the http notification from the payment?

Hello. I ran into such a problem, I want to accept payments on my site, I send myself a test notification about the payment, Yandex sends me a response in a format I don’t understand, I don’t understand why.
Handler Example

$secret = '000000000000000000000000'; 
$r = array(
  'notification_type' => $_POST['notification_type'], 
  'operation_id'      => $_POST['operation_id'],      
  'amount'            => $_POST['amount'],       
  'withdraw_amount'   => $_POST['withdraw_amount'],   
  'currency'          => $_POST['intval'],          
  'datetime'          => $_POST['datetime'],       
  'sender'            => $_POST['sender'],            
  'codepro'           => $_POST['codepro'],      
  'label'             => $_POST['label'],            
  'sha1_hash'         => $_POST['sha1_hash']          
);

if (sha1($r['notification_type'].'&'.
         $r['operation_id'].'&'.
         $r['amount'].'&'.
         $r['currency'].'&'.
         $r['datetime'].'&'.
         $r['sender'].'&'.
         $r['codepro'].'&'.
         $secret.'&'.
         $r['label']) != $r['sha1_hash']) {
  exit('Верификация не пройдена. SHA1_HASH не совпадает.');
}

file_put_contents('history.php', $r . PHP_EOL , FILE_APPEND);

I open the history.php file to see what Yandex sent me there, and there is such a thing
a:1:{i:0;a:11:{s:17:"notification_type";s:12:"p2p-incoming";s:6:"amount";s:6:"343.83";s:8:"datetime";s:20:"2017-03-22T07:34:08Z";s:7:"codepro";s:5:"false";s:6:"sender";s:11:"41001000040";s:9:"sha1_hash";s:40:"ab0760f1a82db2bd56ab897b9d8b3090803a8a24";s:17:"test_notification";s:4:"true";s:15:"operation_label";s:0:"";s:12:"operation_id";s:17:"test-notification";s:8:"currency";s:3:"643";s:5:"label";s:0:"";}}

What am I doing wrong?
I try through the unserialize function, if I process what is written to the file, namely this
a:1:{i:0;a:11:{s:17:"notification_type";s:12:"p2p-incoming";s:6:"amount";s:6:"343.83";s:8:"datetime";s:20:"2017-03-22T07:34:08Z";s:7:"codepro";s:5:"false";s:6:"sender";s:11:"41001000040";s:9:"sha1_hash";s:40:"ab0760f1a82db2bd56ab897b9d8b3090803a8a24";s:17:"test_notification";s:4:"true";s:15:"operation_label";s:0:"";s:12:"operation_id";s:17:"test-notification";s:8:"currency";s:3:"643";s:5:"label";s:0:"";}}

Like this
$data = unserialize('a:1:{i:0;a:11:{s:17:"notification_type";s:12:"p2p-incoming";s:6:"amount";s:6:"475.02";s:8:"datetime";s:20:"2017-03-22T07:57:29Z";s:7:"codepro";s:5:"false";s:6:"sender";s:11:"41001000040";s:9:"sha1_hash";s:40:"cfff3e99ad82fe74802802a4cb7d8838f69440ae";s:17:"test_notification";s:4:"true";s:15:"operation_label";s:0:"";s:12:"operation_id";s:17:"test-notification";s:8:"currency";s:3:"643";s:5:"label";s:0:"";}}');
echo "<pre>";
print_r($data);
echo "</pre>";

Then at the output we get this
Array
(
    [0] => Array
        (
            [notification_type] => p2p-incoming
            [amount] => 475.02
            [datetime] => 2017-03-22T07:57:29Z
            [codepro] => false
            [sender] => 41001000040
            [sha1_hash] => cfff3e99ad82fe74802802a4cb7d8838f69440ae
            [test_notification] => true
            [operation_label] => 
            [operation_id] => test-notification
            [currency] => 643
            [label] => 
        )

)

But if I try to do the same when processing the response, then nothing happens and the same thing is written to the file.
This is how I process the response, for example, I want to know the sender.
$data = unserialize($r);
file_put_contents('history.php', $data[0]['sender'] . PHP_EOL , FILE_APPEND);

get
a:1:{i:0;a:11:{s:17:"notification_type";s:12:"p2p-incoming";s:6:"amount";s:6:"475.02";s:8:"datetime";s:20:"2017-03-22T07:57:29Z";s:7:"codepro";s:5:"false";s:6:"sender";s:11:"41001000040";s:9:"sha1_hash";s:40:"cfff3e99ad82fe74802802a4cb7d8838f69440ae";s:17:"test_notification";s:4:"true";s:15:"operation_label";s:0:"";s:12:"operation_id";s:17:"test-notification";s:8:"currency";s:3:"643";s:5:"label";s:0:"";}}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
riot26, 2017-03-22
@blackdarthvader

php.net/manual/en/function.unserialize.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question