Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include("dbconn.php");
- require("phpmailer/PHPMailerAutoload.php");
- class ipnn
- {
- public function __construct($mode = 'sandbox')
- {
- if($mode == 'sandbox')
- $this->_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
- else
- $this->_url = 'https://www.paypal.com/cgi-bin/webscr';
- }
- public function run()
- {
- $raw_post_data = file_get_contents('php://input');
- $raw_post_array = explode('&', $raw_post_data);
- $_POST = array();
- foreach ($raw_post_array as $keyval)
- {
- $keyval = explode ('=', $keyval);
- if (count($keyval) == 2)
- $_POST[$keyval[0]] = urldecode($keyval[1]);
- }
- $postFields = 'cmd=_notify-validate';
- if(function_exists('get_magic_quotes_gpc'))
- {
- $get_magic_quotes_exists = true;
- }
- //var_dump($postFields);die;
- //cmd=_notify-validate¶m=value¶m2=value2;
- foreach ($_POST as $key => $value)
- {
- if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1)
- {
- $value = urlencode(stripslashes($value));
- }
- else
- {
- $value = urlencode($value);
- }
- $postFields .= "&$key=$value";
- }
- $paypalUrl= "https://www.sandbox.paypal.com/cgi-bin/webscr";
- $ch = curl_init($paypalUrl);
- curl_setopt_array($ch, array(
- CURLOPT_URL => $this->_url,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_SSL_VERIFYPEER => false,
- CURLOPT_POST => true,
- CURLOPT_POSTFIELDS => $postFields
- ));
- $result = curl_exec($ch);
- curl_close($ch);
- $tokens = explode("\r\n\r\n", trim($result));
- $result = trim(end($tokens));
- if (strcmp($result, "VERIFIED") == 0 || strcasecmp($result, "VERIFIED") == 0)
- {
- include("dbconn.php");
- $mail = new PHPMailer();
- // set mailer to use SMTP
- $mail->IsSMTP();
- $mail->Debugoutput = 'html';
- // As this email.php script lives on the same server as our email server
- // we are setting the HOST to localhost
- $mail->Host = "smtp.gmail.com"; // specify main and backup server
- $mail->Port = 587;
- $mail->SMTPAuth = true; // turn on SMTP authentication
- // When sending email using PHPMailer, you need to send from a valid email address
- // In this case, we setup a test email account with the following credentials:
- // email: send_from_PHPMailer@bradm.inmotiontesting.com
- // pass: password
- $mail->Username = "atomsphera1@gmail.com"; // SMTP username
- $mail->Password = "pentium123"; // SMTP password
- $mail->setFrom('Football_Ticket@Fam.com', 'Nazmi Mohamad');
- $item_number = $_POST['item_number'];
- $item_name = $_POST['item_name'];
- $txn_id = $_POST['txn_id'];
- $payment_gross = $_POST['mc_gross'];
- $currency_code = $_POST['mc_currency'];
- $payment_status = $_POST['payment_status'];
- $payer_email = $_POST['payer_email'];
- $payer_status = $_POST['payer_status'];
- $payer_id = $_POST['payer_id'];
- $ic = $_POST['custom'];
- $gameid = $_POST['quantity'];
- $payment_date = date('Y-m-d H:i:s');
- $sql5 = "SELECT * FROM pay WHERE txn_id = '$txn_id'";
- $query5 = mysqli_query($dbconn, $sql5);
- $row5 = mysqli_num_rows($query5);
- if ($row5 > 0)
- {
- echo "Duplicate transaction ID occured so we killed the IPN script. \n\n\n$req";
- exit();
- }
- else
- {
- $insert = mysqli_query($dbconn, "INSERT INTO pay VALUES('".''."','".$txn_id."','".$item_number."','".$item_name."','".$payment_gross."','".$currency_code."','".$payment_status."','".$payer_id."','".$payer_email."','".$payer_status."','".$ic."','".$payment_date."')");
- $a = "<img src='qr_img.php?d=$ic,$item_number,$item_name,$payment_status,$payment_gross'>";
- echo "Your payment has been recorded!";
- //$mail->From = $email;
- // below we want to set the email address we will be sending our email to.
- $mail->addAddress('bobby.mieyehh2723@gmail.com');
- //$to_array = explode(',', $to);
- //foreach($to_array as $address)
- //{
- // $mail->addAddress($address, 'Web Enquiry');
- //}
- // set word wrap to 50 characters
- $mail->WordWrap = 50;
- // set email format to HTML
- $mail->IsHTML(true);
- //$mail->Subject = "You have received feedback from your website!";
- // $message is the user's message they typed in
- // on our contact us page. We set this variable at
- // the top of this page with:
- // $message = $_REQUEST['message'] ;
- $subject = 'Your Payment Receipt';
- $mail->Subject = $subject;
- $mail->AltSubject = $subject;
- $mail->AddEmbeddedImage('qr_img.php?d=$ic,$item_number,$item_name,$payment_status,$payment_gross', 'qr');
- $mail->Body = "<img src=\"cid:qr\" />, $payment_status, $item_name, $ic, $payment_gross";
- $mail->AltBody = "<img src=\"cid:qr\" />, $payment_status, $item_name, $ic, $payment_gross";
- if(!$mail->Send())
- {
- echo "Message could not be sent. <p>";
- echo "Mailer Error: " . $mail->ErrorInfo;
- exit;
- }
- echo "Message has been sent";
- }
- mysqli_close($dbconn);
- }
- $fh = fopen('result.txt', 'w');
- fwrite($fh, $result . ' -- ' . $postFields);
- fclose($fh);
- //echo $result;
- //echo $postFields;
- echo "<table style=color:#FFF> <tr> <td>";
- echo "<img src='qr_img.php?d=$ic,$item_number,$item_name,$payment_status,$payment_gross'> </td> </tr>";
- echo"<tr><td>Identication Number: </td>";
- echo"<td>".$ic."</td></tr>";
- echo"<tr><td>Your Email: </td>";
- echo"<td>".$payer_email."</td></tr>";
- echo"<tr><td>Payment: </td>";
- echo"<td>".$payment_gross."</td></tr>";
- echo"<tr><td>Payment Status: </td>";
- echo"<td>".$payment_status."</td></tr>";
- echo"<tr><td>Payer Status: </td>";
- echo"<td>".$payer_status."</td></tr>";
- echo"<tr><td>Payment Date: </td>";
- echo"<td>".$payment_date."</td></tr>";
- echo"<tr><td>Payment Date: </td>";
- echo"<td>".$gameid."</td></tr>";
- echo"<br><tr><td>"."<input type=button value=Print class='btn btn-primary' style='width:80px'>"."</td></tr>";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement