dezkit Posted June 14, 2008 Share Posted June 14, 2008 is it possible so that when you fill out a form, example: <form action=""> <table border=0><tr> <td>First Name: <td><input type="text" name="fname"> <tr> <td>Last Name: <td><input type="text" name="lname"> <tr> <td>SteamID: <td><input type="text" name="steamid"> <tr> <td vALIGN="top">Type of admin: <td> <input type="radio" name="admin" value="5"> 5 Dollar Admin <br> <input type="radio" name="admin" value="10"> 10 Dollar Admin <br> <input type="radio" name="admin" value="15"> 15 Dollar Admin <br> <input type="radio" name="admin" value="20"> 20 Dollar Admin <tr> <td colspan="2" align="right"><input type="submit" value="BUY NOW"> </table> </form> it goes to a paypal page, you pay for it, and the results (fname, lname, steamid, and admin) get emailed to me. Link to comment https://forums.phpfreaks.com/topic/110250-php-paypal-php-mail/ Share on other sites More sharing options...
dezkit Posted June 15, 2008 Author Share Posted June 15, 2008 new code: (cant edit first post) <font size="+1">Admin Order Form </font><br> <form> <table> <tr> <td align="right">Username: <td><input type="text" name="username" size="13"> <tr> <td align="right">SteamID: <td><input type="text" name="steamid" size="13"> <tr> <td vALIGN="top" align="right">Type: <td> <input type="radio" name="admin" value="5"> 5 Dollar Admin <br> <input type="radio" name="admin" value="10"> 10 Dollar Admin <br> <input type="radio" name="admin" value="15"> 15 Dollar Admin <tr> <td colspan=2 align=right> <input type="reset" value="RESET"> <input type="submit" value="BUY NOW"> </table> </form> <br> Secure transactions with <a href="http://www.paypal.com">PayPal</a> Link to comment https://forums.phpfreaks.com/topic/110250-php-paypal-php-mail/#findComment-565709 Share on other sites More sharing options...
dezkit Posted June 15, 2008 Author Share Posted June 15, 2008 bump before i go to sleep, please people, any information will do very good to me! Link to comment https://forums.phpfreaks.com/topic/110250-php-paypal-php-mail/#findComment-565737 Share on other sites More sharing options...
MasterACE14 Posted June 15, 2008 Share Posted June 15, 2008 What your after is a IPN(instant payment notification) script. Here's the one I use(heavily commented): <?php // this is the function that will do everything if the payment has been successful, in here you can do whatever you need to // you give your players there Supporter Status goods and can e-mail yourself the results of the transaction if you like // Standard Supporter Status Function function standard_supporterstatus($id) { // put your mysql database details in here $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } // put your database name here mysql_select_db("databasename", $con); // here you select the user table, and grab all the players information and put them in common variables // ---> Select Variables <--- $result = mysql_query("SELECT * FROM `user_table` WHERE id='" . $id . "' "); $tmparr = mysql_fetch_array($result); $player_authlevel = $tmparr["authlevel"]; $player_bank = $tmparr["bank"]; $player_currentexp = $tmparr["currentexp"]; $player_strength = $tmparr["strength"]; $player_agility = $tmparr["agility"]; $player_intelligence = $tmparr["intelligence"]; // here you give the player his goods, by using the common variables above you can then add/subtract/times/divide or alter anything in there database // such as the money they have in there bank $bank = $player_bank+50000; $currentexp = $player_currentexp+10000; $strength = $player_strength+5; $agility = $player_agility+5; $intelligence= $player_intelligence+5; // here you check if they already have purchased Ultimate Supporter Status, or Standard. And change there Authority level in the database accordingly if($player_authlevel == 2) { $authlevel = 2; } else { $authlevel = 1; } // now you update the players stats with the variables above, using this mysql UPDATE query // update player stats mysql_query("UPDATE `cf_users` SET `bank`='$bank',`currentexp`='$currentexp',`strength`='$strength',`agility`='$agility',`intelligence`='$intelligence',`authlevel`='$authlevel',`ammo`=`ammo`+'1000',`tcf_time`=`tcf_time`+'48',`tcf_check`='1' WHERE `id`='" . $id . "'"); mysql_query("UPDATE `cf_users` SET `strikeaction` = `strikeaction`+`level`+(`strength`*5000),`covertaction` = `covertaction`+`level`+(`intelligence`*5000),`defenceaction` = `defenceaction`+`level`+(`agility`*5000) WHERE `id`='" . $id . "'"); // now get the players id from the paypal transaction in the 'custom' field $player_id = $id; // now get the info ready to put into there Attack log or where ever you want, just to let them know there Supporter Status purchase was successful $log_type = "Supporter Status"; $importance = "Normal"; $time = time() + (18 * 60 * 60); // put your Admin username/alias here so they know who gave them the supporter status... $player_username = "ACE"; // put your message in here which will go into the attack log or you could also put this into there messages if you wish $message = "<center><font color=\"yellow\">Thankyou for purchasing Supporter Status!<br>"; $message.= "I hope it brings you Power and Glory!<br><br>"; $message.= "Regards ACE</font></center>"; // now use a mysql INSERT query to give them the attack log( log of the purchase's success ) // update player log @mysql_query("INSERT INTO `cf_log` (player,player_id,type,importance,time,message) VALUES ('$player_username','$player_id','$log_type','$importance','$time','$message')") or die('Query:<br /> Updating your log <br /><br />Error:<br />' . mysql_error()); } /////////////////////////////////////////////////// /////////////Begin IPN Script below.///////////////// ////////////////////////////////////////////////// // this can be any e-mail, this will be the e-mail the transaction details are sent to // set this to your e-mail address: $email = "[email protected]"; // now edit what ever you need to for the e-mail stuff between lines 222 and 239, don't touch anything else // YOU DONT NEED TO ALTER ANYTHING BELOW THIS LINE, EVERYTHING BELOW THIS LINE IS THE IPN SCRIPT AND HANDLES // THE ENTIRE PAYPAL TRANSACTION function doTheCurl () { $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } $ch = curl_init(); // check to see if this is sandbox or not if ($_POST["test_ipn"] == 1) { curl_setopt($ch, CURLOPT_URL, "https://www.sandbox.paypal.com/cgi-bin/webscr"); } else { curl_setopt($ch, CURLOPT_URL, "https://www.paypal.com/cgi-bin/webscr"); } curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $req); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); $fp = curl_exec ($ch); curl_close($ch); return $fp; } function doTheHttp () { $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // 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"; // check to see if this is sandbox or not. if ($_POST["test_ipn"] == 1) { $fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30); } else { $fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30); } if (!$fp) { return "ERROR"; } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { return "VERIFIED"; } else if (strcmp ($res, "INVALID") == 0) { return "INVALID"; } } fclose ($fp); } return "ERROR"; } function doEmail ($title,$email) { $alsomail = "$title\n\n----HTTP POST VARS----\n\n"; foreach ($_POST as $key => $value) { $alsomail .= "$key = $value \n\n"; } foreach($_GET as $kee => $val) { $gets .= "$kee = $val \n\n"; } mail($email,$title,$alsomail . "\n\n get values \n\n" . $gets); } /* now with both of those functions defined, you can run a simple check to get back your responce: */ $fp = doTheCurl(); if (!$fp) { // doEmail("cURL ERROR, SWITCHING TO HTTP",$email); $fp = doTheHttp(); } $res = $fp; /* and after that, you can check to see if $res is invalid or verified */ if (strcmp ($res, "VERIFIED") == 0) { /* log stuff into your database here! Also, it's a good idea to send yourself an e-mail with all _POST params, just so you know what's going on. The e-mail code is here, the database code is not. */ doEmail("PayPal Purchase Success",$email); // e-mail the person their password $to = $email; $subject = "Standard Supporter Status"; // message $message = $_POST["custom"]; $message .= ' has purchased Standard Supporter Status'; // headers $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html;"; $headers .= " charset=iso-8859-1\r\n"; $headers .= "From: [email protected] \r\n"; mail($to, $subject, $message, $headers); standard_supporterstatus($_POST["custom"]); } else if (strcmp ($res, "INVALID") == 0) { /* here i send myself an e-mail saying there's been an invalid with all of the details sent to me from ipn. that way i have a record of it. */ doEmail("INVALID PayPal Purchase!!",$email); } else { /* here i send myself an e-mail saying there has been a fatal error - if the paypal server goes down this will happen? doesn't seem likely but it's always good to have some backup just incase. I also place all data sent from IPN in this e-mail so I have record of it. This can also happen with an HTTP error - just a note */ doEmail("Error in IPN Code - Normally HTTP Error",$email); } ?> It also has a section there for updating a database if you want. Otherwise you can just remove that, and just do the e-mail. and here's the form that posts to that PHP page: <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="notify_url" value="http://www.yourwebsite.com.au/purchase_standard.php"> <input type="hidden" name="return_url" value="http://www.yourwebsite.com.au/purchase_standard.php"> <input type="hidden" name="rm" value="2"> <input type="hidden" name="business" value="[email protected]"> <input type="hidden" name="item_name" value="cake"> <input type="hidden" name="item_number" value="1"> <input type="hidden" name="amount" value="10.00"> <input type="hidden" name="custom" value="<?php echo $player['id']; ?>"> <input type="hidden" name="no_shipping" value="1"> <input type="hidden" name="no_note" value="1"> <input type="hidden" name="return" value="http://www.yourwebsite.com.au/supporterstatus.php"> <input type="hidden" name="cancel_return" value="http://www.yourwebsite.com.au/supporterstatus.php"> <input type="hidden" name="currency_code" value="AUD"> <input type="hidden" name="lc" value="AU"> <input type="hidden" name="bn" value="PP-BuyNowBF"> <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but01.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> <img alt="" border="0" src="https://www.paypal.com/en_AU/i/scr/pixel.gif" width="1" height="1"> </form> hope this helps. Regards ACE Link to comment https://forums.phpfreaks.com/topic/110250-php-paypal-php-mail/#findComment-565834 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.