L
L
luckyjenro02021-08-06 19:06:24
PHP
luckyjenro0, 2021-08-06 19:06:24

Why does kiwi execute the request multiple times?

There is a notification handler from QIWI P2P:

include __DIR__ . '/../../../vendor/autoload.php';
include __DIR__ . ('/../../../Modules/MySqli/link.php');
include __DIR__ . ('/../../../Modules/MySqli/vars.php');
include __DIR__ . ('/../Functions.php');
require_once __DIR__ . '/../../Give_Class.php';

use Donate\GiveDonate;

$sha256_hash_header = $_SERVER['HTTP_X_API_SIGNATURE_SHA256']; // Получаем заголовок

$entity_body = file_get_contents('php://input'); // Декодирую тело входящего запроса
$array_body = json_decode($entity_body, 1); // Декодирует строку JSON

$amount_currency = $array_body['bill']['amount']['currency'];
$amount_value = $array_body['bill']['amount']['value'];
$billId = $array_body['bill']['billId'];
$siteId = $array_body['bill']['siteId'];
$status_value = $array_body['bill']['status']['value'];
$nickname = $array_body['bill']['customFields']['nickname'];
$promo = $array_body['bill']['customFields']['promo'];
$count = $array_body['bill']['customFields']['count'];
$good = $array_body['bill']['customFields']['good'];
$paySourcesFilter = $array_body['bill']['customFields']['paySourcesFilter'];
/* тут могут быть дополнительные параметры по типу почты, телефона и тд, ознакомьтесь с документацией если они Вам нужны */

$good_cur = findGood($good);

$good_category = $good_cur['category'];

$array_server = mysqli_query($link, "SELECT * FROM `categorys` WHERE `id`='{$good_category}'");

while ($row = mysqli_fetch_assoc($array_server)) {
  $server_cur = $row['server'];
}

date_default_timezone_set('UTC');

$date_cur = date("y-m-d");

$localtime_assoc = localtime(time(), true);

$time_cur =  $localtime_assoc['tm_hour'] . ":" . $localtime_assoc['tm_min'] . ":" . $localtime_assoc['tm_sec'];

$invoice_parameters = $amount_currency . '|' . $amount_value . '|' . $billId . '|' . $siteId . '|' . $status_value;

$sha256_hash = hash_hmac('sha256', $invoice_parameters, $qiwi_secret);

if (!empty($sha256_hash_header) && $sha256_hash_header == $sha256_hash && $status_value == 'PAID') {
  $response = mysqli_query($link, "INSERT INTO `payments` (`id`, `login`, `good_id`, `sum`, `category`, `server`, `date_pay`, `time_pay`, `amount`, `promo-use`, `status`) VALUES (NULL, '{$nickname}', '{$good}', '{$amount_value}', '{$good_category}', '{$server_cur}', '{$date_cur}', '{$time_cur}', '{$count}', '{$promo}', 'NULL')");

  $request = new GiveDonate();
  $nickname_o = $request->nickname = $nickname;
  $amount_o = $request->amount = $count;
  $good_id_o = $request->good_id = $good;

  $checks = $request->Give($nickname_o, $good_id_o, $amount_o);
  die('OK');
}


For some reason, after the client has paid, a record is entered into the database, then after 20 seconds another one, and this is repeated 5 times, that is, the handler must be entered once, and for some reason the qiwi goes to it 5 times.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
luckyjenro0, 2021-08-06
@luckyjenro0

Problem solved! In my method, which was performed after the payment, there was a delay in connecting to the server for 3 seconds, and in the qiwi documentation it is written that if there was no answer within 2 seconds, then it will send a request on-line!

I
inFureal, 2021-08-06
@inFureal

Make logs of the entire response request from kiwi. There is an option that updates to the state of the transaction come. Something like, it came, retention, receipt, transfer to a personal account, etc.

S
Stockholm Syndrome, 2021-08-06
@StockholmSyndrome

I can assume that kiwi is waiting not just for OK, but also for json as a response, as it is written in the documentation
, and because it does not receive, it sends the request again

$data = [ "error" => "0" ];
echo json_encode($data);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question