Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Content-Type: text/html; charset=ISO-8859-1');
- define('TOKEN', 'Digite seu TOKEN aqui');
- $servername = "localhost";
- $username = " ";
- $password = " ";
- $dbname = "pagseguro";
- $conn = new mysqli($servername, $username, $password, $dbname);
- if ($conn->connect_error)
- {
- die("Connection failed: " . $conn->connect_error);
- }
- mysqli_query($conn, "SET NAMES 'utf8'"); // Essa Query foi a solução que eu encontrei para extrair caracteres especiais sem problemas.
- class PagSeguroNpi
- {
- private $timeout = 20;
- public function notificationPost() {
- $postdata = 'Comando=validar&Token='.TOKEN;
- foreach ($_POST as $key => $value) {
- $valued = $this->clearStr($value);
- $postdata .= "&$key=$valued";
- }
- return $this->verify($postdata);
- }
- private function clearStr($str) {
- if (!get_magic_quotes_gpc()) {
- $str = addslashes($str);
- }
- return $str;
- }
- private function verify($data) {
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, "https://pagseguro.uol.com.br/pagseguro-ws/checkout/NPI.jhtml");
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_HEADER, false);
- curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- $result = trim(curl_exec($curl));
- curl_close($curl);
- return $result;
- }
- }
- if (count($_POST) > 0)
- {
- $npi = new PagSeguroNpi();
- $result = $npi->notificationPost();
- if ($result === "VERIFICADO")
- {
- if($_POST['StatusTransacao'] === "Aprovado")
- {
- $Code = $_POST['TransacaoID'];
- $Produto_ID = $_POST['ProdID_1'];
- if($Produto_ID == 1) $Cash = 1000;
- else if($Produto_ID == 2) $Cash = 2000; //Aqui você irá definir quanto de cash vale cada produto
- $sql = "INSERT INTO pagseguro (Code, Cash) VALUES ('$Code', '$Cash')";
- $conn->query($sql);
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement