• Paypal IPN Vip Subscription
    6 replies, posted
So I'm creating a subscription VIP system for my Garrysmod server, and I'm a total noob at PHP. Basically I want it to get their steamid at the order page, add them into a MySQL database when they purchase it, and keep them in it as long as they pay the subscription. I've made something, but I'm not sure how well it would work. Here it is: [code]<?php // read the post from PayPal system and add 'cmd' $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"; $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); //Delete the 'sandbox' part // assign posted variables to local variables $item_name = $_POST['item_name']; $payment_status = $_POST['payment_status']; $txn_id = $_POST['txn_id']; $txn_type = $_POST['txn_type']; $receiver_email = $_POST['receiver_email']; $payer_email = $_POST['payer_email']; $steam_id = $_POST['custom']; if (!$fp) { // HTTP ERROR } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { if($txn_type == "subscr_eot"){ if($item_name == "VIP") { $link = mysql_connect('xxxxxx', 'xxxxxxxxxxx', 'xxxxxxxxxxx'); mysql_select_db("perp", $link); mysql_query("DELETE FROM vip_database WHERE SteamID='$steam_id'"); mysql_close($link); //Delete from database } } elseif ($txn_type == "subscr_payment"){ if(strcmp ($payment_status, "Completed") == 0){ //Check Transaction ID if($item_name == "VIP") { $link = mysql_connect('xxxxxxxx', 'xxxx', 'xxxxxxxxxxx'); mysql_select_db("perp", $link); $peps = mysql_query("SELECT * FROM vip_database WHERE SteamID='$steam_id'"); $row = mysql_fetch_assoc($peps); echo $row['SteamID']; if(!$row['SteamID']){ mysql_query("INSERT INTO perp_vip (SteamID) VALUES ('$steam_id')"); } mysql_close($link); } } } } else if (strcmp ($res, "INVALID") == 0) { //Invalid Do nothing } } fclose ($fp); } ?>[/code] Is there a better way to do this, or is there something already released? Also how can you simulate months in Paypal sandbox? So I don't have to wait a month to test a subscription. Thanks in advance.
Don't rely on paypal IPN to remove the subscription, set a time when the subscription was made and from there setup a scheduled task or cron job to run a script and remove all VIP's that are old or make a script to check ingame. You also have a few exploits in your paypal code.
Paypal is such a piece of shit. I highly suggest stripe over paypal. Better API, better everything.
[QUOTE=Mr_Razzums;35836764]Paypal is such a piece of shit. I highly suggest stripe over paypal. Better API, better everything.[/QUOTE] That's like saying myspace has cooler features and is way better in every way, so everyone should use it but they don't because none of their friends use myspace.
No it's not because myspace is a piece of shit
[QUOTE=KmartSqrl;35966719]No it's not because myspace is a piece of shit[/QUOTE] Eh ok bad example point is, although it may be better, the people who have money to donate, might not because its not as known as PayPal.
[QUOTE=zzaacckk;35972718]Eh ok bad example point is, although it may be better, the people who have money to donate, might not because its not as known as PayPal.[/QUOTE] Stripe is just plain and simple Credit Card Processing. It's very, very different to paypal. (Also much better)
Sorry, you need to Log In to post a reply to this thread.