[HELP] Automatic PayPal IPN VIP Giver

Results 1 to 5 of 5
  1. #1

    [HELP] Automatic PayPal IPN VIP Giver

    So I am using the IPN script from a post I found: http://forum.ragezone.com/f353/paypa...ic-vip-897947/

    It works and all, but how would I make it where it can hold up to 3 VIP packages instead of just 1?


  2. #2
    R.I.P Millercent FatalLulz is offline
    Grand MasterRank
    Nov 2012 Join Date
    AustraliaLocation
    2,240Posts

    Re: [HELP] Automatic PayPal IPN VIP Giver

    Paste some of the scripts regarding a package and we can help you further. Not downloading something just to help someone

  3. #3

    Re: [HELP] Automatic PayPal IPN VIP Giver

    Shall I post both the paypal.php and the other script?

    - - - Updated - - -

    Here are the two php files:
    paypal.php:

    //////////////////////////////// Script written for RevCMS
    // Coded by lDiverse
    // Edits by LaceUp
    // Free Released by LaceUp
    // //////////////////////////


    <?php
    function filter($var)
    {
    return stripslashes(htmlspecialchars($var));
    }

    require_once('paypal.class.php');
    $p = new paypal_class;
    $p->paypal_url = 'https://www.paypal.com/cgi-bin/webscr';

    $this_script = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];


    if (empty($_GET['action'])) $_GET['action'] = 'process';


    switch ($_GET['action']) {

    case 'process':

    if(!isset($_POST['username']) || !isset($_POST['amount']))
    {
    echo 'username and amount needed for purchase';
    die;
    }

    $name = filter($_POST['username']);


    switch($_POST['amount'])
    {
    case '1':

    $cost = '0.01'; //Cost of VIP
    $wut = 'VIP+'; //Name of Package


    break;

    default:

    $cost = '0.01'; //Cost of VIP again


    break;
    }

    $p->add_field('business', '#######################'); // <---------------- CHANGE ME CHANGE ME CHANGE ME CHANGE ME <----------------
    $p->add_field('return', 'http://'.$_SERVER['HTTP_HOST']);
    $p->add_field('custom', $name);
    $p->add_field('cancel_return', 'http://'.$_SERVER['HTTP_HOST']);
    $p->add_field('notify_url', $this_script.'?action=ipn');
    $p->add_field('item_number', filter($_POST['amount']));
    $p->add_field('item_name', $wut);
    $p->add_field('amount', $cost);


    $p->submit_paypal_post();
    break;

    //EDIT YOUR DATABSE SETTINGS BELOW (Same as your Phoenix Database Info)
    case 'ipn':

    if ($p->validate_ipn()) {

    $host = "localhost";
    $username = "root"; //IIS and XAMPP is root
    $password = "XXXXXXXXXX"; // <---------------- CHANGE ME CHANGE ME CHANGE ME CHANGE ME <----------------
    $dbname = "XXXXXXXXXX"; // <---------------- CHANGE ME CHANGE ME CHANGE ME CHANGE ME <----------------
    $connect = mysql_connect($host, $username, $password) or die(mysql_error());
    mysql_select_db($dbname, $connect) or die("Could not connect to database, error: ".mysql_error());


    switch($p->ipn_data['item_number'])
    {
    case '1':

    $coins = '2000'; //Amount of coins they recieve

    $pixels = '10'; //Amount of pixels they recieve

    $rank = '2'; //Your Hotel's VIP rank (2 is default for Pheonix)


    break;

    }
    mysql_query("UPDATE users SET vip = '1', rank = '2', credits = credits + 2000, activity_points = activity_points + 10 WHERE username = '".$p->ipn_data['custom']."' LIMIT 1");
    }
    break;
    }


    ?>
    - - - Updated - - -

    Paypal.class.php:

    //////////////////////////////// Script written for RevCMS
    // Coded by lDiverse
    // Edits by LaceUp
    // Free Released by LaceUp
    // //////////////////////////


    <?php
    class paypal_class {

    var $last_error;

    var $ipn_log;

    var $ipn_log_file;
    var $ipn_response;
    var $ipn_data = array();

    var $fields = array();



    function paypal_class() {



    $this->paypal_url = 'https://www.paypal.com/cgi-bin/webscr';

    $this->last_error = '';

    $this->ipn_log_file = './ipn_results.log';
    $this->ipn_log = true;
    $this->ipn_response = '';



    $this->add_field('rm','2');
    $this->add_field('cmd','_xclick');

    }

    function add_field($field, $value) {




    $this->fields["$field"] = $value;
    }


    function submit_paypal_post() {



    echo "<html>\n";
    echo "<head><title>Processing Payment...</title>";
    echo "<body onLoad=\"document.forms['paypal_form'].submit();\">\n";
    echo "<center><h2>Please wait, your order is being processed and you";
    echo " will be redirected to the paypal website.</h2></center>\n";
    echo "<form method=\"post\" name=\"paypal_form\" ";
    echo "action=\"".$this->paypal_url."\">\n";


    foreach ($this->fields as $name => $value)
    {
    echo "<input type=\"hidden\" name=\"$name\" value=\"$value\"/>\n";
    }
    echo "<center><br/><br/>If you are not automatically redirected to ";
    echo "paypal within 5 seconds...<br/><br/>\n";
    echo "<input type=\"submit\" value=\"Click Here\"></center>\n";
    echo "</body></html>\n";

    }

    function validate_ipn() {



    $url_parsed=parse_url($this->paypal_url);



    $post_string = '';
    foreach ($_POST as $field=>$value) {
    $this->ipn_data["$field"] = $value;
    $post_string .= $field.'='.urlencode(stripslashes($value)).'&';
    }
    $post_string.="cmd=_notify-validate";



    $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
    if(!$fp) {

    $this->last_error = "fsockopen error no. $errnum: $errstr";
    $this->log_ipn_results(false);
    return false;

    } else {


    fputs($fp, "POST $url_parsed[path] HTTP/1.1\r\n");
    fputs($fp, "Host: $url_parsed[host]\r\n");
    fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
    fputs($fp, "Content-length: ".strlen($post_string)."\r\n");
    fputs($fp, "Connection: close\r\n\r\n");
    fputs($fp, $post_string . "\r\n\r\n");



    while(!feof($fp)) {
    $this->ipn_response .= fgets($fp, 1024);
    }


    fclose($fp);


    }

    if (eregi("VERIFIED",$this->ipn_response)) {

    $this->log_ipn_results(true);
    return true;

    } else {


    $this->last_error = 'IPN Validation Failed.';
    $this->log_ipn_results(false);
    return false;

    }

    }

    function log_ipn_results($success) {

    if (!$this->ipn_log) return; // is logging turned off?


    $text = '['.date('m/d/Y g:i A').'] - ';

    if ($success) $text .= "SUCCESS!\n";
    else $text .= 'FAIL: '.$this->last_error."\n";


    $text .= "IPN POST Vars from Paypal:\n";
    foreach ($this->ipn_data as $key=>$value) {
    $text .= "$key=$value, ";
    }


    $text .= "\nIPN Response from Paypal Server:\n ".$this->ipn_response;


    $fp=fopen($this->ipn_log_file,'a');
    fwrite($fp, $text . "\n\n");


    fclose($fp);
    }


    function dump_fields() {




    echo "<h3>paypal_class->dump_fields() Output:</h3>";
    echo "<table width=\"95%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">
    <tr>
    <td bgcolor=\"black\"><b><font color=\"white\">Field Name</font></b></td>
    <td bgcolor=\"black\"><b><font color=\"white\">Value</font></b></td>
    </tr>";

    ksort($this->fields);
    foreach ($this->fields as $key => $value) {
    echo "<tr><td>$key</td><td>".urldecode($value)."&nbsp;</td></tr>";
    }

    echo "</table><br>";
    }
    }






    - - - Updated - - -

    I just wanted to let somebody who knows what they are doing do this so I do not end up taking somebody's money without them getting anything in return.

  4. #4
    R.I.P Millercent FatalLulz is offline
    Grand MasterRank
    Nov 2012 Join Date
    AustraliaLocation
    2,240Posts

    Re: [HELP] Automatic PayPal IPN VIP Giver

    Where it says;
    PHP Code:
    case '1':

    $cost '0.01'//Cost of VIP
    $wut 'VIP+'//Name of Package 
    Add this below,
    PHP Code:
    case '2':

    $cost '0.02'//Cost of VIP
    $wut 'VIP++'//Name of Package

    break; 
    You just made a new case which in theory is making another level of VIP. Little bit more to do how ever.

    Below where it says;
    PHP Code:
    default:

    $cost '0.01'//Cost of VIP again


    break; 
    Add;
    PHP Code:
    case'2':

    $cost '0.01'//Cost of VIP again


    break; 
    Below where it says;
    PHP Code:
    case '1':

    $coins '2000'//Amount of coins they recieve

    $pixels '10'//Amount of pixels they recieve

    $rank '2'//Your Hotel's VIP rank (2 is default for Pheonix)


    break; 
    Add;
    PHP Code:
    case '2':

    $coins '2000'//Amount of coins they recieve

    $pixels '10'//Amount of pixels they recieve

    $rank '3'//Your Hotel's VIP rank (2 is default for Pheonix)


    break; 
    In theory should work. Try buying package number 2 providing you edit the details to match yours. Will only cost you 2 cents and you'll get it back.

  5. #5

    Re: [HELP] Automatic PayPal IPN VIP Giver

    Okay, the payment works, but now my question is how would I make there be a line like
    mysql_query("UPDATE users SET vip = '1', rank = '2', credits = credits + 2000, activity_points = activity_points + 10 WHERE username = '".$p->ipn_data['custom']."' LIMIT 1");
    for each VIP package. Theres 3 VIP packages total, and the highest VIP rank number is 4.



Advertisement