Jump to content


Photo

Ipn Multi Items

paypal ipn

  • Please log in to reply
1 reply to this topic

#1 Mauro

Mauro

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 12 October 2014 - 10:55 PM

Hello There, hope for some help, i been having some trouble with my php script, before works very well because it was online for single items but now that i integrated with a store that checksout multi items i cant make this works.

 

For some reason it isnt inserting in my database multi-items.

 

Hope that someone can take a look at my code.

if($_POST)
{
        
        
       $paypalmode     =   '.sandbox';
        
        $req = 'cmd=' . urlencode('_notify-validate');
        foreach ($_POST as $key => $value) {
            $value = urlencode(stripslashes($value));
            $req .= "&$key=$value";
        }
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://www'.$paypalmode.'.paypal.com/cgi-bin/webscr');
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www'.$paypalmode.'.sandbox.paypal.com'));
        $res = curl_exec($ch);
        curl_close($ch);

        if (strcmp ($res, "VERIFIED") == 0)
        {
            $item_name = $_POST['item_name'];
            $item_number = $_POST['item_number'];
           
            $payment_currency = $_POST['currency_code'];
            $ref = $_POST['custom'];
            $payment_amount = $_POST['mc_gross']; 
            $receiver_email = $_POST['receiver_email']; 

            
            $mdate=  date('Y-m-d H:i:s');

            $first_name = $_POST['first_name'];
            $last_name = $_POST['last_name'];
            $payer_email = $_POST['payer_email'];
            $address_country = $_POST['address_country'];
            
            $address_zip = $_POST['address_zip'];
            $address_street = $_POST['address_street'];
            $address_city = $_POST['address_city'];

            $conn = mysql_connect($dbhost,$dbusername,$dbpassword);
            if (!$conn)
            {
             die('Could not connect: ' . mysql_error());
            }

            mysql_select_db($dbname, $conn);

            // insert in our IPN record table
            $query = "INSERT INTO sales
            (item_name,item_number,payment_currency,date_time,ref,payment_amount,receiver_email,first_name,last_name,payer_email,address_country,address_zip,address_street,address_city)
            VALUES
            ('$item_name','$item_number','$payment_currency','$mdate','$ref','$payment_amount','$receiver_email','$first_name','$last_name','$payer_email','$address_country','$address_zip','$address_street','$address_city')";


            // Send Email

            $yourEmail = "myemail.com";
                            $subject = "Online Store";

                            $headers = "MIME-Version: 1.0\r\n";
                            $headers .= "Content-type: text/html; charset=utf-8\r\n";/*para o envio com formatação HTML. Charset po ser iso-8859-1 também*/
                            $headers .= "From: Info  <info@domain.com>\r\n";
                            $headers .= "Reply-To: info@otherdmain.com\r\n";
                    
        
                            $body = "";
                            $body .= "Name: $first_name<br />";
                            $body .= "Items: $item_name<br />";
                            $body .= "Email:$payer_email<br />";
                            $body .= "Amount: $payment_amount<br />";
                            $body .= "Date: $mdate<br />";
                            $body .= "R: $address_street<br />";
                            $body .= "City: $address_city<br />";
                            $body .= "CP: $address_city<br />";
                            $body .= "Country: $address_zip<br />";
                            $body .= "Type:Paypal<br /> <br />";
                            $body .= "<img src=\"\"  alt=\"\"/>";

                            mail($yourEmail, $subject, $body,$headers);
							
					



            if(!mysql_query($query))
            {
                //mysql error..!
            }
            mysql_close($conn);

        }
}


#2 paypaldev

paypaldev

    Administrator

  • Administrators
  • 29 posts

Posted 01 February 2015 - 04:21 PM

For multiple item purchases, PayPal will append a number value to identify the product in the IPN response. So your normal value for a single item checkout of item_number, will become, item_number_0, then item_number_1, etc.


Paymetrics.com - Sales Alanytics and Metrics for PayPal.






Also tagged with one or more of these keywords: paypal, ipn

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users