Jump to content

Paypal Pro Hosted Integration:


roldahayes
Go to solution Solved by mac_gyver,

Recommended Posts

Hi, I am integrating Paypal Pro into my checkout and struggling to get it to work correctly.

 

I am using this code to connect to paypal - which all works correctly, processes payments as it should and send paypal receipts to the customer and to me.

 

The problem is that when Paypal redirects back to my receipt page, it is not triggering the email (customer_mail_new.php and client_mail_new.php) to tell me what exactly they customer has ordered!

 

I've been staring at this code for hours now and wonder if anyone can see anything obvious that I have (or haven't) done that is causing the emails to not send at the end of the receipt page?

 

(paypal.php)

<?php  //include header codeinclude_once("func_lib.php"); // use the user_connection include file's connectDB functioninclude_once("usr_conn.php");if(!connectDB()){echo "<p>Unable To Connect To Database</p>";return;}  // assign variables$currency = "£"; //get confirmation or customerID etc$shopperID = stripslashes($_POST['Shopper_ID']);$userID = stripslashes($_POST['User_ID']); //check that the order has not alerady been sentif (isset ($_COOKIE['order'])){$message = "Your order has already been processed";$blnSet = "1";} // select the userID's basket query and the Product Reference relating to each of the basket's productID's $sqlquery = "SELECT * FROM basket INNER JOIN products ON basket.productID = products.Prod_ID WHERE ((basket.userID) = '" . $userID . "')";$baskresult = mysql_query($sqlquery); $rowCount = mysql_num_rows($baskresult);  //set counter to name each hidden form element for the product details$frmCount = 1;    while ($row = mysql_fetch_assoc($baskresult)){ $strLength = strlen ($row["Prod_Type"]);$strPrefix = substr($row["Prod_Type"], 0, 2);$strSuffix = substr($row["Prod_Type"], 2, $strLength); switch ($strPrefix) {     case "BH": $strProdType = "Vehicle Accessory"; break; case "DG": $strProdType = "Dog Guard"; break;case "RB": $strProdType = "Vehicle Accessory"; break;case "XD": $strProdType = "General Accessory"; break;case "XL": $strProdType = "General Accessory"; break;case "WG": $strProdType = "Window Grille"; break;case "BT": $strProdType = "Boot Rack"; break;case "BR": $strProdType = "Bike Rack"; break;case "LB": $strProdType = "Roof Bar"; break;case "LR": $strProdType = "Roof Rack"; break;case "SK": $strProdType = "Ski Rack"; break;case "VR": $strProdType = "Van Racking"; break;default: $strProdType = "The product type for this item could not be found"; }  $bob = number_format(calcVAT(htmlspecialchars($row['Price_ExVat'])), 2); $mail_body .= "\nCar".$frmCount."_Make = ". htmlspecialchars($row['Car_Make']);$mail_body .= "\nCar".$frmCount."_Model = ". htmlspecialchars($row['Car_Model']);$mail_body .= "\nProduct".$frmCount."_Make = ". htmlspecialchars($row['Prod_Make']);$mail_body .= "\nProduct".$frmCount."_Model = ". htmlspecialchars($row['Prod_Model']);$mail_body .= "\nProduct".$frmCount."_Type = ". $strProdType;$mail_body .= "\nProduct".$frmCount."_REF = ". $row['Prod_REF'];$mail_body .= "\nProduct".$frmCount."_Quantity = ". htmlspecialchars($row['quantity']);$mail_body .= "\nProduct".$frmCount."_Price = ". $bob ."\n"; $frmCount ++; } $customer = array("Customer_Title", "Customer_Name", "Customer_Surname", "Business_name", "Customer_Address1", "Customer_Address2", "Customer_Address3", "Customer_Town", "Customer_County",  "Customer_Postcode", "Customer_Email", "Customer_Tel", "Customer_Mobile");$delivery = array("Delivery_Title", "Delivery_Firstname", "Delivery_Surname", "Delivery_Businessname", "Delivery_Address1", "Delivery_Address2", "Delivery_Address3", "Delivery_Town", "Delivery_County", "Delivery_Postcode", "Delivery_Country", "Delivery_Instructions");$search = array("Search_Engine"); foreach($customer as $val) { if($_POST[$val]) { $Customer_Address[] = "$val = ".$_POST[$val]; } }foreach($delivery as $val) { if($_POST[$val]) { $Delivery_Address[] = "$val = ".$_POST[$val]; } }foreach($search as $val) { if($_POST[$val]) { $Search_Engine[] = "$val = ".$_POST[$val]; } } if($_POST['Customer_Title']) { $CustomerName[] = $_POST['Customer_Title']; }if($_POST['Customer_Name']) { $CustomerName[] = $_POST['Customer_Name']; }if($_POST['Customer_Surname']) { $CustomerName[] = $_POST['Customer_Surname']; } @mysql_query("UPDATE shopper SET Customer_Address='".implode("\n",$Customer_Address)."', Delivery_Address='".implode("\n",$Delivery_Address)."', Search_Engine='".implode("\n",$Search_Engine)."', Shopping_Basket='". addslashes($mail_body) ."' WHERE User_ID='$userID'");?><form style="display:none" target="hss_iframe" name="form_iframe" action="https://securepayments.sandbox.paypal.com/acquiringweb" method="post">            <!-- Required -->        <input type="hidden" name="cmd" value="_hosted-payment">        <input type="hidden" name="template" value="TemplateA" />        <input type="hidden" name="business" value="Email Address Here"/>        <input type="hidden" name="paymentaction" value="sale" />        <input type="hidden" name="subtotal" value="<?= $_POST["Total_Price"] ?>" />        <input type="hidden" name="showShippingAddress" value="false" />         <input type="hidden" name="showBillingAddress" value="false" />    <input type="hidden" name="billing_first_name" value="<?= $_POST["Customer_Name"] ?>" />   <input type="hidden" name="billing_last_name" value="<?= $_POST["Customer_Surname"] ?>" />        <input type="hidden" name="billing_address1" value="<?= $_POST["Customer_Address1"] ?>" />        <input type="hidden" name="billing_address2" value="<?= $_POST["Customer_Address2"] ?>" />        <input type="hidden" name="billing_city" value="<?= $_POST["Customer_Town"] ?>" /><input type="hidden" name="billing_province" value="<?= $_POST["Customer_County"] ?>" /><input type="hidden" name="billing_zip" value="<?= $_POST["Customer_Postcode"] ?>" />      <input type="hidden" name="billing_country" value="GB" />        <input type="hidden" name="night_phone_b" value="<?= $_POST["Customer_Tel"] ?>" />   <input type="hidden" name="buyer_email" value="<?= $_POST["Customer_Email"] ?>" />        <input type="hidden" name="first_name" value="<?= $_POST["Delivery_Firstname"] ?>" />         <input type="hidden" name="last_name" value="<?= $_POST["Delivery_Surname"] ?>" />        <input type="hidden" name="address1" value="<?= $_POST["Delivery_Address1"] ?>" />        <input type="hidden" name="address2" value="<?= $_POST["Delivery_Address2"] ?>" /><input type="hidden" name="city" value="<?= $_POST["Delivery_Town"] ?>" /><input type="hidden" name="province" value="<?= $_POST["Delivery_County"] ?>" /><input type="hidden" name="zip" value="<?= $_POST["Delivery_Postcode"] ?>" />        <input type="hidden" name="note" value="<?= $_POST["Delivery_Instructions"] ?>" /><input type="hidden" name="country" value="GB" />        <input type="hidden" name="currency_code" value="GBP" />  <!-- by default USD -->        <input type="hidden" name="showHostedThankyouPage" value="true" />        <input type="hidden" name="cancel_return" value="http://mydomain.com/" />        <input type="hidden" name="custom" value="<?= $userID ?>" />        <input type="hidden" name="return" value="https://www.mydomain.com/upload/order_receipt.php" />        <input type="hidden" name="notify_url" value="https://mydomain.co.uk/upload/ipn.php" /> <!-- URL for IPN! -->         <input type="image" src="https://www.paypal.com/en_GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit"/>        <img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1"/></form><script type="text/javascript">    document.form_iframe.submit();</script></body></html>   

 

 

