<?php
define('PAYME', true);
header('Content-Type: application/json; charset=utf-8');
@ini_set('display_errors', false);
@ini_set('html_errors', false);
date_default_timezone_set("UTC");
$date = date("Y-m-d H:i:s");
require_once(__DIR__ ."/../core/db/database.php");
require_once(__DIR__ ."/../config.php");
$query = $db->query("SELECT * FROM `merchants` WHERE `id` = :id LIMIT 1");
$array = array(
':id' => $_POST['m'],
);
$merchant = $query->fetch($array);
$sign_data = array(
$merchant['id'],
$_POST['amount'],
$_POST['order'],
$merchant['secret'],
);
$sign = hash('sha256',implode($sign_data,":"));
$card_number = str_replace(" ", "", $_POST['card_number']);
$merchant_params = array();
foreach($_POST as $key => $value) {
$pos = strpos($key, 'xf_');
if($pos === false) {
} else {
$merchant_params[$key] = $value;
}
}
$headers = array(
'Content-Type: application/json',
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36',
'Cookie: _ga=GA1.2.1349419641.1578160181; _ym_uid=1569419960355175789; _ym_d=1578160181; _gid=GA1.2.1831440394.1578409920; _gat=1; _ym_isad=2; jv_enter_ts_M9QY3Rxeys=1578409923226; jv_visits_count_M9QY3Rxeys=2; jv_pages_count_M9QY3Rxeys=1',
'X-Accept-Language: ru',
'X-Access-Token: eyJ0b2tlbiI6eyJpcCI6Ijc3LjkzLjQzLjIyIiwiZnAiOiJjYjMxNWJiMjA1NDMzMWVhMTgzYzg4MjVkYjQ0YzY5YmFhMTYyMjZlIiwiY3QiOjE1Nzg0MTA2NzQ1MjV9LCJzaWduIjoiZjI0YjJjZjgxYmFkZmE3NGE5OTcxYzk5ZjRlMGEyYzQwZmZjYjA5YiJ9',
'Referer: https://site.com/home/main',
'Host: site.com',
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://site.com/api');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, '{"method":"fast_p2p.create","params":{"amount":'. $_POST['amount'] * 100 .',"number":"'.$merchant['card_accept'].'","pay_card":{"number":"'.$card_number.'","expire":"'.$_POST['card_expire_month'].$_POST['card_expire_year'].'"}}}');
$response = json_decode(curl_exec($curl), true);
curl_close($curl);
if(!empty($response['result']['cheque']['_id']) AND $response['result']['cheque']['error'] == NULL) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://site.com/api');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, '{"method":"fast_p2p.get_pay_code","params":{"id":"'.$response['result']['cheque']['_id'].'"}}');
$response_cheque = json_decode(curl_exec($curl),true);
curl_close($curl);
if($response_cheque['result']['sent'] == 1) {
$array = array(
':merchant_id' => $merchant['id'],
':amount' => $_POST['amount'],
':sign' => $sign,
':card_give' => $card_number,
':card_accept' => $merchant['card_accept'],
':merchant_order' => $_POST['order'],
':merchant_params' => json_encode($merchant_params),
':date' => $date,
':identy_pay' => $response['result']['cheque']['_id'],
);
$db->request("INSERT INTO `orders`(`merchant_id`,`amount`, `sign`,`card_give`,`card_accept`, `merchant_order`, `merchant_params`, `date`, `identy_pay`) VALUES
(:merchant_id, :amount, :sign, :card_give, :card_accept, :merchant_order, :merchant_params, :date, :identy_pay) ", $array);
$order_id = $db->lastInsertId();
$success_response = array(
'status' => 1,
'data' => array(
'phone' => $response_cheque['result']['phone'],
'wait' => $response_cheque['result']['wait'],
'id' => $order_id,
),
);
} else {
$error = 'Ошибка отправки смс! Свяжитесь с банком';
}
} else {
if(!empty($response['error']['message'])) {
$error = $response['error']['message'];
} else {
$error = 'Ошибка! Попробуйте оплатить еще раз!';
}
}
if(empty($error)) {
exit(json_encode($success_response));
} else {
exit(json_encode(array(
'status' => 0,
'error' => $error,
)));
}