Ipn script not working here but working in other webhost


#1

Hello!

I am trying to get my script to work below but I can’t seem to get it to work on this server but can get it to work on my other webhosting server:

<?php if ($_SERVER['REQUEST_METHOD'] != 'POST') { header("Location: index.php"); exit(); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "cmd=_notify-validate&" . http_build_query($_POST)); $response = curl_exec($ch); curl_close($ch); if ($response == 'VERIFIED' && $_POST['receiver_email'] == 'piano0011@hotmail.com') { $cEmail = $_POST['payer_email']; $name = $_POST['first_name']." ".$_POST['last_name']; $price = $_POST['mc_gross']; $currency = $_POST['mc_currency']; $item = $_POST['item_number']; $paymentStatus = $_POST['payment_status']; if ($item == "subscriptionplan" && $currency == "USD" && $paymentStatus == "Completed" && $price == 100) { echo ' success';

#2

What error are you getting? :slight_smile:


#3

Hello!

I am getting the message of invalid


#4

Can you please send a screenshot?


#5

Hello!

This is the screenshot


#6

hang on a sec… it is working now I think


#7

I don’t think it is working because it should be sending an email to confirm the purchased:

<?php

 if ($_SERVER['REQUEST_METHOD'] != 'POST') {
 	header("Location: index.php");
 	exit();
 }

 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr');
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, "cmd=_notify-validate&" . http_build_query($_POST));
 $response = curl_exec($ch);
 curl_close($ch);

if ($response == 'VERIFIED' && $_POST['receiver_email'] == 'piano0011@hotmail.com') {
	$cEmail = $_POST['payer_email'];
    $name = $_POST['first_name']." ".$_POST['last_name'];
    
    $price = $_POST['mc_gross'];
    $currency = $_POST['mc_currency'];
    $item = $_POST['item_number'];
    $paymentStatus = $_POST['payment_status'];

    if ($item == "subscriptionplan" && $currency == "USD" && $paymentStatus == "Completed" && $price == 100) {

    	$sql = "SELECT * FROM memberships WHERE user_email = ?;";
        $paid = 1;
    	$stmt = mysqli_stmt_init($conn);

                if(!mysqli_stmt_prepare($stmt, $sql)) {
			           echo "SQL error";
			        } else {
			          mysqli_stmt_bind_param($stmt, "s", $cEmail);
			          mysqli_stmt_execute($stmt);
                      $result = mysqli_stmt_get_result($stmt);
                      $resultCheck = mysqli_num_rows($result);
                      if ($resultCheck < 1) {
                      	 header("Location: header2.php?listener=noaccount");
                      	 exit();
                      } else {
                      	$sql2 = "UPDATE memberships
                                 SET paid = ?
                                 WHERE user_email = ?
                      	        ;";

                      	$stmt = mysqli_stmt_init($conn);

                if(!mysqli_stmt_prepare($stmt, $sql2)) {
			           echo "SQL error";
			        } else {
			          mysqli_stmt_bind_param($stmt, "is", $paid, $cEmail);
			          mysqli_stmt_execute($stmt);
                      }
    	$to = $cEmail;

                                    //sender
                                    $from = 'pianocourse101@hotmail.com';
                                    $fromName = 'PianoCourse101';

                                    //email subject
                                    $subject = 'Thank you for purchasing one of our subscriptionplans!'; 

                                    //attachment file path
                                    $file = "codexworld.pdf";

                                    //email body content
                                    $htmlContent = "<h1>Thank you for purchasing one of our subscriptionplans!!</h1>
                                        <p>Dear ".$name.", \n\nThank you for purchasing one of our subscriptionplans!\n\nYou can now access your lessons via the members' section. You are also welcome to download the contents for your own personal learning</p>"

                                    //header for sender info
                                    $headers = "From: $fromName"." <".$from.">";

                                    //boundary 
                                    $semi_rand = md5(time()); 
                                    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 

                                    //headers for attachment 
                                    $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; 

                                    //multipart boundary 
                                    $message = "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" .
                                    "Content-Transfer-Encoding: 7bit\n\n" . $htmlContent . "\n\n"; 

                                    //preparing attachment
                                    if(!empty($file) > 0){
                                        if(is_file($file)){
                                            $message .= "--{$mime_boundary}\n";
                                            $fp =    @fopen($file,"rb");
                                            $data =  @fread($fp,filesize($file));

                                            @fclose($fp);
                                            $data = chunk_split(base64_encode($data));
                                            $message .= "Content-Type: application/octet-stream; name=\"".basename($file)."\"\n" . 
                                            "Content-Description: ".basename($file)."\n" .
                                            "Content-Disposition: attachment;\n" . " filename=\"".basename($file)."\"; size=".filesize($file).";\n" . 
                                            "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
                                        }
                                    }
                                    $message .= "--{$mime_boundary}--";
                                    $returnpath = "-f" . $from;

                                    //send email
                                    $mail = @mail($to, $subject, $message, $headers, $returnpath); 

                                    //email sending status
                                    echo $mail?"<h1>Mail sent.</h1>":"<h1>Mail sending failed.</h1>";



    } else {
    	header("Location: update.php?listener=notmatchinginformation");
    	exit();
    }
}

#8

Where in your code does it echo invalid?


#9

Hello!

I thought it was working before but when I changed my setting in my ipn simulator, it didn’t get updated in my test.txt file