1

I'm such new on e-commerce and I've developed using PHP a ticketting system based on https://github.com/smhack/Ticket, well everything works fine and the payement works (PayPal Shopping Cart) etc... (I'm using PayPal Sandbox)

I have tested my IPN on the IPN simulator and it works, however in my project I can't figure why the PHP code on the IPN is not taken on consideration (Insert on the database, sending confirmation mail)

HTML :

<form name="_xclick" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="m.bendriss-facilitator@gpayme.com">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="item_name" value="<?php echo $classTitle;?>">
    <input type="hidden" name="item_number" value="Class">
    <input type="hidden" name="custom" value="<?php echo $id;?>">
    <input type="hidden" name="amount" value="<?php echo $price;?>">
    <input type="hidden" name="return" value="http://www.croisentoi.com/ticket/">
    <input type="hidden" name="notify_url" value="http://www.croisentoi.com/ticket/ipn.php">
    <input type="image" src="http://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>

ipn.php :

<?php

    include('ipnlistener.php');
    include("config.php"); 

    if($sqlTicketservertype = 'mysql'){
    $db = new PDO('mysql:host='.$sqlTicketserver.';dbname='.$sqlTicketdbname, $sqlTicketusername, $sqlTicketpassword);
    }
    // tell PHP to log errors to ipn_errors.log in this directory
    ini_set('log_errors', true);
    ini_set('error_log', dirname(__FILE__).'/ipn_errors.log');

    $listener = new IpnListener();
    $listener->use_sandbox = true;

    try {
        $verified = $listener->processIpn();
    } catch (Exception $e) {
        // fatal error trying to process IPN.
    error_log($e->getMessage());
        exit(0);
    }

    if ($verified) {
        // IPN response was "VERIFIED"
        $email = $_POST['payer_email'];
        $txn = $_POST['txn_id'];
        $firstName = $_POST['first_name']; 
        $lastName = $_POST['last_name'];
        $paymentDate = $_POST['payment_date'];

        $query = $db->PREPARE("INSERT INTO tickets ( email, txn, firstName, lastName, paymentDate  ) VALUES ( '$email', '$txn', '$firstName', '$lastName', '$paymentDate'  )");
        $query->execute();

        mail('bendrissmehdi@gmail.com', 'Valid IPN', $listener->getTextReport());
    } else {
        // IPN response was "INVALID"
        mail('bendrissmehdi@gmail.com', 'Invalid IPN', $listener->getTextReport());
    }

?>

I Thought that the IPN should be executed when the payement is Ok. So why this file is not read ? Do you have any idea about this ?

EDIT : The project is hosted on http://croisentoi.com/ticket

Thank you

1 Answers1

0

You have to turn on IPN Notification in the Paypal Sandbox site too, in order for it to work from your PHP scripts. Go ahead and turn it on with an ipn url (you can later override this url using the "return" attribute in your php script):

https://www.sandbox.paypal.com/cgi-bin/customerprofileweb?cmd=_profile-ipn-notify

Prahlad Yeri
  • 3,567
  • 4
  • 25
  • 55
  • Thank you Prahlad. I've enabled them now, and setted the url of the IPN php file in the field `Url of notification`. I proceed the payement and when the payement is done I get redirected to my website but nothing get executed and the Database is still empty. Did I forget something ? Thank you. –  Oct 24 '13 at 10:17
  • 1
    @Mehdi - In the notification url, check for POST variables. When paypal sends an IPN notification to you, it adds a lot of post data like order_name, order_qty, custom, etc. I don't remember the exact names right now, but there are a plethora of them. Iterate through the $_POST php array to fetch them. – Prahlad Yeri Oct 24 '13 at 11:26
  • I can see that you have handled some variables in your code, but check their exact names. For time-being, comment out this code and just write all $_POST variables in the response to check out what paypal is sending your. – Prahlad Yeri Oct 24 '13 at 11:31
  • Or just to be sure, remove the block: "if ($verified)", to see that whether at least the variables are received. You may then check out the $listener->processIPN() function for any issues. – Prahlad Yeri Oct 24 '13 at 11:33
  • My bad, I did setted the IPN url in the buyer account instead of the seller one... Sorry, I didn't pe attention.. It works perfectly now. Thanks. –  Oct 24 '13 at 12:04