execute('INSERT INTO `znote_pagseguro_notifications` VALUES (null, ?, ?, CURRENT_TIMESTAMP)', [getValue($code), $details]); } function VerifyPagseguroIPN($code) { global $pagseguro; $url = $pagseguro['urls']['ws']; $cURL = curl_init(); curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($cURL, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($cURL, CURLOPT_URL, 'https://' . $url . '/v3/transactions/' . $code . '?email=' . $pagseguro['email'] . '&token=' . $pagseguro['token']); curl_setopt($cURL, CURLOPT_HEADER, false); curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true); curl_setopt($cURL, CURLOPT_FORBID_REUSE, true); curl_setopt($cURL, CURLOPT_FRESH_CONNECT, true); curl_setopt($cURL, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($cURL, CURLOPT_TIMEOUT, 60); curl_setopt($cURL, CURLINFO_HEADER_OUT, true); curl_setopt($cURL, CURLOPT_HTTPHEADER, array( 'Connection: close', 'Expect: ', )); $Response = curl_exec($cURL); $Status = (int)curl_getinfo($cURL, CURLINFO_HTTP_CODE); curl_close($cURL); return trim($Response); } $transactionCode = getValue($_GET['transaction'] ?? null); $rawTransaction = VerifyPagseguroIPN($transactionCode); $transaction = simplexml_load_string((string)$rawTransaction); if ($transaction === false || !isset($transaction->items->item[0])) { header('Location: shop.php'); exit; } $transactionStatus = (int) $transaction->status; $completed = ($transactionStatus != 7) ? 0 : 1; $custom = (int) $transaction->reference; $item = $transaction->items->item[0]; $points = $item->quantity; $price = $points * ($pagseguro['price'] / 100); db()->execute( 'INSERT INTO `znote_pagseguro` VALUES (null, ?, ?, ?, ?, ?, ?)', [sanitize((string)$transaction->code), $custom, $price, $points, $transactionStatus, $completed] ); header('Location: shop.php?callback=processing');