...

View Full Version : Paypal PHP code not working



Vernk
01-21-2012, 08:31 PM
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


<!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>

_Aerospace_Eng_
01-21-2012, 08:43 PM
What are the errors you are getting? We will likely need to see your ipn.php code. Remove and sensitive credentials.

Vernk
01-21-2012, 09:40 PM
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

Vernk
01-22-2012, 12:46 AM
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/

Vernk
01-22-2012, 01:42 AM
Here is my ipn.php


<?php
// Using Send Function - send ("/ban tester");
function send($cmd){
$cmd = str_replace(chr(32),"%20",$cmd);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://cosmicmc.net:8084/data.json?req=sendchat&message=" . $cmd);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_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, $errstr, 30);
if (!$fp) {
write2LogFile( "ERROR Can not connect to paypal!" );
}
else
{
fputs ($fp, $header . $req);
while (!feof($fp))
{
$res = fgets ($fp, 1024);
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. " Auto: Paypal dispute/reversal of rank.");

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

mlseim
01-22-2012, 01:46 AM
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 ?

Vernk
01-22-2012, 03:14 AM
No you don't need it
It looks like something wrong with the insertting idk try the demo and see

mlseim
01-22-2012, 03:48 AM
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.



<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
$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>

_Aerospace_Eng_
01-22-2012, 06:34 AM
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.

Vernk
01-22-2012, 11:13 PM
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.

Vernk
01-24-2012, 12:37 AM
Bump waiting for anyone to help :(

Vernk
01-26-2012, 12:57 AM
Bump..

jmj001
01-26-2012, 04:55 AM
your ipn code has a syntax error

this

send ("/rank " .$custom_field. " " .$item_name. ");

should be

send ("/rank " .$custom_field. " " .$item_name);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum