<?php
session_start();
include "../config.php";
include "../Stripe/init.php";
include "../Stripe/syek.php";
\Stripe\Stripe::setApiKey("$secret");

// Token is created using Stripe.js or Checkout!
// Get the payment token submitted by the form:

$token        = $_POST['stripeToken'];
$email        = $_POST['stripeEmail'];
$uid          = $_POST['uid'];
$currency     = $_POST['currency'];
$amount       = $_POST['amount'];
$name         = $_POST['name'];
$item         = $_POST['name'];
$item1         = $_POST['description'];
$description  = $_POST['description'];
$userid=$_SESSION['uname'];
$number  = $_POST['number'];
$type  = $_POST['type'];
$userid=$_POST['userid'];

#This is the standard try catch block stripe suggests
date_default_timezone_set('America/New_York');
try{
    $charge = \Stripe\Charge::create(array(
        "amount"        => $amount,
        "currency"      => $currency,
        "description"   => $description,
        "receipt_email" => $email,
        "metadata" => array("order_id" => $orderid),
        "source" => $token,
    ));

    $orderid 	  = $_POST['orderid'];
    $ip 	      = $_POST['ip'];
    $email	      = $_POST['stripeEmail'];
    $today = date('Y-m-d h:i:s',strtotime("now"));

    $amountCent = $amount/100;
    $netamount = $amount*97/100-0.30;

    include "../secureheader.php";
    include "../style.php";

    echo "<div align=\"center\"><span class=\"copy\">Thank you. Your payment has been completed.<br>A receipt for your payment has been sent to $email<br>Return back to the <a href=\"$domain/members/advertisestats.php\" class=\"copy\">Members Area Here</a></span></div><br><br>";


    //sample IPN code below change to your own
    
    $query = "select * from members where userid='".$userid."'";
    $result = mysql_query ($query) or die ("Query failed");
    $numrows = @ mysql_num_rows($result);
    if ($numrows == 1) {
        $user = mysql_fetch_array($result);
        //if($item == "Membership") {
        if($item != $sitename." Membership ".$userid) {
            
        }
################################################
if ($memtype == "SUPER JV")
{
$hheadlineadprice = $superjvhheadlineadprice;
$hheadlineadpointprice = $hheadlineadpointpricesuperjv;
$hheadlineadmaxhits = $superjvhheadlineadmaxhits;
$hheaderadprice = $superjvhheaderadprice;
$hheaderadpointprice = $hheaderadpointpricesuperjv;
$hheaderadmaxhits = $superjvhheaderadmaxhits;
}
if ($memtype == "JV Member")
{
$hheadlineadprice = $jvhheadlineadprice;
$hheadlineadpointprice = $hheadlineadpointpricejv;
$hheadlineadmaxhits = $jvhheadlineadmaxhits;
$hheaderadprice = $jvhheaderadprice;
$hheaderadpointprice = $hheaderadpointpricejv;
$hheaderadmaxhits = $jvhheaderadmaxhits;
}
if (($memtype != "SUPER JV") and ($memtype != "JV Member"))
{
$hheadlineadprice = $prohheadlineadprice;
$hheadlineadpointprice = $hheadlineadpointpricepro;
$hheadlineadmaxhits = $prohheadlineadmaxhits;
$hheaderadprice = $prohheaderadprice;
$hheaderadpointprice = $hheaderadpointpricepro;
$hheaderadmaxhits = $prohheaderadmaxhits;
}
################################################
		
} if($item == "Per 1000 Points") {
mysql_query("INSERT INTO transactions VALUES ('id', '".$userid."','Stripe Payment - 1000 points','".time()."','$$amountCent')");
mysql_query("UPDATE members SET points=points+1000 WHERE userid = '".$userid."'");

} elseif($item == "Solo Ad") {
mysql_query("INSERT INTO transactions VALUES ('id', '".$userid."','Stripe Payment - Solo Ad','".time()."','$$amountCent')");
mysql_query("INSERT INTO `solos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '".$userid."', '0', '', '', '0', '0')");


} elseif($item == "Hot Headline Ad") {
mysql_query("INSERT INTO transactions (`id`, `userid`, `action`, `date`, `quantity`) VALUES ('id', '".$userid."','Stripe Payment - Hot Headline Ad $hheadlineadmaxhits Impressions','".time()."','$$amountCent')");
mysql_query ( "insert into hheadlineads (userid,max,purchase) values('" . dbput ( $userid ) . "','$hheadlineadmaxhits',NOW())" );
$quantity --;


} elseif($item == "Banner Ad") {
mysql_query("INSERT INTO transactions VALUES (`id`, '".$userid."','Stripe Payment - Banner Ad','".time()."','$$amountCent')");
mysql_query("INSERT INTO `banners` ( `id` , `name` , `bannerurl` , `targeturl` , `userid` , `status` , `shown` , `clicks` , `max` , `added` )VALUES (NULL , '', '', '', '".$userid."', '0', '0', '0', '1000', '0')");


} elseif($item == "High Priority Solo Ad") {
mysql_query("INSERT INTO transactions (`id`, `userid`, `action`, `date`, `quantity`) VALUES  ('id','".$userid."','Stripe Payment - High Priority Solo Ad','".time()."','$$amountCent')");
mysql_query ( "INSERT INTO `hpsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );


} elseif($item == "Button Ad") {
mysql_query("INSERT INTO `buttons` (`id` , `name` , `bannerurl` , `targeturl` , `userid` , `status` , `shown` , `clicks` , `max` , `added` )VALUES (NULL , '', '', '', '".$userid."', '0', '0', '0', '1000', '0')");
mysql_query("INSERT INTO transactions VALUES ('id', '".$userid."','Stripe Payment - Button Banner Ad','".time()."','$$amountCent')");



} elseif($item == "Top Navigation Link") {
mysql_query("INSERT INTO transactions VALUES ('id','".$userid."','Stripe Payment - Top Navigation Link','".time()."','$$amountCent')");
mysql_query("INSERT INTO `topnav` ( `userid` , `date`) VALUES ('".$userid."', '".time()."')");


} elseif($item == "Bottom Navigation Link") {
mysql_query("INSERT INTO transactions VALUES ('id','".$userid."','Stripe Payment - Bottom Navigation link','".time()."','$$amountCent')");
mysql_query("INSERT INTO `botnav` ( `userid` , `date`) VALUES ('".$userid."', '".time()."')");


} elseif($item == "Solo Footer Ad") {
mysql_query("INSERT INTO transactions VALUES ('id', '".$userid."','Stripe Payment - ".$quantity." Solo Footer Ad','".time()."','$$amountCent')");
mysql_query("INSERT INTO `footerads` (`userid`, `paid`) VALUES('$userid','100')");



} elseif($item == "Full Page Login Ad") {
$rented = $_POST['rented'];
mysql_query("insert into `fullloginads` (`userid`, `rented`) values('$userid','$rented')");
mysql_query("INSERT INTO transactions VALUES ('id', '".$userid."','Stripe Payment - Full Page Login Ad $rented','".time()."','$$amountCent')");

				

} elseif($item == "Login Ad") {
mysql_query("INSERT INTO transactions VALUES ('id','".$userid."','Stripe Payment - Login Ad','".time()."','$$amountCent')");
mysql_query("insert into `loginads` (`userid`, `max`) VALUES('".$userid."','1000')");



} elseif($item == "Traffic Link 50") {
mysql_query("INSERT INTO transactions VALUES ('id','".$userid."','Stripe Payment - Traffic Link 50','".time()."','$$amountCent')");
mysql_query("insert into `tlinks` (`userid`, `paid`) VALUES('$userid','50')");



} elseif($item == "Traffic Link 100") {
mysql_query("INSERT INTO transactions VALUES ('id', '".$userid."','Stripe Payment - Traffic Link 100','".time()."','$$amountCent')");
mysql_query("insert into `tlinks` (`userid`, `paid`) VALUES('$userid','100')");




} elseif($item == "Traffic Link 200") {
mysql_query("INSERT INTO transactions VALUES ('id', '".$userid."','Stripe Payment -  Traffic Link 200','".time()."','$$amountCent')");
mysql_query("insert into `tlinks` (`userid`, `paid`) values('$userid','200')");



} elseif($item == "PTC 1") {
mysql_query("INSERT INTO transactions VALUES ('id', '".$userid."','Stripe Payment - PTC 50','".time()."','$$amountCent')");
mysql_query("insert into `ptcads` (`userid`, `paid`) values('$userid','50')");



} elseif($item == "PTC 2") {
mysql_query("INSERT INTO transactions VALUES ('id', '".$userid."','Stripe Payment - PTC 100','".time()."','$$amountCent')");
mysql_query("insert into `ptcads` (`userid`, `paid`) values('".$userid."','100')");



} elseif($item == "PTC 3") {
mysql_query("INSERT INTO transactions VALUES ('id', '".$userid."','Stripe Payment -  PTC 200','".time()."','$$amountCent')");
mysql_query("insert into `ptcads` (userid,paid) values('".$userid."','200')");



} elseif($item == "Hot Link 5000") {
mysql_query("INSERT INTO transactions VALUES ('id','".$userid."','Stripe Payment - Hot Link 5000','".time()."','$$amountCent')");
mysql_query("insert into `hotlinks` (`userid`, `max`) values('".$userid."','5000')");		

					

} elseif($item == "Hot Link 10000") {
mysql_query("INSERT INTO transactions VALUES ('id','".$userid."','Stripe Payment - Hot Link 10000','".time()."','$$amountCent')");
mysql_query("insert into `hotlinks` (`userid`, `max`) values('".$userid."','10000')");	



} elseif($item == "Hot Link 20000") {
mysql_query("INSERT INTO transactions VALUES ('id','".$userid."','Stripe Payment - Hot Link 20000','".time()."','$$amountCent')");
mysql_query("insert into `hotlinks` (`userid`, `max`) values('".$userid."','20000')");	



} elseif($item == "JV Membership Upgrade") {
mysql_query("INSERT INTO transactions VALUES ('id', '".$userid."','Stripe Payment - JV Member Upgrade','".time()."','$$amountCent')");
upgrade_jv($userid);


} elseif($item == "SuperJV Membership") {
mysql_query("INSERT INTO transactions VALUES ('id', '".$userid."','Stripe Payment - SUPER JV Upgrade','".time()."','$$amountCent')");
upgrade_superjv($userid);


} elseif($item == "Cash Solo") {
mysql_query("INSERT INTO transactions VALUES ('id','".$userid."','Stripe Payment - Cash Solo','".time()."','$$amountCent')");
mysql_query ( "INSERT INTO `cashsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . $userid . "', '0', '', '', '0', '0')" );

} elseif($item == "High Priority Cash Solo Ad") {
mysql_query("INSERT INTO transactions VALUES ('id','".$userid."','Stripe Payment - High Priority Cash Solo Ad','".time()."','$$amountCent')");
mysql_query ( "INSERT INTO `hpcsolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '" . dbput ( $userid ) . "', '0', '', '', '0', '0')" );

} elseif($item == "Headline 5000") {
mysql_query("INSERT INTO transactions VALUES ('id','".$userid."','Stripe Payment - Headline 5000','".time()."','$$amountCent')");
mysql_query ( "insert into headlineads (userid,max) values('" . dbput ( $userid ) . "','5000')" );

} elseif($item == "Headline 10000") {
mysql_query("INSERT INTO transactions VALUES ('id','".$userid."','Stripe Payment - Headline 10000','".time()."','$$amountCent')");
mysql_query ( "insert into headlineads (userid,max) values('" . dbput ( $userid ) . "','10000')" );

} elseif($item == "Headline 20000") {
mysql_query("INSERT INTO transactions VALUES ('id','".$userid."','Stripe Payment - Headline 20000','".time()."','$$amountCent')");
mysql_query ( "insert into headlineads (userid,max) values('" . dbput ( $userid ) . "','20000')" );

} elseif($item == "Solo Header Ad") {
mysql_query("INSERT INTO transactions VALUES ('id','".$userid."','Stripe Payment - Solo Header Ad','".time()."','$$amountCent')");
mysql_query ( "insert into headerads (userid,paid) values('" . dbput ( $userid ) . "','100')" );
$quantity --;

} elseif($item == "Solo Footer Ad") {
mysql_query("INSERT INTO transactions VALUES ('id','".$userid."','Stripe Payment - Solo Footer Ad','".time()."','$$amountCent')");
mysql_query ( "insert into footerads (userid,paid) values('" . dbput ( $userid ) . "','100')" );
$quantity --;

} elseif($item == "Daily Bonus") {
 $rented = $_POST['rented'];   
mysql_query("INSERT INTO transactions VALUES ('id','".$userid."','Stripe Payment - Daily Bonus $rented','".time()."','$$amountCent')");
mysql_query ( "insert into dailybonus (userid,rented) values('" . dbput ( $userid ) . "','$rented')" );



} elseif($item == "Hot Header Ad") {
mysql_query ( "INSERT INTO transactions VALUES ('id','" . dbput ( $userid ) . "','Stripe Payment - Hot Header Ad $hheaderadmaxhits Clicks','" . time () . "','$$amountCent')" );
mysql_query ( "insert into hheaderads (userid,max,purchase) values('" . dbput ( $userid ) . "','$hheaderadmaxhits',NOW())" );
$quantity --;

} elseif ($item1 == $sitename." Set N Forget Solo(s)") {
mysql_query ( "INSERT INTO transactions VALUES ('id', '" . ( $userid ) . "','Stripe Payment - Set N Forget Solo(s)','" . time () . "','$$amountCent')" );
mysql_query ( "INSERT INTO `snfsolos` (`userid`, `type`, solos_left) VALUES ('".$userid."', '".$type."', '".$number."')" );

} elseif ($item1 == $sitename." Set N Forget Cash Solo(s)") {
mysql_query ( "INSERT INTO transactions VALUES ('id', '" . ( $userid ) . "','Stripe Payment - Set N Forget Cash Solo(s)','" . time () . "','$$amountCent')" );
mysql_query ( "INSERT INTO `snfcsolos` (`userid`, `type`, cashsolos_left) VALUES ('".$userid."', '".$type."', '".$number."')" );
    
    
} elseif($item == "Special Offer") {
mysql_query("INSERT INTO transactions VALUES ('id', '".$userid."','Stripe Payment - Special Offer','".time()."','$$amountCent')");
$sql = mysql_query("SELECT * FROM offerpage LIMIT 1");
$offer = mysql_fetch_array($sql);


if($offer['points']) { 
mysql_query("UPDATE members SET points=points+".$offer['points']." WHERE userid='".$userid."'");

}

if($offer['banner_num'] AND $offer['banner_views']) {
$count = $offer['banner_num'];
while($count > 0) {
mysql_query("INSERT INTO `banners` ( `id` , `name` , `bannerurl` , `targeturl` , `userid` , `status` , `shown` , `clicks` , `max` , `added` )VALUES (NULL , '', '', '', '".$userid."', '0', '0', '0', '".$offer['banner_views']."', '0')");
$count--;

}

}

if($offer['button_num'] AND $offer['button_views']) {
$count = $offer['button_num'];
while($count > 0) {
mysql_query("INSERT INTO `buttons` ( `id` , `name` , `bannerurl` , `targeturl` , `userid` , `status` , `shown` , `clicks` , `max` , `added` )VALUES (NULL , '', '', '', '".$userid."', '0', '0', '0', '".$offer['button_views']."', '0')");
$count--;

}

} 

if($offer['traffic_num'] AND $offer['traffic_views']) {
$count = $offer['traffic_num'];
while($count > 0) {
mysql_query("insert into `tlinks` (userid,paid) values('$userid','".$offer['traffic_views']."')");
$count--;

}

}

if($offer['login_num'] AND $offer['login_views']) {
$count = $offer['login_num'];
while($count > 0) {
mysql_query("insert into `loginads` (userid,max) values('$userid','".$offer['login_views']."')");
$count--;

}

}


if($offer['hotlink_num'] AND $offer['hotlink_views']) {
$count = $offer['hotlink_num'];
while($count > 0) {
mysql_query("INSERT INTO `hotlinks` (userid,max,purchase) values('$userid','".$offer['hotlink_views']."','".time()."')");
$count--;

}

} 

if($offer['solo_num']) {
$count = $offer['solo_num'];
while($count > 0) {
mysql_query("INSERT INTO `solos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '".$userid."', '0', '', '', '0', '0')");
$count--;


}

}


if($offer['upgrade_pro']=="1") {
upgrade_jv($userid);

}

if($offer['upgrade_pro']=="2") {
upgrade_superjv($userid);

}

if($offer['ptc_num'] AND $offer['ptc_views']) {
$count = $offer['ptc_num'];
while($count > 0) {
mysql_query("insert into `ptcads` (userid,paid) values('$userid','".$offer['ptc_views']."')");


$count--;


}

}


if($offer['topnav_num']) {
$count = $offer['topnav_num'];
while($count > 0) {		
mysql_query("INSERT INTO `topnav` (`userid` , `date`) VALUES ('".$userid."', '".time()."')");


$count--;

}

}


if($offer['botnav_num']) {
$count = $offer['botnav_num'];
while($count > 0) {		
mysql_query("INSERT INTO `botnav` (`userid` , `date`) VALUES ('".$userid."', '".time()."')");

	
$count--;

}

}


if($offer['psolo_num']) {
$count = $offer['psolo_num'];
while($count > 0) {
mysql_query("INSERT INTO `supersolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '".$userid."', '0', '', '', '0', '0')");
$count--;


}

}

}


elseif($item == "Special Offer Ad Package") {
mysql_query("INSERT INTO transactions VALUES ('id', '".$userid."','Stripe Payment - Special Offer Ad Package','".time()."','$$amountCent')");
$sql = mysql_query("SELECT * FROM offerpage LIMIT 1");
$offer = mysql_fetch_array($sql);

if($offer['points']){ 
mysql_query("UPDATE members SET points=points+".$offer['points']." WHERE userid='".$userid."'");
}

if($offer['banner_num'] AND $offer['banner_views']) {
$count = $offer['banner_num'];
while($count > 0) {
mysql_query("INSERT INTO `banners` ( `id` , `name` , `bannerurl` , `targeturl` , `userid` , `status` , `shown` , `clicks` , `max` , `added` )VALUES (NULL , '', '', '', '".$userid."', '0', '0', '0', '".$offer['banner_views']."', '0')");


$count--;


}

}



if($offer['button_num'] AND $offer['button_views']) {
$count = $offer['button_num'];
while($count > 0) {
mysql_query("INSERT INTO `buttons` ( `id` , `name` , `bannerurl` , `targeturl` , `userid` , `status` , `shown` , `clicks` , `max` , `added` )VALUES (NULL , '', '', '', '".$userid."', '0', '0', '0', '".$offer['button_views']."', '0')");

$count--;

}

} 

if($offer['traffic_num'] AND $offer['traffic_views']) {
$count = $offer['traffic_num'];
while($count > 0) {
mysql_query("insert into `tlinks` (userid,paid) values('$userid','".$offer['traffic_views']."')");


$count--;


}

}


if($offer['login_num'] AND $offer['login_views']) {
$count = $offer['login_num'];
while($count > 0) {
mysql_query("insert into `loginads` (userid,max) values('$userid','".$offer['login_views']."')");


$count--;

}

}


if($offer['hotlink_num'] AND $offer['hotlink_views']) {
$count = $offer['hotlink_num'];
while($count > 0) {
mysql_query("INSERT INTO `hotlinks` (userid,max,purchase) values('$userid','".$offer['hotlink_views']."','".time()."')");


$count--;

}

} 

if($offer['solo_num']) {
$count = $offer['solo_num'];
while($count > 0) {
mysql_query("INSERT INTO `solos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '".$userid."', '0', '', '', '0', '0')");
$count--;


}

}



if($offer['upgrade_pro']=="1") {
upgrade_jv($userid);


}

if($offer['upgrade_pro']=="2") {
upgrade_superjv($userid);

}			            


if($offer['ptc_num'] AND $offer['ptc_views']) {
$count = $offer['ptc_num'];
while($count > 0) {
mysql_query("insert into `ptcads` (userid,paid) values('$userid','".$offer['ptc_views']."')");


$count--;


}

}


if($offer['topnav_num']) {
$count = $offer['topnav_num'];
while($count > 0) {		
mysql_query("INSERT INTO `topnav` (`userid` , `date`) VALUES ('".$userid."', '".time()."')");

	
$count--;


}

}



if($offer['botnav_num']) {
$count = $offer['botnav_num'];
while($count > 0) {		
mysql_query("INSERT INTO `botnav` (`userid` , `date`) VALUES ('".$userid."', '".time()."')");
$count--;

}

}



if($offer['psolo_num']) {
$count = $offer['psolo_num'];
while($count > 0) {
mysql_query("INSERT INTO `supersolos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '".$userid."', '0', '', '', '0', '0')");
$count--;

}
}

if($offer['premiumads'] AND $oto['premiumads_days']) {
$count = $offer['premiumads'];
while($count > 0) {
mysql_query("INSERT INTO `premiumads` (`userid`,`days`)VALUES ('$userid','".$offer['premiumads_days']."')");
$count--;


}

}		
		
		
 //end sample IPN code

//echo "<meta http-equiv=\"refresh\" content=\"5; url=$domain/members/advertise.php\">";

?>
<!--META HTTP-EQUIV="Refresh"CONTENT="5; URL=/members/advertise.php"-->
<?

    }
    include "../securefooter.php";

} catch(Stripe_CardError $e) {
    $error = $e->getMessage();
    // Since it's a decline, Stripe_CardError will be caught
    $body = $e->getJsonBody();
    $err  = $body['error'];

    print('Status is:' . $e->getHttpStatus() . "\n");
    print('Type is:' . $err['type'] . "\n");
    print('Code is:' . $err['code'] . "\n");
    // param is '' in this case
    print('Param is:' . $err['param'] . "\n");
    print('Message is:' . $err['message'] . "\n");
} catch (Stripe_InvalidRequestError $e) {
    // Invalid parameters were supplied to Stripe's API
} catch (Stripe_AuthenticationError $e) {
    // Authentication with Stripe's API failed
    // (maybe you changed API keys recently)
} catch (Stripe_ApiConnectionError $e) {
    // Network communication with Stripe failed
} catch (Stripe_Error $e) {
    // Display a very generic error to the user, and maybe send
    // yourself an email
} catch (Exception $e) {
    // Something else happened, completely unrelated to Stripe
}
?>