close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

PayPal Auto Return with Payment Data Transfer (PDT) -- Empty data fields

Thread began 6/01/2012 10:17 am by toni272059 | Last modified 6/05/2012 4:01 pm by Jason Byrnes | 25540 views | 9 replies |

toni272059

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?

Attached Files
payment-process.pdf.zip
Sign in to reply to this post

Jason ByrnesWebAssist

so the details coming back from paypal are stored in the an array called "$keyarray"


I think your probably trying to access variables from the key array by the wrong name.


to see the contents of the $keyarray array including the variable names that you should be using, use the following code:

php:
<?php

echo("<pre>");
var_dump($keyarray);
echo(
"</pre>");
?>





quite frankly, paypal standard is a bear of a system to work with. I would recommend express checkout instead, it is another free service from paypal and you wont have the issues like IPN and PDT.

you will need to sign up for api access, in eCart, select to use paypal payments pro, then delete the checkout form from the checkout page.

If you stick with standard, you will need to use the IPN page to send the UE receipt, there are many threads in this form that talk about IPN and sending the email.

Sign in to reply to this post

toni272059

I found info to use correct PayPal html variables and updated Confirm page code

<?php //WA eCart Validation
if ((WA_eCart_FormatNumber($eCart1->DisplayInfo("Price") - (($eCart1->DisplayInfo("Price")/$eCart1->TotalColumn("TotalPrice")) * $eCart1->GetDiscounts()), false, 2) > 0)) {
?>
<input type="hidden" name="amount_<?php echo $eCart1_Index+1; ?>" id="amount_<?php echo $eCart1_Index+1; ?>" value="<?php echo WA_eCart_FormatNumber($eCart1->DisplayInfo("Price") - (($eCart1->DisplayInfo("Price")/$eCart1->TotalColumn("TotalPrice")) * $eCart1->GetDiscounts()), false, 2) ?>" />
<input type="hidden" name="item_name_<?php echo $eCart1_Index+1; ?>" id="item_name_<?php echo $eCart1_Index+1; ?>" value="<?php echo $eCart1->DisplayInfo("Name") ?>" />
<input type="hidden" name="item_number_<?php echo $eCart1_Index+1; ?>" id="item_number_<?php echo $eCart1_Index+1; ?>" value="<?php echo $eCart1->DisplayInfo("ID") ?>" />
<input type="hidden" name="quantity_<?php echo $eCart1_Index+1; ?>" id="quantity_<?php echo $eCart1_Index+1; ?>" value="<?php echo $eCart1->DisplayInfo("Quantity") ?>" />
<input type="hidden" name="on0_<?php echo $eCart1_Index+1; ?>" id="on0_<?php echo $eCart1_Index+1; ?>" value="Embroidery Type:" />
<input type="hidden" name="os0_<?php echo $eCart1_Index+1; ?>" id="os0_<?php echo $eCart1_Index+1; ?>" value="<?php echo $eCart1->DisplayInfo("EmbroideryType"); ?>" />
<input type="hidden" name="on1_<?php echo $eCart1_Index+1; ?>" id="on1_<?php echo $eCart1_Index+1; ?>" value="Embroider Style:" />
<input type="hidden" name="os1_<?php echo $eCart1_Index+1; ?>" id="os1_<?php echo $eCart1_Index+1; ?>" value="<?php echo $eCart1->DisplayInfo("EmbroideryStyle"); ?>" />
<input type="hidden" name="on2_<?php echo $eCart1_Index+1; ?>" id="on2_<?php echo $eCart1_Index+1; ?>" value="Your Letters:" />
<input type="hidden" name="os2_<?php echo $eCart1_Index+1; ?>" id="os2_<?php echo $eCart1_Index+1; ?>" value="<?php echo $eCart1->DisplayInfo("EmbroideryText"); ?>" />
<input type="hidden" name="on3_<?php echo $eCart1_Index+1; ?>" id="on3_<?php echo $eCart1_Index+1; ?>" value="Special Request:" />
<input type="hidden" name="os3_<?php echo $eCart1_Index+1; ?>" id="os3_<?php echo $eCart1_Index+1; ?>" value="<?php echo $eCart1->DisplayInfo("SpecialRequest"); ?>" />

Now the options are being listed in the PayPal Sandbox Review Order details (options-bn.jpg attached) and are also listed in the PayPal email to both customer and seller. But still not on the checkout_success screen. Both the options and the item name are missing.

I updated the variable names in the checkout_success code to match those on the confirm page. I tried adding your code below in various places (after paypal php, before paypal php, before doctype) but just caused undefined variable error along with error messages about the undefined index items (checkout_success_1.jpg)

Sign in to reply to this post

Jason ByrnesWebAssist

did you try using this code to dump the $keyarray:

php:
<?php 

echo("<pre>"); 
var_dump($keyarray); 
echo(
"</pre>"); 
?>




this will tell you all of the available variables being passed from payapl.

Sign in to reply to this post

toni272059

Yes I used it. BUT did not know where it was supposed to go!
checkout_success.php
Tried three different places, before paypal php code, after it, and also before the doctype.
Each time would get same error about undefined variable

Sign in to reply to this post

Jason ByrnesWebAssist

it should go after the paypal code.


your going to continue to get the undefined variable error untill you find out the correct variables names to use.

the code i gave will out put all of the variables that paypal passes over, it will show you what variable names Can be used.

Sign in to reply to this post

toni272059

Follows returned content on checkout_success page

Thank you for your payment. Your transaction has been completed, and a receipt for your purchase has been emailed to you. You may log into your account at us to view details of this transaction.

Notice: Undefined variable: header in /home/content/19/8636319/html/TEST/checkout_success.php on line 122

Notice: Undefined offset: 1 in /home/content/19/8636319/html/TEST/checkout_success.php on line 153

Notice: Undefined index: item_name in /home/content/19/8636319/html/TEST/checkout_success.php on line 165

Notice: Undefined index: os0 in /home/content/19/8636319/html/TEST/checkout_success.php on line 168

Notice: Undefined index: os1 in /home/content/19/8636319/html/TEST/checkout_success.php on line 169

Notice: Undefined index: os2 in /home/content/19/8636319/html/TEST/checkout_success.php on line 170

Notice: Undefined index: os3 in /home/content/19/8636319/html/TEST/checkout_success.php on line 171

Thank you for your purchase!

Payment Details
Name: Toni Mills
Item:
Amount: 151.35

Embroidery Details if selected
Embroidery Type:
Embroidery Style:
Embroidery Text:
Special Request:

array(51) {
["mc_gross"]=>string(6) "151.35"
["protection_eligibility"]=>string(29) "Partially Eligible - INR Only"
["address_status"]=>string(11) "unconfirmed"
["item_number1"]=>string(1) "5"
["tax"]=>string(4) "0.00"
["payer_id"]=>string(13) "LJXZNNDC28YBC"
["address_street"]=>string(12) "4 porter Ave"
["payment_date"]=>string(25) "14:28:11 Jun 04, 2012 PDT"
["option_name2_1"]=>string(16) "Embroider Style:"
["option_selection1_1"]=>string(8) "Initials"
["payment_status"]=>string(9) "Completed"
["option_name4_1"]=>string(16) "Special Request:"
["option_selection3_1"]=>string(4) "TONI"
["charset"]=>string(12) "windows-1252"
["address_zip"]=>string(5) "02840"
["mc_shipping"]=>string(4) "0.00"
["mc_handling"]=>string(5) "16.35"
["first_name"]=> string(4) "Toni"
["mc_fee"]=>string(4) "4.69"
["address_country_code"]=>string(2) "US"
["address_name"]=>string(10) "Toni Mills"
["custom"]=>string(0) ""
["payer_status"]=>string(8) "verified"
["business"]=>string(29) "tonihm_1337810685_biz@cox.net"
["address_country"]=>string(13) "United States"
["num_cart_items"]=> string(1) "1"
["mc_handling1"]=>string(4) "0.00"
["address_city"]=>string(7) "Newport"
["payer_email"]=>string(29) "custom_1337778962_per@cox.net"
["mc_shipping1"]=>string(4) "0.00"
["tax1"]=>string(4) "0.00"
["option_name1_1"]=>string(16) "Embroidery Type:"
["option_name3_1"]=>string(13) "Your Letters:"
["txn_id"]=>string(17) "62514849RR281891C"
["payment_type"]=>string(7) "instant"
["option_selection2_1"]=>string(12) "Signal Flags"
["last_name"]=>string(5) "Mills"
["address_state"]=>string(2) "RI"
["item_name1"]=>string(17) "Shore Dinner Tote"
["receiver_email"]=>string(29) "tonihm_1337810685_biz@cox.net"
["payment_fee"]=>string(4) "4.69"
["option_selection4_1"]=>string(55) "Please use the signal flags for the letters. Thank you."
["quantity1"]=>string(1) "1"
["receiver_id"]=>string(13) "F6HX3ZEJEBP5U"
["txn_type"]=> string(4) "cart"
["mc_gross_1"]=>string(6) "135.00"
["mc_currency"]=>string(3) "USD"
["residence_country"]=>string(2) "US"
["transaction_subject"]=>string(30) "Shopping CartShore Dinner Tote"
["payment_gross"]=>string(6) "151.35"
[""]=>string(0) ""
}


Follows content for the various line errors

Line 122: $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
Line 153: list($key,$val) = explode("=", $lines[$i]);
Line 165: $itemname = $keyarray['item_name'];
Lines 168-171:
$embroiderytype = $keyarray['os0'];
$embroiderystyle = $keyarray['os1'];
$embroiderytext = $keyarray['os2'];
$specialrequest = $keyarray['os3'];

I tried changing 'os0' to 'option_selection1' but just came back with same error
Undefined index: option_selection1 in /home/content/19/8636319/html/TEST/checkout_success.php on line 168

Sign in to reply to this post

Jason ByrnesWebAssist

well, the item name variable is "item_name1"
["item_name1"]=>string(17) "Shore Dinner Tote"


the option name variables are "option_name1_1", "option_name2_1", "option_name3_1", and "option_name4_1";
["option_name1_1"]=>string(16) "Embroidery Type:"
["option_name2_1"]=>string(16) "Embroider Style:"
["option_name3_1"]=>string(13) "Your Letters:"
["option_name4_1"]=>string(16) "Special Request:"

and the option value variables are "option_selection1_1", "option_selection2_1", "option_selection3_1", and "option_selection4_1":
["option_selection1_1"]=>string(8) "Initials"
["option_selection2_1"]=>string(12) "Signal Flags"
["option_selection3_1"]=>string(4) "TONI"
["option_selection4_1"]=>string(55) "Please use the signal flags for the letters. Thank you."


if there are more than one items in the cart, then there will be more variables for "item_name2", and the option name and value variables will be repeated as well changing the ending _1, to _2

Sign in to reply to this post

toni272059

I figured that. But still don't understand how that would work with multiple items purchased in one order.

I did another test, this time with three items in the cart. Abbreviated results are

["item_name1"]=> string(16) "Shore Dinner Set"
["item_name2"]=> string(21) "Long Bungee Dog Leash"
["item_name3"]=> string(33) "Court Tennis Racquet Bag - Single"

["option_name1_1"]=> string(16) "Embroidery Type:"
["option_name1_2"]=> string(16) "Embroidery Type:"
["option_name1_3"]=> string(16) "Embroidery Type:"

["option_selection1_1"]=> string(8) "Initials"
["option_selection1_2"]=> string(0) ""
["option_selection1_3"]=> string(9) "Word/Name"

["option_name2_1"]=> string(16) "Embroider Style:"
["option_name2_2"]=> string(16) "Embroider Style:"
["option_name2_3"]=> string(16) "Embroider Style:"

["option_selection2_1"]=> string(6) "Circle"
["option_selection2_2"]=> string(0) ""
["option_selection2_3"]=> string(5) "Greek"

["option_name3_1"]=> string(13) "Your Letters:"
["option_name3_2"]=> string(13) "Your Letters:"
["option_name3_3"]=> string(13) "Your Letters:"

["option_selection3_1"]=> string(8) "ITEM ONE"
["option_selection3_2"]=> string(0) ""
["option_selection3_3"]=> string(10) "GREEK NAME"

["option_name4_1"]=> string(16) "Special Request:"
["option_name4_2"]=> string(16) "Special Request:"
["option_name4_3"]=> string(16) "Special Request:"

["option_selection4_1"]=> string(29) "Item One Special Instructions"
["option_selection4_2"]=> string(0) ""
["option_selection4_3"]=> string(19) "Item 3 Special Inst"

HTML file with complete list attached.

Plus, PayPal's instructions are to use on0, os0, on1, os1, etc.
e_howto_html_Appx_websitestandard_htmlvariables

I have this on the Confirm page prior to going to PayPal

<p class="eC_ItemEmbroideryType">Embroidery Type: <span style="color:#C00;text-transform:uppercase"><input type="hidden" name="on0" value="<?php echo $eCart1->DisplayInfo("EmbroideryType"); ?>"><?php echo $eCart1->DisplayInfo("EmbroideryType"); ?></span></p>

<p class="eC_ItemEmbroideryStyle">Embroidery Style: <span style="color:#C00;text-transform:uppercase;"><input type="hidden" name="on1" value="<?php echo $eCart1->DisplayInfo("EmbroideryStyle"); ?>"><?php echo $eCart1->DisplayInfo("EmbroideryStyle"); ?></span></p>

<p class="eC_ItemEmbroideryText">Your Letters: <span style="color:#C00;text-transform:uppercase"><input type="hidden" name="on2" value="<?php echo $eCart1->DisplayInfo("EmbroideryText"); ?>"><?php echo $eCart1->DisplayInfo("EmbroideryText"); ?></span></p>

<p class="eC_ItemSpecialRequest">Special Request: <span style="color:#C00;"><input type="hidden" name="on3" value="<?php echo $eCart1->DisplayInfo("SpecialRequest"); ?>"><?php echo $eCart1->DisplayInfo("SpecialRequest"); ?></span></p>

Plus the eCart validation code listed in previous post (yesterday 8:16pm)

I have sent a request to PayPal support but they take a day or two to respond...

Have you/WebAssist/eCart had any experience with Host Merchant Services as a payment gateway?
www.hostmerchantservices.com/

Attached Files
Boomerang Needleworks thanks you for your order.html.zip
Sign in to reply to this post

Jason ByrnesWebAssist

you need to hand code logic that will look at the number of cart items:
["num_cart_items"]=> string(1) "1"


and then loop through to crate the correct number of variables.

if you need further assistance in creating this, I would suggest signing up for a premiere support appointment where we will work with you one on one.

Sign in to reply to this post
loading

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