(order_receipt.php)

 <?php//include header code//include_once("head.php");//include header codeinclude_once("func_lib.php"); // use the user_connection include file's connectDB functioninclude_once("usr_conn.php");if(!connectDB()){echo "<p>Unable To Connect To Database</p>";return;}// assign variables$currency = "£"; //get confirmation or customerID etc$userID = stripslashes(($_COOKIE['userID'] ? $_COOKIE['userID'] : str_replace("AR_", "", $_GET["oid"])));$shopperID = stripslashes(substr($userID, 0, 6)); $token = md5(uniqid(rand(),1));setcookie("userID", $token, time() + 3600, "/");setcookie("userID", $token, time() + 3600, "/upload/");//echo "userID = ".$_COOKIE['userID']; //get the user details$result = mysql_query("SELECT * FROM shopper WHERE User_ID='$userID'");$UserDetails = mysql_fetch_assoc($result); $custdetails = explode("\n",$UserDetails["Customer_Address"]);foreach($custdetails as $value) {if(strpos($value,"Customer_Email") !== false) { $Customer_Email = str_replace("Customer_Email = ", "", $value); }} //check that the order has not alerady been sentif (isset ($_COOKIE['order'])){$message = "Your order has already been processed";$blnSet = "1"; } ?>   <?php  //get info from shopper table$sqlquery = "SELECT * FROM shopper WHERE user_ID = '" . $userID . "'";$result = mysql_query($sqlquery);echo '<!--'.mysql_error() .'-->';$rowCount = mysql_num_rows($result);echo'<!--test-->';// if no matches then nothing to checkoutif ($rowCount == 0){echo'<!--in-->';echo ("<p><font class=error>Your basket was empty. You have come to this page in error!!<br>Please return to the main site</font></p>");return;}else{ //store shopper details$shoprow = mysql_fetch_assoc($result);$Basket_total = number_format(htmlspecialchars($shoprow['Basket_total']), 2);$Post_type = htmlspecialchars($shoprow['Postage']);//echo "tot: " . $Basket_total;$Postage = htmlspecialchars($shoprow['Postage']);//get basket details$sqlquery = "SELECT * FROM basket WHERE userID = '" . $userID . "'";$result = mysql_query($sqlquery);$rowCount = mysql_num_rows($result);if ($rowCount == 0){echo "<font class=error><p>Error: Your basket was empty.</p></font>";return;}else{// select the userID's basket query and the Product Reference relating to each of the basket's productID's$sqlquery = "SELECT * FROM basket INNER JOIN products ON basket.productID = products.Prod_ID WHERE ((basket.userID) = '" . $userID . "')";//echo $sqlquery;$baskresult = mysql_query($sqlquery);$rowCount = mysql_num_rows($baskresult); //set counter to name each hidden form element for the product details$frmCount = 1; while ($row = mysql_fetch_assoc($baskresult)){ //cut the prod_type variable//get the length of the variable$strLength = strlen ($row["Prod_Type"]);//assign first 2 characters of variable$strPrefix = substr($row["Prod_Type"], 0, 2);//debug//echo "\n prefix :" . $strPrefix;//assign remaining characters of variable$strSuffix = substr($row["Prod_Type"], 2, $strLength);//debug//echo "\n suffix :" . $strSuffix; //set product header image depending on the Prod_Type Code//start the table row$strProdType = prodType ($strPrefix);  echo("<tr class=stdtable><td align=center> " . htmlspecialchars($row['Car_Make']) . " " . "</td>");echo("<td align=center> " . $strProdType . " " . "</td>");echo("<td align=center> " . htmlspecialchars($row['Prod_Make']) . "<br>" . htmlspecialchars($row['Product_Desc']) . "</td>");echo("<td align=center> " . htmlspecialchars($row['Prod_REF']) . " " . "</td>");echo("<td align=center>". htmlspecialchars($row['quantity']) ."</td></tr>");//create hidden form names and values containing product detailsecho "<input type=hidden name=Product".$frmCount."_Make value=\"". htmlspecialchars($row['Prod_Make']) ."\">";echo "<input type=hidden name=Product".$frmCount."_Model value=\"". htmlspecialchars($row['Prod_Model']) ."\">";echo "<input type=hidden name=Product".$frmCount."_Type value=\"". $strProdType ."\">";echo "<input type=hidden name=Product".$frmCount."_REF value=\"". $row['Prod_REF'] ."\">";echo "<input type=hidden name=Product".$frmCount."_Quantity value=\"". htmlspecialchars($row['quantity']) ."\">";//incrementcount by 1$frmCount ++;}//end while echo("<tr class=stdtable><td colspan=3> </td><td align=center><b>TOTAL</b></td><td align=center>" . $currency . $Basket_total . "</td></tr>"); }//end else}//end else?>                                                  Number = <?php echo $shopperID; ?> </td>                       <?php //create messsage based on whether mail was sent or not if ($UserDetails["Success"] == 1) echo ("Your order has been placed successfully. We will email or call you shortly confirming your details. <br><br>Thank you for visiting."); else echo ("<span style=\"color:#c00; font-size:1.4em;\">Unfortunately there has been an error sending your order. Please try again, or email us <a href=mailto:emailhere.co.uk>info@autorack.co.uk</a><br></span>");echo $message; ?>                         <?php //include footer code   if ($UserDetails["Success"] == 1){//finally send out a confirmation email to the customer, including their ShopperIDinclude_once("customer_mail_new.php");include_once("client_mail_new.php");}?>     <?php$blnSet = "";?> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.