PayPal Auto Return with Payment Data Transfer (PDT) -- Empty data fields
I have been working with PayPal Sandbox and with PayPal's help have managed to process a payment all the way back to the checkout_success.php page. There I have added PayPal's PDT code to show transaction details.
However, only some of the order details are being displayed.
As in, the first name, last name and total price are there, but not the product item name and special order details.
PDF attached showing screen grabs of the payment process from product_detail thru to checkout_success.
Here is the code on the checkout_success page from PayPal with additional code noted for the special order items
<?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-synch';
$tx_token = $_GET['tx'];
//$auth_token = "GX_sTf5bW3wxRfFEbgofs88nQxvMQ7nsI8m21rzNESnl_79ccFTWj2aPgQ0";
$auth_token = "CduukMlO1KidMS9n67P27_ccJwYyxxUDEPsSVWA8Eye8hM3RLpUAHF7jjbW";
$req .= "&tx=$tx_token&at=$auth_token";
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
// If possible, securely post back to paypal using HTTPS
// Your PHP server will need to be SSL enabled
// $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
// read the body data
$res = '';
$headerdone = false;
while (!feof($fp)) {
$line = fgets ($fp, 1024);
if (strcmp($line, "\r\n") == 0) {
// read the header
$headerdone = true;
}
else if ($headerdone)
{
// header has been read. now read the contents
$res .= $line;
}
}
// parse the data
$lines = explode("\n", $res);
$keyarray = array();
if (strcmp ($lines[0], "SUCCESS") == 0) {
for ($i=1; $i<count($lines);$i++){
list($key,$val) = explode("=", $lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}
// check 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
// code from PayPal
$firstname = $keyarray['first_name'];
$lastname = $keyarray['last_name'];
$itemname = $keyarray['item_name'];
$amount = $keyarray['payment_gross'];
// code added
$embroiderytype = $keyarray['EmbroideryType'];
$embroiderystyle = $keyarray['EmbroideryStyle'];
$embroiderytext = $keyarray['EmbroideryText'];
$specialrequest = $keyarray['SpecialRequest'];
echo ("<p><h3>Thank you for your purchase!</h3></p>");
echo ("<b>Payment Details</b><br>\n");
// code from PayPal
echo ("<li>Name: $firstname $lastname</li>\n");
echo ("<li>Item: $itemname</li>\n");
echo ("<li>Amount: $amount</li>\n");
echo ("\n");
// code added
echo ("<b>Embroidery Details if selected</b><br>\n");
echo ("<li>Embroidery Type: $embroiderytype</li>\n");
echo ("<li>Embroidery Style: $embroiderystyle</li>\n");
echo ("<li>Embroidery Text: $embroiderytext</li>\n");
echo ("<li>Special Request: $specialrequest</li>\n");
echo ("");
}
else if (strcmp ($lines[0], "FAIL") == 0) {
// log for manual investigation
}
}
fclose ($fp);
?>
NOTE: I should add to make the PDT code work on checkout_success.php I had to delete the redirects that eCart had added above the <!doctype...
<?php
//WA eCart Include
require_once("WA_eCart/eCart1_PHP.php");
?><?php
$eCart1->GetContent();
?>
<?php
if ($eCart1->IsEmpty()) {
$eCart1->redirStr = "cart.php";
$eCart1->cartAction = "RedirectIfEmpty";
}
?>
<?php
// WA eCart Redirect
if ($eCart1->redirStr != "") {
header("Location: ".$eCart1->redirStr);
}
?>
ALSO: In addition to getting the missing order details to display, can I add a Show If for the Embroidery Options so only shows if Embroidery was included in the order?
Many thanks as always!
ADDENDUM
Once the checkout_success page content is working correctly, can I then setup with Universal Email to send the customer an email confirming all the order details?
I did try to add Universal Email to the Order Confirm page before going to PayPal but that would be too soon. What if the customer does not complete the order with PayPal, abandons the order? Plus I should note it did not work, as in did not send an email.
I guess I do not understand how UE works with PayPal orders. Because another issue arises if the customer does not have a PayPal account and so is not automatically redirected back to checkout_success. They have to manually select the link to be taken back from PayPal to checkout_success. Is that when IPN would be used (Instant Payment Notification) and if so how do I setup with UE?