0

I have noticed that the page on paypal for the donation button and subscription form look different and I am not sure if the donation button supports ipn or not because someone sent me a link before but it doesn't have any solutions. I am trying to do a similar script for a donation button that will send an email to thank the user for the donation.

<?php
 ob_start();
include_once __DIR__.'/header2.php';
if (!$_SESSION['u_uid']) {
     echo "<meta http-equiv='refresh' content='0;url=index.php?donation=notlogin'>";
    exit();
} else {

include_once __DIR__.'/includes/dbh.php';

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

 $ch = curl_init();
 curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
 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, 1);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
 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'] === "admin@pianocourse101.com") {

    $cEmail = strip_tags($_POST['payer_email']);
    $firstname = strip_tags($_POST['first_name']);
    $lastname = strip_tags($_POST['last_name']);



    $price = strip_tags($_POST['mc_gross']);
    $currency = strip_tags($_POST['mc_currency']);
    $item = strip_tags($_POST['item_number']);
    $paymentStatus = strip_tags($_POST['payment_status']);




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

        $sql = "INSERT INTO donation (user_email, firstname, lastname, amount) VALUES (?,?,?,?);";

        $stmt = mysqli_stmt_init($conn);

                if(!mysqli_stmt_prepare($stmt, $sql)) {
                       echo "SQL error";
                    } else {
                        mysqli_stmt_bind_param($stmt, "sssi", $cEmail, $firstname, $lastname, $price); 
                        mysqli_stmt_execute($stmt);

                             // Edit this path if PHPMailer is in a different location.


//$mail->SMTPDebug = 2;
include_once __DIR__.'/PHPMailer/Exception.php';
include_once __DIR__.'/PHPMailer/PHPMailer.php';
include_once __DIR__.'/PHPMailer/SMTP.php';
$mail = new PHPMailer\PHPMailer\PHPMailer();
$mail->CharSet = 'UTF-8';
//$mail->isSMTP();  enable this for localhost and disable for live host??? 
$mail->isHTML(true);

/*
 * Server Configuration
 */

$mail->Host = 'smtp.gmail.com'; // Which SMTP server to use.
$mail->Port = 587; // Which port to use, 587 is the default port for TLS and 465 for SSL security.
$mail->SMTPSecure = 'tls'; // Which security method to use. TLS is most secure.
$mail->SMTPAuth = true; // Whether you need to login. This is almost always required.
$mail->Username = "pianocourseforkids101@gmail.com"; // Your Gmail address.
$mail->Password = "*******"; // Your Gmail login password or App Specific Password.

/*
 * Message Configuration
 */

$mail->setFrom('Admin@pianocourse101.com', 'PianoCourse101 Registration'); // Set the sender of the message.
$mail->addAddress($cEmail, 'PianoCourse101 Registration'); // Set the recipient of the message.
$mail->Subject = 'PianoCourse101 Registration'; // The subject of the message.

/*
 * Message Content - Choose simple text or HTML email
 */

// Choose to send either a simple text email...
$mail->Body = "Dear $firstname $lastname, <br /></br />

Thank-you for your kind donation towards PianoCourse101!<br /><br />We hope that you will continue to enjoy your time with us and most importantly, we wish you the best in your piano learning.
<br /><br />

From,

<br /><br />

PianoCourse101
"; // Set a plain text body.

// ... or send an email with HTML.
//$mail->msgHTML(file_get_contents('contents.html'));
// Optional when using HTML: Set an alternative plain text message for email clients who prefer that.
//$mail->AltBody = 'This is a plain-text message body'; 

// Optional: attach a file
$mail->addAttachment('images/phpmailer_mini.png');
if ($mail->send()) {

                     echo "<meta http-equiv='refresh' content='0;url=update.php?upgradelevel1monthly=success'>"; 
                                  exit();
} else {
    echo "Mailer Error: " . $mail->ErrorInfo;
}        



    }
}
}
}


 ?>
piano0011
  • 49
  • 5
  • **[You should not change `CURLOPT_SSL_VERIFYHOST` or `CURLOPT_SSL_VERIFYPEER`](https://paragonie.com/blog/2017/10/certainty-automated-cacert-pem-management-for-php-software)**. It could be a security risk! [Here is how to get the certificate bundle if your server is missing one](https://stackoverflow.com/a/32095378/1839439) – Dharman Aug 01 '19 at 17:00
  • I have set it to 1 but still can't get it to work.... I really disparately need this to work! – piano0011 Aug 02 '19 at 01:01
  • What exactly is the error that you are getting? – Pablo Aug 02 '19 at 03:40
  • I am not getting any errors but can't get any information to be displayed after the all verified success – piano0011 Aug 02 '19 at 05:10
  • does it take web accept as a donation? – piano0011 Aug 02 '19 at 05:10
  • I guess I can always add an extra code in my listener.php but not sure why I can't get a separate file to work for this??? – piano0011 Aug 02 '19 at 09:12
  • Can someone please help me with this? have I misread something here because I can't find any solution... When choosing the paypal donation button, it looks different from the subscription part of paypal – piano0011 Aug 03 '19 at 09:01
  • Has anyone been having problems with paypal ipn not working recently? I selected the web accept but none of the information has been pulled up – piano0011 Aug 03 '19 at 09:01

0 Answers0