php - How to dispay previous orders made via PayPal for each customer -
i doing graduation project e-commerce website http://www.fieldhockey-world.co.uk , want user able see previous orders made via paypal. manage integrate paypal trying create foreignkey users table transactions table cant info because users redirected paypal website purchase goods. database tables follow: transactions table
id int(11) pk product_id_array varchar(255) payer_email varchar(255) first_name varchar(255) last_name varchar(255) payment_date varchar(255) mc_gross varchar(255) payment_currency varchar(255) txn_id varchar(255) unique receiver_email varchar(255) payment_type varchar(255) payment_status varchar(255) txn_type varchar(255) payer_status varchar(255) address_street varchar(255) address_city varchar(255) address_state varchar(255) address_zip varchar(255) address_country varchar(255) address_status varchar(255) notify_version varchar(255) verify_sign varchar(255) payer_id varchar(255) mc_currency varchar(255) mc_fee varchar(255)**
users table
user_id int(11) pk username varchar(32) password varchar(32) first_name varchar(32) last_name varchar(32) email varchar(80) unique email_code varchar(32) active int(11) type int(11**)** date_of_birth date street_address varchar(80) city varchar(80) post_code varchar(6)
if have ideas please allow me know. indeed!
my_ipn code
<?php // check see there posted variables coming script if ($_server['request_method'] != "post") die ("no post variables"); // initialize $req variable , add together cmd key value pair $req = 'cmd=_notify-validate'; // read post paypal foreach ($_post $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // post of paypal's server using curl, , validate paypal // utilize curl instead of php more universally operable script (fsockopen has issues on environments) //$url = "https://www.sandbox.paypal.com/cgi-bin/webscr"; $url = "https://www.paypal.com/cgi-bin/webscr"; $curl_result=$curl_err=''; $ch = curl_init(); curl_setopt($ch, curlopt_url,$url); curl_setopt($ch, curlopt_returntransfer,1); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, $req); curl_setopt($ch, curlopt_httpheader, array("content-type: application/x-www-form-urlencoded", "content-length: " . strlen($req))); curl_setopt($ch, curlopt_header , 0); curl_setopt($ch, curlopt_verbose, 1); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_timeout, 30); $curl_result = @curl_exec($ch); $curl_err = curl_error($ch); curl_close($ch); $req = str_replace("&", "\n", $req); // create nice list in case want email ourselves reporting // check result verifies if (strpos($curl_result, "verified") !== false) { $req .= "\n\npaypal verified ok"; } else { $req .= "\n\ndata not verified paypal!"; mail("bogomilpavlov@yahoo.com", "ipn interaction not verified", "$req", "from: bogomilpavlov@yahoo.com" ); exit(); } $txn_id = $_post['txn_id']; $payer_email = $_post['payer_email']; $custom = $_post['custom']; $first_name = $_post['first_name']; $last_name = $_post['last_name']; $payment_date = $_post['payment_date']; $mc_gross = $_post['mc_gross']; $payment_currency = $_post['payment_currency']; $payment_type = $_post['payment_type']; $payment_status = $_post['payment_status']; $txn_type = $_post['txn_type']; $payer_status = $_post['payer_status']; $address_street = $_post['address_street']; $address_city = $_post['address_city']; $address_state = $_post['address_state']; $address_zip = $_post['address_zip']; $address_country = $_post['address_country']; $address_status = $_post['address_status']; $notify_version = $_post['notify_version']; $verify_sign = $_post['verify_sign']; $payer_id = $_post['payer_id']; $mc_currency = $_post['mc_currency']; $mc_fee = $_post['mc_fee']; // place transaction database $sql = mysql_query("insert transactions (product_id_array, payer_email, first_name, last_name, payment_date, mc_gross, payment_currency, txn_id, receiver_email, payment_type, payment_status, txn_type, payer_status, address_street, address_city, address_state, address_zip, address_country, address_status, notify_version, verify_sign, payer_id, mc_currency, mc_fee) values('$custom','$payer_email','$first_name','$last_name','$payment_date','$mc_gross','$payment_currency','$txn_id','$receiver_email','$payment_type','$payment_status','$txn_type','$payer_status','$address_street','$address_city','$address_state','$address_zip','$address_country','$address_status','$notify_version','$verify_sign','$payer_id','$mc_currency','$mc_fee')") or die ("unable execute query"); mysql_close(); // mail service details mail("bogomilpavlov93@gmail.com", "normal ipn result!", $req, "from: bogomilpavlov@yahoo.com"); ?> cart code
<?php // connect mysql database include("storescripts/init.php"); protect_page(); include("includes/template_head.php"); session_start(); // start session first thing in script // script error reporting (cart error!!!!) //error_reporting(e_all); //ini_set('display_errors', '1'); ?> <?php //section 1 (if user attempts add together cart product page) if (isset($_post['pid'])) { $pid = $_post['pid']; $wasfound = false; $i = 0; // if cart session variable not set or cart array empty if (!isset($_session["cart_array"]) || count($_session["cart_array"]) < 1) { // run if cart empty or not set $_session["cart_array"] = array(0 => array("item_id" => $pid, "quantity" => 1)); } else { // run if cart has @ to the lowest degree 1 item in foreach ($_session["cart_array"] $each_item) { $i++; while (list($key, $value) = each($each_item)) { if ($key == "item_id" && $value == $pid) { // item in cart let's adjust quantity using array_splice() array_splice($_session["cart_array"], $i-1, 1, array(array("item_id" => $pid, "quantity" => $each_item['quantity'] + 1))); $wasfound = true; } // close if status } // close while loop } // close foreach loop if ($wasfound == false) { array_push($_session["cart_array"], array("item_id" => $pid, "quantity" => 1)); } } //header("location: cart.php"); } ?> <?php //section 2 (if user chooses empty shopping cart) if (isset($_get['cmd']) && $_get['cmd'] == "emptycart") { unset($_session["cart_array"]); } ?> <?php //section 3 (if user chooses adjust item quantity) if (isset($_post['item_to_adjust']) && $_post['item_to_adjust'] != "") { // execute code $item_to_adjust = $_post['item_to_adjust']; $quantity = $_post['quantity']; $quantity = preg_replace('#[^0-9]#i', '', $quantity); // filter numbers if ($quantity >= 100) { $quantity = 99; } if ($quantity < 1) { $quantity = 1; } if ($quantity == "") { $quantity = 1; } $i = 0; foreach ($_session["cart_array"] $each_item) { $i++; while (list($key, $value) = each($each_item)) { if ($key == "item_id" && $value == $item_to_adjust) { // item in cart let's adjust quantity using array_splice() array_splice($_session["cart_array"], $i-1, 1, array(array("item_id" => $item_to_adjust, "quantity" => $quantity))); } // close if status } // close while loop } // close foreach loop } ?> <?php //section 4 (if user wants remove item cart) if (isset($_post['index_to_remove']) && $_post['index_to_remove'] != "") { // access array , run code remove array index $key_to_remove = $_post['index_to_remove']; if (count($_session["cart_array"]) <= 1) { unset($_session["cart_array"]); } else { unset($_session["cart_array"]["$key_to_remove"]); sort($_session["cart_array"]); } } ?> <?php //section 5 (render cart user view on page) $cartoutput = ""; $carttotal = ""; global $carttotal; $pp_checkout_btn = ''; $product_id_array = ''; if (!isset($_session["cart_array"]) || count($_session["cart_array"]) < 1) { $cartoutput = "<h2 align='center'>your shopping cart empty</h2>"; } else { // start each loop $pp_checkout_btn .= '<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="business" value="bogomilpavlov@yahoo.com">'; $i = 0; foreach ($_session["cart_array"] $each_item) { $item_id = $each_item['item_id']; $sql = mysql_query("select * products id='$item_id' limit 1"); while ($row = mysql_fetch_array($sql)) { $product_name = $row["product_name"]; $price = $row["price"]; $details = $row["details"]; } $pricetotal = $price * $each_item['quantity']; $carttotal = $pricetotal + $carttotal; $pricetotal = money_format("%10.2n", $pricetotal); // dynamic checkout buttom assembly $x = $i + 1; $pp_checkout_btn .= '<input type="hidden" name="item_name_' . $x . '" value="' . $product_name . '"> <input type="hidden" name="amount_' . $x . '" value="' . $price . '"> <input type="hidden" name="quantity_' . $x . '" value="' . $each_item['quantity'] . '"> '; // create product array variable $product_id_array .= "$item_id-".$each_item['quantity'].","; // dynamic table row assembly $cartoutput .= "<tr>"; $cartoutput .= '<td align="center" bgcolor="#f9f9f9"><a href="product.php?id=' . $item_id . '">' . $product_name . '</a><br /><img src="inventory_images/' . $item_id . '.jpg" alt="' . $product_name. '" width="100" height="80" border="1" align="center" /></td>'; $cartoutput .= '<td bgcolor="#f9f9f9">' . $details . '</td>'; $cartoutput .= '<td bgcolor="#f9f9f9">£' . $price . '</td>'; $cartoutput .= '<td bgcolor="#f9f9f9"><form action="cart.php" method="post"> <input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" /> <input name="adjustbtn' . $item_id . '" type="submit" value="change" /> <input name="item_to_adjust" type="hidden" value="' . $item_id . '" /> </form></td>'; ; $cartoutput .= '<td bgcolor="#f9f9f9">£' . $pricetotal . '</td>'; $cartoutput .= '<td bgcolor="#f9f9f9"><form action="cart.php" method="post"><input name="deletebtn' . $item_id . '" type="submit" value="x" /><input name="index_to_remove" type="hidden" value="' . $i . '" /></form></td>'; $cartoutput .= '</tr>'; $i++; } $carttotal = money_format("%10.2n", $carttotal); //finish paypal checkout scheme $pp_checkout_btn .= '<input type="hidden" name="custom" value="' . $product_id_array . '"> <input type="hidden" name="notify_url" value="https://www.fieldhockey-world.co.uk/storescripts/my_ipn.php"> <input type="hidden" name="return" value="https://www.fieldhockey-world.co.uk/checkout_complete.php"> <input type="hidden" name="rm" value="2"> <input type="hidden" name="cbt" value="return store"> <input type="hidden" name="cancel_return" value="https://www.fieldhockey-world.co.uk/paypal_cancel.php"> <input type="hidden" name="lc" value="gb"> <input type="hidden" name="currency_code" value="gbp"> <input type="image" src="https://www.paypalobjects.com/en_us/i/btn/x-click-but6.gif" name="submit" alt="make payments paypal - it\'s fast, free , secure!" > </form>'; } ?> it bit long have...
php mysql paypal
No comments:
Post a Comment