How to get donation curl to work with ipn

I am trying to get the following to work but for some reason, I can only get it to work with a subscription button and not for a donate button. This is weird because when testing with curl, I got all verified message but nothing after that is working but I repeat that I got this to work with my other subscription button. I also did set the url_notify to my php page and here is the code:

    <?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'] === "[email protected]") {

        $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 = "[email protected]"; // Your Gmail address.
    $mail->Password = "*******"; // Your Gmail login password or App Specific Password.

    /*
     * Message Configuration
     */

    $mail->setFrom('[email protected]', '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;
    }        



        }
    }
    }
    }


     ?>
    ```

    [php](https://stackoverflow.com/questions/tagged/php)

I guess that I can always use my other listener.php, which is working… I just thought that I could get a second file to work

I am still trying to get this to work and read that ipn does not support donation curl…

Maybe nobody here knows? I can’t imagine everyone seeing this topic has experiencing working with the PayPal API. You’re asking a pretty specific question about PayPal. Maybe you’d have more luck on a PayPal related forum or just a generic development forum (like StackOverflow).

1 Like

I guess you are right because I tried stackoverflow but they couldn’t tell me answers too…

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.