close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

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 | 60 views | 7 replies |

JBWebWorks

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

<?php require_once('Connections/connsqli.php'); ?>
<?php require_once('webassist/mysqli/queryobj.php'); ?>
<?php
require "paypal_integration_class/paypal.class.php";
require "config.php";

$p = new paypal_class;
$p->paypal_url = $payPalURL;

if ($p->validate_ipn()) {
if($p->ipn_data['payment_status']=='Completed')
{
$amount = $p->ipn_data['mc_gross'] - $p->ipn_data['mc_fee'];
?>
<?php
if (true) {
$InsertQuery = new WA_MySQLi_Query($connsqli);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "paypal_transactions";
$InsertQuery->bindColumn("transaction_ID", "s", "".$p->ipn_data['txn_id']."", "WA_DEFAULT");
$InsertQuery->bindColumn("first_name", "s", "".$p->ipn_data['first_name']."", "WA_DEFAULT");
$InsertQuery->bindColumn("last_name", "s", "".$p->ipn_data['last_name']."", "WA_DEFAULT");
$InsertQuery->bindColumn("email1", "s", "".$p->ipn_data['payer_email']."", "WA_DEFAULT");
$InsertQuery->bindColumn("address1", "s", "".$p->ipn_data['address1']."", "WA_DEFAULT");
$InsertQuery->bindColumn("address2", "s", "".$p->ipn_data['address2']."", "WA_DEFAULT");
$InsertQuery->bindColumn("city", "s", "".$p->ipn_data['city']."", "WA_DEFAULT");
$InsertQuery->bindColumn("state", "s", "".$p->ipn_data['state']."", "WA_DEFAULT");
$InsertQuery->bindColumn("zip", "s", "".$p->ipn_data['zip']."", "WA_DEFAULT");
$InsertQuery->bindColumn("amount", "d", "".$amount."", "WA_DEFAULT");
$InsertQuery->bindColumn("item_name", "s", "".$p->ipn_data['item_name']."", "WA_DEFAULT");
$InsertQuery->bindColumn("quantity", "i", "".$p->ipn_data['quantity']."", "WA_DEFAULT");
$InsertQuery->bindColumn("payment_gross", "s", "".$p->ipn_data['mc_gross']."", "WA_DEFAULT");
$InsertQuery->bindColumn("payment_fee", "i", "".$p->ipn_data['payment_fee']."", "WA_DEFAULT");
$InsertQuery->bindColumn("special_requests", "s", "".$p->ipn_data['option_selection1']."", "WA_DEFAULT");
$InsertQuery->bindColumn("original_request", "s", "".http_build_query($_POST)."", "WA_DEFAULT");
$InsertQuery->saveInSession("");
$InsertQuery->execute();
$InsertGoTo = "";
if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
$InsertQuery->redirect($InsertGoTo);
}
?>
<?php
}
}
?>
Sign in to reply to this post

Mags

Did you try turning on error reporting? Add the following code to the very top of the page, then try to run your page and let me know what the error message is:

<?php
error_reporting(E_ALL);
ini_set('display_errors','on');
?>

Sign in to reply to this post

JBWebWorks

nothing shows as this is all code on the page

Sign in to reply to this post

JBWebWorks

one strange thing - I us e DW with webassist SQLI and when i click on server behaviors and click ok, it changes the code to this

<?php
error_reporting(E_ALL);
ini_set('display_errors','on');
?><?php require_once('Connections/connsqli.php'); ?>
<?php require_once('webassist/mysqli/queryobj.php'); ?>
<?php
require "paypal_integration_class/paypal.class.php";
require "config.php";

$p = new paypal_class;
$p->paypal_url = $payPalURL;

if ($p->validate_ipn()) {
if($p->ipn_data['payment_status']=='Completed')
{
$amount = $p->ipn_data['mc_gross'] - $p->ipn_data['mc_fee'];
?>
<?php
if (true) {
$InsertQuery = new WA_MySQLi_Query($connsqli);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "paypal_transactions";
$InsertQuery->bindColumn("transaction_ID", "i", "\".$p->ipn_data['txn_id'].\"", "WA_DEFAULT");
$InsertQuery->bindColumn("first_name", "s", "\".$p->ipn_data['first_name'].\"", "WA_DEFAULT");
$InsertQuery->bindColumn("last_name", "s", "\".$p->ipn_data['last_name'].\"", "WA_DEFAULT");
$InsertQuery->bindColumn("email1", "s", "\".$p->ipn_data['payer_email'].\"", "WA_DEFAULT");
$InsertQuery->bindColumn("address1", "s", "\".$p->ipn_data['address1'].\"", "WA_DEFAULT");
$InsertQuery->bindColumn("address2", "s", "\".$p->ipn_data['address2'].\"", "WA_DEFAULT");
$InsertQuery->bindColumn("city", "s", "\".$p->ipn_data['city'].\"", "WA_DEFAULT");
$InsertQuery->bindColumn("state", "s", "\".$p->ipn_data['state'].\"", "WA_DEFAULT");
$InsertQuery->bindColumn("zip", "s", "\".$p->ipn_data['zip'].\"", "WA_DEFAULT");
$InsertQuery->bindColumn("amount", "d", "\".$amount.\"", "WA_DEFAULT");
$InsertQuery->bindColumn("item_name", "s", "\".$p->ipn_data['item_name'].\"", "WA_DEFAULT");
$InsertQuery->bindColumn("quantity", "i", "\".$p->ipn_data['quantity'].\"", "WA_DEFAULT");
$InsertQuery->bindColumn("payment_gross", "s", "\".$p->ipn_data['mc_gross'].\"", "WA_DEFAULT");
$InsertQuery->bindColumn("payment_fee", "i", "\".$p->ipn_data['payment_fee'].\"", "WA_DEFAULT");
$InsertQuery->bindColumn("special_requests", "s", "\".$p->ipn_data['option_selection1'].\"", "WA_DEFAULT");
$InsertQuery->bindColumn("original_request", "s", "\".http_build_query($_POST).\"", "WA_DEFAULT");
$InsertQuery->saveInSession("");
$InsertQuery->execute();
$InsertGoTo = "";
if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
$InsertQuery->redirect($InsertGoTo);
}
?>
<?php
}
}
?>



it adds the back slashes

Sign in to reply to this post

Mags

If the page was built a while ago and you now have a newer version of DataAssist installed, chances are it will make some updates in the code if you open and re-save the server behavior. Not sure what the significance of the backslash is though, or why it would be added. You could try removing them manually. There certainly doesn't look to be any errors in the code. I see it's a page that runs the insert behavior on page load, so with error reporting on I would expect it to show an error when you load the page if it doesn't write to the database.

Has your server upgraded its PHP version recently? One thing you could try - where single quotes have been used (i.e. ['txn_id']) try changing to double quotes (i.e. ["txn_id"] - I'm not sure if this will make any difference but I've had a few issues when upgrading to PHP8 where I've had to change single to double quotes or vice-versa.

Sign in to reply to this post

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
}
Sign in to reply to this post

Mags

Sorry, I don't really know anything about Paypal integration. Errors 301 and 302 are usually redirect errors though - 301 is permanent and 302 is temporary.

Sign in to reply to this post

JBWebWorks

I found (I think) that when the redirect is to https://paypal.com/cgi-bin/webscr the error is 301 permanently moved
and when the redirect is to https://ipnpb.paypal.com/cgi-bin/webscr the error is 302 temporarily moved

i don't know what that means or how to fix?

Sign in to reply to this post

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...