ElvansX
11-22-05, 10:06 AM
Hi,
I did my searched but couldnt find any post/thread that similar with my problem, so i start this.
Senario:
I want to make a donation for my site and a member who donate will get a access for download. So i login to my paypal account, and enable IPN and auto return. i created a paypal button, and put it somewhere on my website. It look like this :
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="email@domain.com">
<input type=hidden name=item_name value="Subscribe">
<input type=hidden name=amount value="1">
<input type=hidden name=item_number value="$itemnumber"11282>
<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="image" src="https://www.paypal.com/en_US/i/btn/x-click-but23.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
* no problem with this button.
then the code i copied from paypal and modified a bit to check whick part is wrong. Notice
echo "CHK #<br>";
the ipn code:
<?php
// 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.sandbox.paypal.com', 80, $errno, $errstr, 30);
// assign posted variables to local variables
$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'];
if (!$fp) {
echo "CHK 1<br>";
} else {
echo "CHK 2<br>";
fputs ($fp, $header . $req);
echo "CHK 3<br>";
$anime_donate = 5;
$userid = 2;
global $db;
while (!feof($fp)) {
//echo "CHK 4<br>";
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
echo "CHK 5<br>";
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
}
else if (strcmp ($res, "INVALID") == 0) {
echo "CHK 6<br>";
// log for manual investigation
}
}
echo "CHK 7<br>";
fclose ($fp);
echo "CHK 8<br>";
}
?>
The process:
user will click the paypal button and redirrect to paypal page. They will login with paypal account and after finish, paypal will redirrect them back to my page(use auto-return) which is the ipn page(code above).
The result for the page should be blank, but i insert the
echo "CHK #<br>";
to see which part is wrong.
the result is here:
CHK 2
CHK 3
CHK 4
CHK 4
CHK 4
CHK 4
CHK 4
CHK 4
CHK 4
CHK 4
CHK 4
CHK 6
CHK 7
CHK 8
Problem:
As you can see >> CHK 5 is missing, and want to put my code inside to auto validate my member so that they can start download after donate.
Am i missing something or powweb didnt support/enable fsockopen or anything else?
im still newbie with PHP, kindly please explain to me step by step.
Thank you.
I did my searched but couldnt find any post/thread that similar with my problem, so i start this.
Senario:
I want to make a donation for my site and a member who donate will get a access for download. So i login to my paypal account, and enable IPN and auto return. i created a paypal button, and put it somewhere on my website. It look like this :
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="email@domain.com">
<input type=hidden name=item_name value="Subscribe">
<input type=hidden name=amount value="1">
<input type=hidden name=item_number value="$itemnumber"11282>
<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="image" src="https://www.paypal.com/en_US/i/btn/x-click-but23.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
* no problem with this button.
then the code i copied from paypal and modified a bit to check whick part is wrong. Notice
echo "CHK #<br>";
the ipn code:
<?php
// 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.sandbox.paypal.com', 80, $errno, $errstr, 30);
// assign posted variables to local variables
$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'];
if (!$fp) {
echo "CHK 1<br>";
} else {
echo "CHK 2<br>";
fputs ($fp, $header . $req);
echo "CHK 3<br>";
$anime_donate = 5;
$userid = 2;
global $db;
while (!feof($fp)) {
//echo "CHK 4<br>";
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
echo "CHK 5<br>";
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
}
else if (strcmp ($res, "INVALID") == 0) {
echo "CHK 6<br>";
// log for manual investigation
}
}
echo "CHK 7<br>";
fclose ($fp);
echo "CHK 8<br>";
}
?>
The process:
user will click the paypal button and redirrect to paypal page. They will login with paypal account and after finish, paypal will redirrect them back to my page(use auto-return) which is the ipn page(code above).
The result for the page should be blank, but i insert the
echo "CHK #<br>";
to see which part is wrong.
the result is here:
CHK 2
CHK 3
CHK 4
CHK 4
CHK 4
CHK 4
CHK 4
CHK 4
CHK 4
CHK 4
CHK 4
CHK 6
CHK 7
CHK 8
Problem:
As you can see >> CHK 5 is missing, and want to put my code inside to auto validate my member so that they can start download after donate.
Am i missing something or powweb didnt support/enable fsockopen or anything else?
im still newbie with PHP, kindly please explain to me step by step.
Thank you.