Goose87 Posted December 2, 2007 Share Posted December 2, 2007 I have a php game, and I want people to be able to make payments via paypal. I then want some sort of automated system that will automatically give the user the items in the game that they've bought. I have tried looking everywhere, but no-one will tell me because they wnat to protec their games. Thanks, Goose. Quote Link to comment https://forums.phpfreaks.com/topic/79821-paypal-automated-payment-using-php/ Share on other sites More sharing options...
revraz Posted December 2, 2007 Share Posted December 2, 2007 Have you tried searching for "paypal and php" in Google? Quote Link to comment https://forums.phpfreaks.com/topic/79821-paypal-automated-payment-using-php/#findComment-404272 Share on other sites More sharing options...
ILYAS415 Posted December 2, 2007 Share Posted December 2, 2007 I am looking for an easy to use script. Mate what you need to be looking for is a php paypal ipn script. They can be really difficult to set up i have tried countlessly for my php game www.ragingmortals.com sorry ifim not allowed to post links mods i never actually read the rules properly Anyway i do have some php ipn scripts which arent mine and i can also get one of my friend who also owns a php game but his seems complicated because it uses 'switches' functions which im not familiar with. Quote Link to comment https://forums.phpfreaks.com/topic/79821-paypal-automated-payment-using-php/#findComment-404278 Share on other sites More sharing options...
Goose87 Posted December 2, 2007 Author Share Posted December 2, 2007 I've had a look at the paypal php ipn scripts. I dont think they are what I'm looking for. The one i found earlier and went through the code extensively, only produced an email for the user giving a password for the item, that's not what I want, I want the thing to access my database, and give the user some items in the game when the payment has been successful. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/79821-paypal-automated-payment-using-php/#findComment-404462 Share on other sites More sharing options...
cooldude832 Posted December 2, 2007 Share Posted December 2, 2007 I am looking for an easy to use script. Mate what you need to be looking for is a php paypal ipn script. They can be really difficult to set up i have tried countlessly for my php game www.ragingmortals.com sorry ifim not allowed to post links mods i never actually read the rules properly Anyway i do have some php ipn scripts which arent mine and i can also get one of my friend who also owns a php game but his seems complicated because it uses 'switches' functions which im not familiar with. No one is going to hand you one, do your own search, but I can explain how paypal's IPN (Instant payment notification) works IPN (in a nutshell) 1) Person Makes a payment for items on your site with paypal, your site gives paypal the item number, and your mysql user number for that person 2) They complete payment and return to your site. 3) Paypal verifies the payment is legit 4) After payment is verified (or not) paypal pings a page on your server you tell them to with the data of the sale 5) You are required to verify the data by paypal for consistency 5.a) if it is consistent you can use it and distribute your items, start shipping, etc. 5.a.I)If the payment cleared send stuff 5.a.II)If it didn't clear the payment wasn't good alert user and don't send stuff 5.b) If its not consitent you should ignore the data as it could be a hack attack That is about it, it is very critical you dont process on your thankyou page as this could result in bounced payments. Quote Link to comment https://forums.phpfreaks.com/topic/79821-paypal-automated-payment-using-php/#findComment-404472 Share on other sites More sharing options...
ILYAS415 Posted December 3, 2007 Share Posted December 3, 2007 cooldude i wasnt expecting any1 to hand me one! Anyway Goose what you can do with a paypal ipn script is... 1). Create a random code and email it to the user. Make sure to insert the code into your db so that u can check for it later on and see if it matches anything anyone types in. Make a code box in which people can type in the code they recieved in their email. When they type in their code they can/have to specify a email (the one they used in their payment) for security reasons so that noone else uses their code. 2). ... Or you can choose to simply connect the ipn script to your database and give them the product manually by running queries etc. Ipn scripts can also connect to your db so you can run quries on the same page. It is known as a 'Instant payment notification' script which basically means its MADE for notifying the owner of the product but it can also be used for automated and electronic stuff e.g. like in your game you want to credit them with a donators package or something like that. ---------------------------------------------------------- Their is also another payment method script you can use which allows the players on your game to pay by sms. This is very useful becuz then ull earn lots of $$$. Basically you'll hav to lk this up on google. Try typing "Onebip sms payments" or something lyk that. Quote Link to comment https://forums.phpfreaks.com/topic/79821-paypal-automated-payment-using-php/#findComment-405193 Share on other sites More sharing options...
Goose87 Posted December 3, 2007 Author Share Posted December 3, 2007 I know that no-one will just give me the script. I don't really understand how the script works. I found an IPN script on google that seemed quite good, but I couldn't work out EXACTLY how it worked. I wanted it to adjust the part that had an email being sent, to making the database update with the ID of the user, and the donator package item for example, but i just had NO idea where the variables were in the script. I might post the script below and see if someone could just add the parts where i'd have the user id and the donator package id for example. I REALLY need this to work for my game, or i won;t be able to afford the server costs, so i'd absolutely love it if someone could help me out. Cheers. DATABASE STUFF: CREATE TABLE sales ( invoice INT UNSIGNED AUTO_INCREMENT, receiver_email VARCHAR(60), item_name VARCHAR(100), item_number VARCHAR(10), quantity VARCHAR(6), payment_status VARCHAR(10), pending_reason VARCHAR(10), payment_date VARCHAR(20), mc_gross VARCHAR(20), mc_fee VARCHAR(20), tax VARCHAR(20), mc_currency VARCHAR(3), txn_id VARCHAR(20), txn_type VARCHAR(10), first_name VARCHAR(30), last_name VARCHAR(40), address_street VARCHAR(50), address_city VARCHAR(30), address_state VARCHAR(30), address_zip VARCHAR(20), address_country VARCHAR(30), address_status VARCHAR(10), payer_email VARCHAR(60), payer_status VARCHAR(10), payment_type VARCHAR(10), notify_version VARCHAR(10), verify_sign VARCHAR(10), referrer_id VARCHAR(10), PRIMARY KEY (invoice) ); <?php //------------------------------------------------------------------ // Open log file (in append mode) and write the current time into it. // Open the DB Connection. Open the actual database. //------------------------------------------------------------------- $log = fopen("ipn.log", "a"); fwrite($log, "\n\nipn - " . gmstrftime ("%b %d %Y %H:%M:%S", time()) . "\n"); $db = mysql_connect("localhost", "yourname", "yourpassword"); mysql_select_db("yourdb",$db); //------------------------------------------------ // Read post from PayPal system and create reply // starting with: 'cmd=_notify-validate'... // then repeating all values sent - VALIDATION. //------------------------------------------------ $postvars = array(); while (list ($key, $value) = each ($HTTP_POST_VARS)) { $postvars[] = $key; } $req = 'cmd=_notify-validate'; for ($var = 0; $var < count ($postvars); $var++) { $postvar_key = $postvars[$var]; $postvar_value = $$postvars[$var]; $req .= "&" . $postvar_key . "=" . urlencode ($postvar_value); } //-------------------------------------------- // Create message to post back to PayPal... // Open a socket to the PayPal server... //-------------------------------------------- $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 ("www.paypal.com", 80, $errno, $errstr, 30); //--------------------------------------------- fwrite($log, "Vals: ". $invoice." ". $receiver_email." ". $item_name." ". $item_ number." ". $quantity." ". $payment_status." ". $pending_reason." ".$payment_dat e." ". $payment_gross." ". $payment_fee." ". $txn_id." ". $txn_type." ". $first_ name." ". $last_name." ". $address_street." ". $address_city." ". $address_state . " ".$address_zip." ". $address_country." ". $address_status." ". $payer_email. " ". $payer_status." ". $payment_type." ". $notify_version." ". $verify_sign. "\ n"); //---------------------------------------------------------------------- // Check HTTP connection made to PayPal OK, If not, print an error msg //---------------------------------------------------------------------- if (!$fp) { echo "$errstr ($errno)"; fwrite($log, "Failed to open HTTP connection!"); $res = "FAILED"; } //-------------------------------------------------------- // If connected OK, write the posted values back, then... //-------------------------------------------------------- else { fputs ($fp, $header . $req); //------------------------------------------- // ...read the results of the verification... // If VERIFIED = continue to process the TX... //------------------------------------------- while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { //---------------------------------------------------------------------- // If the payment_status=Completed... Get the password for the product // from the DB and email it to the customer. //---------------------------------------------------------------------- if (strcmp ($payment_status, "Completed") == 0) { $qry = "SELECT password FROM products WHERE pid = \"$item_number\" "; $result = mysql_query($qry,$db); while ($myrow = mysql_fetch_row($result)) { $passwd = $myrow[0]; } $message .= "Dear Customer,\n Thankyou for your order.\n\nThe password f or the item you ordered is: $row[0]\n\nIf you have any problems, please contact us: \n\nsales\@yourdomain.com"; mail($payer_email, "Your Book Password...", $message, "From: [email protected]\nReply-To: [email protected]"); } //---------------------------------------------------------------------- // If the payment_status is NOT Completed... You'll have to send the // password later, by hand, when the funds clear... //---------------------------------------------------------------------- else { $message .= "Dear Customer,\n Thankyou for your order.\n\nThe password for the item you ordered will be sent to you when the funds have cleared.\n\nThankyou \n\nsales\@yourdomain.com"; mail($payer_email, "Your Book Password...", $message, "From: [email protected]\nReply-To: [email protected]"); mail($receiver_email, "Incomplete PayPal TX...", "An incomplete transaction requires your attention."); } //---------------------------------------------------------------- // ..If UNVerified - It's 'Suspicious' and needs investigating! // Send an email to yourself so you investigate it. //---------------------------------------------------------------- else { mail($payer_email, "An Error Occurred...", "Dear Customer,\n an error occurred while PayPal was processing your order. It will be investigated by a human at the earliest opportunity.\n\nWe apologise for any inconvenience.", "From: [email protected]\nReply-To: [email protected]"); mail($receiver_email, "Invalid PayPal TX...", "An invalid transaction requires your attention."); } } } //-------------------------------------- // Insert Transaction details into DB. //-------------------------------------- $qry = "INSERT into psales ( invoice, receiver_email, item_name, item_number, quantity, payment_status, pendi ng_reason, payment_date, payment_gross, payment_fee, txn_id, txn_type, first_nam e, last_name, address_street, address_city, address_state, address_zip, address_ country, address_status, payer_email, payer_status, payment_type, notify_version , verify_sign ) VALUES ( \"$invoice\", \"$receiver_email\", \"$item_name\", \"$item_number\", \"$quanti ty\", \"$payment_status\", \"$pending_reason\", \"$payment_date\", \"$payment_gr oss\", \"$payment_fee\", \"$txn_id\", \"$txn_type\", \"$first_name\", \"$last_na me\", \"$address_street\", \"$address_city\", \"$address_state\", \"$address_zip \", \"$address_country\", \"$address_status\", \"$payer_email\", \"$payer_status \", \"$payment_type\", \"$notify_version\", \"$verify_sign\" ) "; $result = mysql_query($qry,$db); //------------------------------------------- // Close PayPal Connection, Log File and DB. //------------------------------------------- fclose ($fp); fclose ($log); mysql_close($db); ?> Thanks a lot, if someone helps me out, I'd REALLY appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/79821-paypal-automated-payment-using-php/#findComment-405233 Share on other sites More sharing options...
ILYAS415 Posted December 3, 2007 Share Posted December 3, 2007 Okay no problem. Its quite ironic that u actually show me that script becuz thats the same one i am currently trying to use. Okay if your talking about the $payer_email and $reciever_email variables don't worry their just variables fetched from the paypal website. The problem with the script u provided is that i dont think it includes a manual. I tihnk your meant to create a button in the paypal button factory and make the button somehow notify the ipn script uve provided. Ive seen somewere b4 how to do this but im afraid it didn't work then. Hopefully someone hu nos will reply here... i said hopefully Quote Link to comment https://forums.phpfreaks.com/topic/79821-paypal-automated-payment-using-php/#findComment-405256 Share on other sites More sharing options...
Goose87 Posted December 3, 2007 Author Share Posted December 3, 2007 Yeah its the top result when i searched on google for an IPN. I just need someone with experience to explain how I can adjust this script for my tailored needs. Afterall, I can only learn if someone points me in the right direction to start with. If i learn by someone teaching me, I can then build on that knowledge, rather than sitting here being clueless like I am now. Quote Link to comment https://forums.phpfreaks.com/topic/79821-paypal-automated-payment-using-php/#findComment-405277 Share on other sites More sharing options...
Goose87 Posted December 3, 2007 Author Share Posted December 3, 2007 is no-one willing to help me out here? Surely I am no competition to everyone else by having an online game that can accept money automatically rather than have to do it all manually?? I'd really appreciate it if someone who has the knowledge could just explain it to me. If you don't want to explain it to the whole community, but are willing to explain it to just me, email me at [email protected] Cheers, Goose. Quote Link to comment https://forums.phpfreaks.com/topic/79821-paypal-automated-payment-using-php/#findComment-405541 Share on other sites More sharing options...
brown2005 Posted December 3, 2007 Share Posted December 3, 2007 hey message me at [email protected] and i might be able to help Quote Link to comment https://forums.phpfreaks.com/topic/79821-paypal-automated-payment-using-php/#findComment-405550 Share on other sites More sharing options...
Distant_storm Posted December 3, 2007 Share Posted December 3, 2007 I am looking to make a click and buy system with paypal. I never heard of this automated process with paypal might look into it myself although im thinking it is going to be heavy object orientated. Switch control proberbly just gets the result from paypal and you make a decision based on the result correct ? Quote Link to comment https://forums.phpfreaks.com/topic/79821-paypal-automated-payment-using-php/#findComment-405583 Share on other sites More sharing options...
cooldude832 Posted December 4, 2007 Share Posted December 4, 2007 There is no php, and beyond this its a third party integration. You have the scripts right there. All you need is to config your paypal account properly. Send paypal what you want (Such as the primary key to that row in your mysql) and then when the IPN pings your server verify and if its good insert. I gave you a very clear explination, and paypal gives you the exact IPN verification script to use. Quote Link to comment https://forums.phpfreaks.com/topic/79821-paypal-automated-payment-using-php/#findComment-405591 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.