Bravo List

Bravo List (http://www.bvlist.com/index.php)
-   Mods & Themes (http://www.bvlist.com/forumdisplay.php?f=109)
-   -   paypal ipn (http://www.bvlist.com/showthread.php?t=9102)

sharpie 27th April 2013 00:13

paypal ipn
 
how do i deal with subscription payments via the paypal.php so that members get correct credits currently the paypal.php only deals with donations and not subscriptions

Code:

require "include/bittorrent.php";
require_once("ircbot.php");       
dbconn();


$donb=0;
// 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 ('www.paypal.com', 80, $errno, $errstr, 30);
// assign posted variables to local variables
$id = mysql_insert_id();
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$clid = $_POST['custom'];
$payment_type = $_POST['payment_type'];
$ip =  $_SERVER['REMOTE_ADDR'];
$trans_id = $_POST['txn_id'];
$os2 = $_POST['option_selection2'];
$payment_gross = $_POST['mc_gross'];
$payment_fee = $_POST['payment_fee'];
$os1 = $_POST['option_selection1'];
if (!$txn_id) die;
if (!$clid) die;
if ($receiver_email != "****@*****") die; #Your Paypal Emial here

// block pending echecks. paypal posts payments again when echecks clear, blocks double credits.
if ($payment_type == "echeck" && $payment_status == "Pending") die;

if (!$fp){
}
else
{
fputs ($fp, $header . $req);
while (!feof($fp))
{
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0)
{
// process payment

///Sort Upload and Donor time amounts
if ($payment_amount == 2)
{$days = 1*1;}
if ($payment_amount == 5)
{$days = 1*2;}
elseif ($payment_amount == 10)
{$days = 1*4;}
elseif ($payment_amount == 20)
{$days = 1*8;}
elseif ($payment_amount == 25)
{$days = 1*16;}
elseif ($payment_amount == 40)
{$days = 1*32;}
elseif ($payment_amount == 30)
{$days = 1*52;}
elseif ($payment_amount == 45)
{$days = 1*704;}
else {$days = 1*1;}

//set donor upload upgrade
if ($payment_amount == 2)
{$donb = 5368709120; }
if ($payment_amount == 5)
{$donb = 10737418240; }
elseif ($payment_amount == 10)
{$donb = 21474836480; }
elseif ($payment_amount == 20)
{$donb = 42949672960; }
elseif ($payment_amount == 25)
{$donb = 128849018880; }
elseif ($payment_amount == 40)
{$donb = 171798691840; }
elseif ($payment_amount == 30)
{$donb = 257698037760; }
elseif ($payment_amount == 45)
{$donb = 322122547200; }
else {
$donb = 1073741824*$payment_amount;}

//Set User Invites
if ($payment_amount == 2)
{$invites = 1; }
if ($payment_amount == 5)
{$invites = 2; }
elseif ($payment_amount == 10)
{$invites = 4; }
elseif ($payment_amount == 20)
{$invites = 6; }
elseif ($payment_amount == 25)
{$invites = 8; }
elseif ($payment_amount == 40)
{$invites = 10; }
elseif ($payment_amount == 30)
{$invites = 12; }
elseif ($payment_amount == 45)
{$invites = 14; }
else {
$invites = 0;}

//Set User Seedbonus
if ($payment_amount == 2)
{$seedbonus = 1000; }
if ($payment_amount == 5)
{$seedbonus = 15625; }
elseif ($payment_amount == 10)
{$seedbonus = 31250; }
elseif ($payment_amount == 20)
{$seedbonus = 62500; }
elseif ($payment_amount == 25)
{$seedbonus = 125000; }
elseif ($payment_amount == 40)
{$seedbonus = 250000; }
elseif ($payment_amount == 30)
{$seedbonus =500000; }
elseif ($payment_amount == 45)
{$seedbonus = 1000000; }
else {
$seedbonus = 0;}

//get user information from DB
$query = "SELECT * FROM users WHERE id='".$clid."'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$username = $row['username'];
$old=date($row['donoruntil']);
$class = $row['class'];
$dona = $row['uploaded'];

//Set class to VIP if lower then VIP
if ($class <= 32)
{$class = 32;}
$r = @mysql_query("SELECT * FROM users WHERE id=$clid") or sqlerr();
$user = mysql_fetch_array($r) or bark("No user with ID.");
//Reset download upload post and reset to zero H&R's
$query = "UPDATE users SET donor='yes', downloadpos='yes', class=$class, timeswarned = 0,warned ='no',invites=invites+$invites,seedbonus=seedbonus+$seedbonus WHERE id='".$clid."'";
$result = mysql_query("$query");


//Get Donor time if already some left from before
If ($old<>"0000-00-00 00:00:00")
{
$old1=strtotime($old)- gmtime();
$donateuntil = get_date_time((gmtime() + $days * 604800) +$old1);
}
else
{$donateuntil = get_date_time(gmtime() + $days * 604800);}
//add Upload bonus for amount given at 1Gb per ?1
$bonus = $donb + $dona;
$donordif =strtotime($donateuntil)- gmtime();
//add to mod comment for staff to check if payment made via here
$modcomment = gmdate("d-m-Y [H:i]") . " Donation Made Auto Promoted to Vip.\n". $modcomment;
//$modcomment = gmdate("d-m-Y H:i") . " Donation Made Auto Promoted to Vip";
$modcom = sqlesc($modcomment);
//update users total and bonus totals
$query = "UPDATE users SET uploaded='".$bonus."', modcomment = CONCAT($modcom,modcomment), donoruntil='$donateuntil', donated=$payment_amount,total_donated=total_donated+$payment_amount WHERE id='".$clid."'";
$result = mysql_query($query);

//Send Message to Site Owners
$sysop = mysql_query("SELECT id FROM users WHERE id=9") or sqlerr(__FILE__, __LINE__);
while ($sysopid = mysql_fetch_assoc($sysop)){
//$sysopmsg = "User: ".$username." | Amount : $$payment_amount | Email: $payer_email";
//new_msg(0, $sysopid['id'], $sysopmsg);
}
}}

$day = date("d");
$month = date("m");
$year = date("Y");
$time = time();
//Update users User Level.                               
$query = "INSERT into donations
(ip,txn_id,name,donation,fees,dnuid,time,username)
VALUES
('$ip','$trans_id','$os2','$payment_gross','$payment_fee','$os1','$time','$username')";
$result = mysql_query($query);
//bot signup end
/** shoutbox announce new signup **/
$message = "Thanks ".$username." for supporting GT & adding £$payment_amount to the site fund ";
autoshouts($message);
/** end **/
/** irc announce new donation **/
$msgs = array();
$msgs[] = "\0036$username Added \0038£$payment_amount To The Site Fund";
IRCSendMsg($msgs);
/** end **/

header("Location: http://****/");

fclose ($fp);
}
stdfoot();
?>

Thanks in advance

joeroberts 27th April 2013 12:42

you have to A premium account on paypal and activate it on paypal first

sharpie 27th April 2013 13:13

is that the same as a Premier account? if so i have this m8

joeroberts 27th April 2013 13:37

In paypal go to My Account=> Profile =>My selling tools
and edit Instant payment notifications
every time a user sends you money for any reason it well notify that page be it for donation or subscription.

sharpie 27th April 2013 13:56

Awesome m8 will give it a bash thank you for the help


All times are GMT +2. The time now is 03:17.

Powered by vBulletin® Version 3.8.11 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions Inc.