Sign in to follow this  
Followers 0
hominidsmash

script help

12 posts in this topic

Just looking to see if someone can make a easy php script to pull emails from PayPal IPN on checkout and insert it into a SQL table for a mailing list automatically. Anyone wanna help :P

Share this post


Link to post
Share on other sites

i really havent worked with paypal's IPN before, so pretty much cant explain this exactly how it is,

but here's what i think,

 

Please login or register to see this link.

 

as that post explained, paypal returns the value's once the payment is completed,

what you need though is to look through the functions.php file there, you probably have something similar since once the payment is made you'll want the order to be stored in your database,

 

as you can see here in the payments.php :

// assign posted variables to local variables$data['item_name'] = $_POST['item_name'];$data['item_number'] = $_POST['item_number'];$data['payment_status'] = $_POST['payment_status'];$data['payment_amount'] = $_POST['mc_gross'];$data['payment_currency'] = $_POST['mc_currency'];$data['txn_id'] = $_POST['txn_id'];$data['receiver_email'] = $_POST['receiver_email'];$data['payer_email'] = $_POST['payer_email'];$data['custom'] = $_POST['custom'];

you'll see it also returns the payer_email,

which means, all you have to do is let your sql query (which inserts the data into your orders table) to also log $data['payer_email'] into either the same table, simply by adding the email value into the orders table, or to log it into a mailing table,

 

either way, i cant really be more specific as to how you can save this data since you didnt share any of the code you're using right now, hope this'll help you set it up though.

Share this post


Link to post
Share on other sites

so basically I need to pull, $data['payer_email'] = $payer_email; and $cart_item_data['quantity'] = $cart_item['quantity']; and send them to a seperate "mailing list db"

 

 

 

if the quantity is 1 I will need it to send an email 27 days, if it is 2, 57 days, and so on 30*x-3, where x=quantity.

 

I don't really know where to start so the little code I do have is pretty much garbo.

 

Any help would be greatly appreciated. 

 

I am willing to donate like $20 to who ever helps me if need be :)

Share this post


Link to post
Share on other sites

Ok, so I lied.

 

This what I have so far:

 

<?php// Start require_once('mail/config.php');// Gather order data.$order_data['receiver_email'] = $receiver_email;$order_data['first_name'] = $first_name;$order_data['last_name'] = $last_name;$order_data['payer_email'] = $payer_email;//Debug mode:error_reporting(E_ALL);//Sure you want to show some error if something went wrong:$errors = array(); /** *  * @return TRUE if connection established  * FALSE on error */function connect(){ $connection = mysql_connect(NULL, NULL, NULL);  // SQL Server information IE: (localhost, root, pass) $db = mysql_select_db(mail_queue,$connection);     if (!$connection || !$db ){   return false;  } else {   return true; }}//So this code will run if user did submit the form:if (!empty($_POST)){ //Connect sql server: if ( !connect() ){   $errors[] = "Can't establish link to MySQL server"; }  //No error at this point - means that it successfully connected to SQL server:  if ( empty($errors) ){  //let's prevent sql injection:  $payer_email = mysql_real_escape_string($payer_email);  $first_name = mysql_real_escape_string($first_name);  $last_name = mysql_real_escape_string($last_name);   }//Now we should try to INSERT the values:$query = "INSERT INTO `mail_queue` (`first_name`,`last_name`, `payer_email`) VALUES ('$first_name', '$last_name', '$email')";//So try it:if ( !mysql_query($query) ){   //    //die (mysql_error());   $errors[] = "Can't insert the values";} else {   //Or on success:   print ("Success"); // Temp   }mysql_close($connection);}?>

 

In this I just want it to pull, the first+last name, and the email and put it into the mail queue db

$payer_email = mysql_real_escape_string($_POST['payer_email']);$first_name = mysql_real_escape_string($_POST['first_name']);$last_name = mysql_real_escape_string($_POST['last_name']);

Does this work? Make sure that you actually got some values in those posts by printing them out.

I don't really understand what the main problem is.. :P

Share this post


Link to post
Share on other sites

also, in your query, 

$query = "INSERT INTO `mail_queue` (`first_name`,`last_name`, `payer_email`) VALUES ('$first_name', '$last_name', '$email')";\\

 

$email doesnt exist, theres only $payer_email

 

but ye, like ocrion stated, try printing the values before running the query, to see if they actually contain the values you need, that way, if they do, you know the problem lies in inserting the query into your database, if they do not contain the value, then you'll have to look back to how you receive and handle them

Share this post


Link to post
Share on other sites

$order_data['receiver_email'] = $receiver_email;
$order_data['first_name'] = $first_name;
$order_data['last_name'] = $last_name;
$order_data['payer_email'] = $payer_email;

 

Where is the data coming from? Is it $_POST, $_GET, are you setting it manually above/in  config.php? Could do with seeing more of your code.

Share this post


Link to post
Share on other sites

you have to verify the ipn request with sending it back to paypal via curl. for smaller apps this is common:

 

Please login or register to see this link.

 

You can see a pretty basic example on github, you have to use it more advanced ofc. I would suggest to use a database class if you are not that advanced with is, this one is doing a pretty good job:

 

Please login or register to see this link.

 

Negative 'mc_gross' values are refunds, positive ones are payments obvious. Make sure to insert the txn id in a seperate column and check if the id already exists before processing the payment, otherwise it can get abused. Also check for payment_status, receiver_email and mc_currency.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0