Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Regular Coder
    Join Date
    Oct 2011
    Posts
    113
    Thanks
    9
    Thanked 1 Time in 1 Post

    Paypal PHP code not working

    This is a simple code for a rank purchase. But it's not working any ideas?
    Paypal says there is errors so something is wrong with my code.
    I'm using this with my IPN

    PHP Code:
    <!DOCTYPE html>
    <head>
    <title>Shop</title>
    <style type="text/css">
    .textbox {
        width:170px;
        border-radius:3px;
        border:2px solid #5797FF;
        font-size:13px;
        background-color:#E6E6E6;
    }
    .text {
        font-family:Arial;
        font-size:17px;
        color:#BFBFBF;
        text-shadow: 2px 2px 2px #fff;
    }
    .button {
        border:2px solid #006B02;
        background-color:#69966A;
        color:#FFF;
        height:30px;
            text-shadow: 2px 2px 2px #000;
        width:170px;
        border-radius:5px;
        padding:3px;
    }
    .button:hover {
        border:2px solid #001B02;
        background-color:#006B02;
        color:#FFF;
        height:30px;
        width:170px;
        text-shadow: 2px 2px 2px #000;
        border-radius:5px;
        padding:3px;
    }
    </style>
    </head>
    <body>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <img src="donate.png" alt="X" />
    <Br /><Br />
    <form action="https://www.paypal.com/cgi-bin/webscr" method="POST">
    <span class="text">Minecraft Username:</span><br />
    <input type="text" name="username" class="textbox"><br /><br />
    <select name="rank" class="textbox">
    <optgroup label="Ranks">

    <option value="Citizen">Citizen | $5.00</option>
    <option value="Supporter">Supporter | $20.00</option>
    <option value="Elite">Elite | $40.00</option>
    <option value="Master">Master | $70.00</option>
    <option value="Executive">Executive | $120.00</option>
    <option value="Exclusive">Exclusive | $270.00</option>
    <option value="Ultimate">Ultimate | $500.00</option>
    </optgroup>
    </select>
    <?php
       $rank 
    = @$_POST['rank'];
       
    $username = @$_POST['username'];

    /*
    switch($rank) {

     case "Citizen":
      $price = 5;
     break;

     case "Supporter":
      $price = 20;
     break;

     case "Elite":
      $price = 40;
     break;

     case "Master":
      $price = 70;
     break;

     case "Executive":
      $price = 120;
     break;

     case "Exclusive":
      $price = 270;
     break;

     case "Ultimate":
      $price = 500;
     break;

    }
    */

       
    if ($rank == "Citizen") {
          
    $price 5;
       } if (
    $rank == "Supporter") {
          
    $price 20;
       } if (
    $rank == "Elite") {
          
    $price 40;
       } if (
    $rank == "Master") {
          
    $price 70;
       } if (
    $rank == "Executive") {
          
    $price 120;
       } if (
    $rank == "Exclusive") {
          
    $price 270;
       } if (
    $rank == "Ultimate") {
          
    $price 500;
       }

    ?>
    <br />
    <br />
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="vernk@techie.com">
    <input type="hidden" name="item_name" value="<?php echo $rank?>">
    <input type="hidden" name="item_number" value="1">
    <input type="hidden" name="amount" value="<?php echo $price?>">
    <input type="hidden" name="no_shipping" value="1">
    <input type="hidden" name="no_note" value="1">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="lc" value="US">
    <input type="hidden" name="bn" value="PP-BuyNowBF">
    <input type="hidden" name="return" value="http://blitz-gaming.net/mc">
    <input type="hidden" name="cancel_return" value="http://blitz-gaming.net/mc">
    <input type="hidden" name="rm" value="2">
    <input type="hidden" name="notify_url" value="http://blitz-gaming.net/paypal/ipn.php" />
    <input type="hidden" name="custom" value="<?php echo $username?>">
    <input type="submit" class="button" name="submit" value="Purchase">
    </form>
    </body>
    </html>

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    What are the errors you are getting? We will likely need to see your ipn.php code. Remove and sensitive credentials.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Oct 2011
    Posts
    113
    Thanks
    9
    Thanked 1 Time in 1 Post
    It's not the IPN, but if you try to run that code on the server it totally fails, it doesn't generate the price, item name, or the custom then paypal says the form is invalid or something idk what's wrong with the code

  • #4
    Regular Coder
    Join Date
    Oct 2011
    Posts
    113
    Thanks
    9
    Thanked 1 Time in 1 Post
    Help please *bump*

    if you want to test the script.

    Here is the link to what happens. Looks like the fields don't get filled out

    http://blitz-gaming.net/paypal/
    Last edited by Vernk; 01-22-2012 at 01:00 AM.

  • #5
    Regular Coder
    Join Date
    Oct 2011
    Posts
    113
    Thanks
    9
    Thanked 1 Time in 1 Post
    Here is my ipn.php

    PHP Code:
        <?php
        
    // Using Send Function - send ("/ban tester");
        
    function send($cmd){
        
    $cmd str_replace(chr(32),"%20",$cmd);
        
    $ch curl_init();
        
    curl_setopt($chCURLOPT_URL"http://cosmicmc.net:8084/data.json?req=sendchat&message=" $cmd);
        
    curl_setopt($chCURLOPT_HEADER0);
        
    curl_setopt($chCURLOPT_USERPWD"admin:passwordcovered");
        
    curl_exec($ch);
        
    curl_close($ch);
        }
        function 
    write2LogFile$message$file "mylog.txt" ) { $file fopen($file"a"); fputs($file"[".date('d-m-Y')."] ".$message."\n"); fclose($file); }
        
    $req 'cmd=_notify-validate';
        foreach (
    $_POST as $key => $value)
        {
                
    $value urlencode(stripslashes($value));
                
    $req .= "&$key=$value";
        }
        
    $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.sandbox.paypal.com'80$errno$errstr30);
        if (!
    $fp) {
                
    write2LogFile"ERROR Can not connect to paypal!" );
        }
        else
        {
                
    fputs ($fp$header $req);
                while (!
    feof($fp))
                {
                        
    $res fgets ($fp1024);
                        if (
    strcmp ($res"VERIFIED") == 0)
                        {
                                
    $payment_status $_POST['payment_status'];
                                
    $transaction_id $_POST['txn_id'];
                                
    $payer_email $_POST['payer_email'];
                                
    $custom_field $_POST['custom'];
                                
    $item_name $_POST['item_name'];
                                
    $item_number $_POST['item_number'];
                                
    $payment_amount $_POST['mc_gross'];
                                
    $payment_currency $_POST['mc_currency'];
                                
    $receiver_email $_POST['receiver_email'];
         
                                if (
    $receiver_email == 'vernk@techie.com') {
                                if ( 
    $payment_status == 'Completed' )
                                {           
                                        
    // Payment/Donation is completed. Give points here
                                         
    send ("" .$custom_field" has just completed a purchase of " .$payment_amount" for rank " .$item_name"! Congratulations!");
                                         
    send ("/rank " .$custom_field" " .$item_name");
                                         
                                }
                                }
                                else if ( $payment_status == 'Canceled_Reversal' )
                                {
                                        // The user was dumb enough to dispute for a refund ban him here.
                                        send ("
    /ban " .$custom_field. " AutoPaypal dispute/reversal of rank.");
                                        
                                }
                        }
                }
                fclose ($fp);
        }
        ?>

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    When the button appears to pay it,
    view the HTML that shows the form going to paypal.
    Copy and post it so we can see it.

    There must be a format problem ...
    Such as your dollar amounts ... maybe you need them like 70.00 instead of 70 ?

  • #7
    Regular Coder
    Join Date
    Oct 2011
    Posts
    113
    Thanks
    9
    Thanked 1 Time in 1 Post
    No you don't need it
    It looks like something wrong with the insertting idk try the demo and see

  • #8
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    You need two forms ...

    1) the form where they select item and price.
    this form sends the POST data to the next one.
    You can do some javascripting here to submit this form to the
    paypal button form ... making the "pay now" button appear.

    PHP Code:
    <form action="button.php" method="post">
    <
    span class="text">Minecraft Username:</span><br /> 
    <
    input type="text" name="username" class="textbox"><br /><br /> 
    <
    select name="rank" class="textbox"
    <
    optgroup label="Ranks"

    <
    option value="Citizen">Citizen | $5.00</option
    <
    option value="Supporter">Supporter | $20.00</option
    <
    option value="Elite">Elite | $40.00</option
    <
    option value="Master">Master | $70.00</option
    <
    option value="Executive">Executive | $120.00</option
    <
    option value="Exclusive">Exclusive | $270.00</option
    <
    option value="Ultimate">Ultimate | $500.00</option
    </
    optgroup
    </
    select>
    <
    input type="submit" name="submit" value="Continue to Checkout"
    </
    form

    2) the next form is just the paypal "pay now" button
    with the fields entered in, using the POSTed variables
    from the first form.

    Call this script "button.php" ..
    PHP Code:
    <?php
    $rank
    =$_POST['rank'];
    $price=$_POST['price'];
    $username=$_POST['username'];
    if (
    $rank == "Citizen") { 
          
    $price 5
       } if (
    $rank == "Supporter") { 
          
    $price 20
       } if (
    $rank == "Elite") { 
          
    $price 40
       } if (
    $rank == "Master") { 
          
    $price 70
       } if (
    $rank == "Executive") { 
          
    $price 120
       } if (
    $rank == "Exclusive") { 
          
    $price 270
       } if (
    $rank == "Ultimate") { 
          
    $price 500

    ?>
    <form action="https://www.paypal.com/cgi-bin/webscr" method="POST">
    <input type="hidden" name="cmd" value="_xclick"> 
    <input type="hidden" name="business" value="vernk@techie.com"> 
    <input type="hidden" name="item_name" value="<?php echo $rank?>"> 
    <input type="hidden" name="item_number" value="1"> 
    <input type="hidden" name="amount" value="<?php echo $price?>"> 
    <input type="hidden" name="no_shipping" value="1"> 
    <input type="hidden" name="no_note" value="1"> 
    <input type="hidden" name="currency_code" value="USD"> 
    <input type="hidden" name="lc" value="US"> 
    <input type="hidden" name="bn" value="PP-BuyNowBF"> 
    <input type="hidden" name="return" value="http://blitz-gaming.net/mc"> 
    <input type="hidden" name="cancel_return" value="http://blitz-gaming.net/mc"> 
    <input type="hidden" name="rm" value="2"> 
    <input type="hidden" name="notify_url" value="http://blitz-gaming.net/paypal/ipn.php" /> 
    <input type="hidden" name="custom" value="<?php echo $username?>"> 
    <input type="submit" class="button" name="submit" value="Purchase"> 
    </form>

  • #9
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    I just tried this and it worked fine. I entered a "username", when to pay, and paypal had everything in there with the exception of the custom field.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #10
    Regular Coder
    Join Date
    Oct 2011
    Posts
    113
    Thanks
    9
    Thanked 1 Time in 1 Post
    Is there a reason why my IPN doesn't work?
    The send function works and sends messages/commands ingame
    But when someone finished purchasing the rank nothing happens.

    Can I use that cURL in the IPN to send or will it not work?

    Also, apparently it doesnt work with developer.paypal.com when I try to do the IPN form there

    I came across another problem:
    As you can see I put the widget in the sidebar, http://blitz-gaming.net/mc/
    But when you hit complete purchase it doesn't take you to Paypal.
    This is using an iframe.
    This URL works : http://blitz-gaming.net/paypal
    It was working before I don't know why it doesn't take you to paypal anymore.
    Last edited by Vernk; 01-23-2012 at 01:25 AM.

  • #11
    Regular Coder
    Join Date
    Oct 2011
    Posts
    113
    Thanks
    9
    Thanked 1 Time in 1 Post
    Bump waiting for anyone to help

  • #12
    Regular Coder
    Join Date
    Oct 2011
    Posts
    113
    Thanks
    9
    Thanked 1 Time in 1 Post
    Bump..

  • #13
    Regular Coder
    Join Date
    Jan 2012
    Posts
    271
    Thanks
    2
    Thanked 65 Times in 65 Posts
    your ipn code has a syntax error

    this
    PHP Code:
    send ("/rank " .$custom_field" " .$item_name"); 
    should be
    PHP Code:
    send ("/rank " .$custom_field" " .$item_name); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •