// Ищем телефон $found = $db->getOne('modx_sms_validator', $sms['phones'], 'phone', 'id,user_id,status,phone,code_sent'); if (!empty($found)) { if ($state['status'] == 'checked') { throw new Exception('checked', 200); } // Повторный запрос, модифицируем строку в БД $state = $found; $state['code_sent'] = $state['code_sent'] . ',' . $sms_code; $check_arr = explode(',', $state['code_sent']); if (count($check_arr) > MAX_STORE_CODES) { unset($check_arr[0]); $state['code_sent'] = implode(',', $check_arr); } $state['status'] = 'ready'; $db->updateOne('modx_sms_validator', $found['id'], $state); } else { // Номер не зарегистрирован, новая строка в БД $state = array('phone' => $sms['phones'], 'code_sent' => $sms_code); $state['user_id'] = $modx->user->id; $state['id'] = $db->putOne('modx_sms_validator', $state); } // print_r($state); // Отправляем смс $response = send_sms($sms, $smsc_config); $state['response'] = $response['raw']; if (isset($response['response']['id'])) { $state['request_id'] = $response['response']['id']; $state['status'] = 'sent'; } else { $state['status'] = 'error';
} if (isset($_REQUEST['Desc'])) { $order['Desc'] = filter_var($_REQUEST['Desc'], FILTER_SANITIZE_STRING); } if (isset($_REQUEST['name'])) { $order['name'] = filter_var($_REQUEST['name'], FILTER_SANITIZE_STRING); } if (isset($_REQUEST['email'])) { $order['email'] = filter_var($_REQUEST['email'], FILTER_SANITIZE_EMAIL); } if (isset($_REQUEST['phone'])) { $order['email'] = filter_var($_REQUEST['phone'], FILTER_SANITIZE_STRING); } // Database save row, and get this row ID require_once API_ROOT_PATH . '/core/class/database/database.class.php'; require_once API_ROOT_PATH . '/core/config/pdo.config.php'; $db = new Database($pdoconfig_lander); $id = $db->putOne('payments', $order); // Подготовка запроса в Робокассу $robokassa_data = array('InvId' => $id, 'Desc' => $order['Desc'], 'IncCurrLabel' => "", 'Culture' => "ru", 'Encoding' => "utf-8"); $robokassa_data = array_merge($robokassa_data, $order); $robokassa = new Robokassa($robokassa_data, $payments_config['robokassa']); $order['SignatureValue'] = $robokassa->genCRC2(); $db->updateOne('payments', $id, $order); if (DEBUG) { print "payURL: " . $robokassa->payURL() . "\n"; print_r($order); print_r($robokassa->resultArray()); } else { header('Location: ' . $robokassa->payURL()); }
} // Чтение инфо о Заказе из БД require_once API_ROOT_PATH . '/core/class/database/database.class.php'; require_once API_ROOT_PATH . '/core/config/pdo.config.php'; $db = new Database($pdoconfig_lander); $order = $db->getOne('payments', $id); //print_r($order); // Проверка if ($order['SignatureValue'] == $_POST['SignatureValue']) { $log_array['status'] = 'Successful'; } // Запись в файл $log_array['attempt'] = $order['attempts'] + 1; $log_array['Requested ID'] = $id; $json = json_encode($log_array); $curtime = time() - 3600; $data = date("Y-m-d H:i:s", $curtime); $content = $data . ' incoming POST:' . $json . " REMOTE_ADDR:" . $_SERVER['REMOTE_ADDR'] . "\n"; file_put_contents('log.txt', $content, FILE_APPEND); // Обновление информации в БД $status = 'Неизвестный статус'; if ($log_array['status'] == 'Fail') { $status = 'Ошибка'; } if ($log_array['status'] == 'Successful' || $order['Status'] == 'Оплачено') { $status = 'Оплачено'; } // $db_data = array('Status' => $status, 'attempts' => $log_array['attempt']); $db->updateOne('payments', $id, $db_data); print $log_array['status'];