close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Ray built paypal listener page insert doesn't work anymore code. Does anything look wrong?

Thread began 2/14/2024 11:10 am by JBWebWorks | Last modified 2/16/2024 7:43 am by JBWebWorks | 92 views | 7 replies

JBWebWorks

Thanks, I will try that.
It didn’t work so I found this code and it does the insert but not correct data because PayPal doesn’t validate. It gives errors 301 or 302. Any suggestions?

<?php require_once('Connections/connsqli.php'); ?>
<?php require_once('webassist/mysqli/queryobj.php'); ?>
<?php

// STEP 1: Read POST data

// reading posted data from directly from $_POST causes serialization
// issues with array data in POST
// reading raw POST data from input stream instead.
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
$keyval = explode ('=', $keyval);
if (count($keyval) == 2)
$myPost[$keyval[0]] = urldecode($keyval[1]);
}
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
$get_magic_quotes_exists = true;
}
foreach ($myPost as $key => $value) {
if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
$value = urlencode(stripslashes($value));
} else {
$value = urlencode($value);
}
$req .= "&$key=$value";
}


// STEP 2: Post IPN data back to paypal to validate

$ch = curl_init('https://ipnpb.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
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_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));

// In wamp like environments that do not come bundled with root authority certificates,
// please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path
// of the certificate as shown below.
// curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
if( !($res = curl_exec($ch)) ) {
// error_log("Got " . curl_error($ch) . " when processing IPN data");
curl_close($ch);
exit;
}
curl_close($ch);


// STEP 3: Inspect IPN validation result and act accordingly

if (strcmp ($res, "VERIFIED") == 0) {
// check whether the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment

// assign posted variables to local variables
$txn_id = $_POST['txn_id'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$payer_email = $_POST['payer_email'];
$address_street = $_POST['address_street'];
$address_city = $_POST['address_city'];
$address_state = $_POST['address_state'];
$address_zip = $_POST['address_zip'];
$item_name = $_POST['item_name'];
$quantity = $_POST['quantity'];
$payment_amount = $_POST['mc_gross'];
$mc_fee = $_POST['mc_fee'];
$mc_shipping = $_POST['mc_shipping'];


// <---- HERE you can do your INSERT to the database
if (true) {
$InsertQuery = new WA_MySQLi_Query($connsqli);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "paypal_transactions";
$InsertQuery->bindColumn("transaction_ID", "i", "txn_id", "WA_DEFAULT");
$InsertQuery->bindColumn("first_name", "s", "first_name", "WA_DEFAULT");
$InsertQuery->bindColumn("last_name", "s", "last_name", "WA_DEFAULT");
$InsertQuery->bindColumn("email1", "s", "payer_email", "WA_DEFAULT");
$InsertQuery->bindColumn("address_street", "s", "address_street", "WA_DEFAULT");
$InsertQuery->bindColumn("city", "s", "address_city", "WA_DEFAULT");
$InsertQuery->bindColumn("state", "s", "address_state", "WA_DEFAULT");
$InsertQuery->bindColumn("zip", "s", "address_zip", "WA_DEFAULT");
$InsertQuery->bindColumn("item_name", "s", "item_name", "WA_DEFAULT");
$InsertQuery->bindColumn("quantity", "s", "quantity", "WA_DEFAULT");
$InsertQuery->bindColumn("payment_gross", "s", "mc_gross", "WA_DEFAULT");
$InsertQuery->bindColumn("mc_shipping", "s", "mc_shipping", "WA_DEFAULT");
$InsertQuery->bindColumn("payment_fee", "s", "mc_fee", "WA_DEFAULT");
$InsertQuery->saveInSession("");
$InsertQuery->execute();
$InsertGoTo = "";
if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
$InsertQuery->redirect($InsertGoTo);
}
} else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...