Free Ringtones - Personal Loans - Credit Counseling - Credit Report - Loans

PDA

View Full Version : IPN and Sandbox help.


joesgraphics
Mar 6th 2007, 8:04 am
HI im trying to get my php ipn script to work with the paypal Sandbox for testing but when i go to pay with the Sandbox paypal account its asks for a creditcard info when i login could any of you see if my script is setup right



ipn_res.php:
<?php
include ("../_config.php");


// database settings
$host="localhost";
$ln="bob";
$pw="No";
$db="ummm";
//umm would i realy say hehe


$active = 'true';

// paypal email
$paypal_email = "paypal addy";

// email address where script should send notifications
$error_email = "bob@bob.bobo.com";

// email header
$em_headers = "From: from_name <from_email>\n";
$em_headers .= "Reply-To: from_email\n";
$em_headers .= "Return-Path: from_email\n";
$em_headers .= "Organization: company_name\n";
$em_headers .= "X-Priority: 3\n";


// -----------------


require("ipn_cls.php");

$paypal_info = $HTTP_POST_VARS;
$paypal_ipn = new paypal_ipn($paypal_info);

foreach ($paypal_ipn->paypal_post_vars as $key=>$value) {
if (getType($key)=="string") {
eval("\$$key=\$value;");
}
}

$paypal_ipn->send_response();
$paypal_ipn->error_email = $error_email;

if (!$paypal_ipn->is_verified()) {
$paypal_ipn->error_out("Bad order (PayPal says it's invalid)" . $paypal_ipn->paypal_response , $em_headers);
die();
}


switch( $paypal_ipn->get_payment_status() )
{
case 'Pending':

$pending_reason=$paypal_ipn->paypal_post_vars['pending_reason'];

if ($pending_reason!="intl") {
$paypal_ipn->error_out("Pending Payment - $pending_reason", $em_headers);
break;
}


case 'Completed':

$qry= "SELECT i.mc_gross, i.mc_currency FROM item_table as i WHERE i.item_number='$item_number'";
mysql_connect("$host","$ln","$pw") or die("Unable to connect to database");
mysql_select_db("$db") or die("Unable to select database");
$res=mysql_query ($qry);
$config=mysql_fetch_array($res);

if ($paypal_ipn->paypal_post_vars['txn_type']=="reversal") {
$reason_code=$paypal_ipn->paypal_post_vars['reason_code'];
$paypal_ipn->error_out("PayPal reversed an earlier transaction.", $em_headers);
// you should mark the payment as disputed now
} else {

if (
(strtolower(trim($paypal_ipn->paypal_post_vars['business'])) == $paypal_email) && (trim($mc_currency)==$config['mc_currency']) && (trim($mc_gross)-$tax == $quantity*$config['mc_gross'])
) {

$qry="INSERT INTO $tablename VALUES (0 , '$link', '$bid', '$email', '$active', '$title', '$desc1', '$desc2', '$desc3', '$name', '$date', '$udate')";


if (mysql_query($qry)) {

$paypal_ipn->error_out("This was a successful transaction", $em_headers);
// you should add your code for sending out the download link to your customer at $payer_email here.

} else {
$paypal_ipn->error_out("This was a duplicate transaction", $em_headers);
}
} else {
$paypal_ipn->error_out("Someone attempted a sale using a manipulated URL", $em_headers);
}
}
break;

case 'Failed':
// this will only happen in case of echeck.
$paypal_ipn->error_out("Failed Payment", $em_headers);
break;

case 'Denied':
// denied payment by us
$paypal_ipn->error_out("Denied Payment", $em_headers);
break;

case 'Refunded':
// payment refunded by us
$paypal_ipn->error_out("Refunded Payment", $em_headers);
break;

case 'Canceled':
// reversal cancelled
// mark the payment as dispute cancelled
$paypal_ipn->error_out("Cancelled reversal", $em_headers);
break;

default:
// order is not good
$paypal_ipn->error_out("Unknown Payment Status - " . $paypal_ipn->get_payment_status(), $em_headers);
break;

}

?>


AND




ipn_cls.php:
<?php

class paypal_ipn
{
var $paypal_post_vars;
var $paypal_response;
var $timeout;

var $error_email;

function paypal_ipn($paypal_post_vars) {
$this->paypal_post_vars = $paypal_post_vars;
$this->timeout = 120;
}

function send_response()
{
$fp = @fsockopen( "www.sandbox.paypal.com", 80, &$errno, &$errstr, 120 );

if (!$fp) {
$this->error_out("PHP fsockopen() error: " . $errstr , "");
} else {
foreach($this->paypal_post_vars AS $key => $value) {
if (@get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
$values[] = "$key" . "=" . urlencode($value);
}

$response = @implode("&", $values);
$response .= "&cmd=_notify-validate";

fputs( $fp, "POST /cgi-bin/webscr HTTP/1.0\r\n" );
fputs( $fp, "Content-type: application/x-www-form-urlencoded\r\n" );
fputs( $fp, "Content-length: " . strlen($response) . "\r\n\n" );
fputs( $fp, "$response\n\r" );
fputs( $fp, "\r\n" );

$this->send_time = time();
$this->paypal_response = "";

// get response from paypal
while (!feof($fp)) {
$this->paypal_response .= fgets( $fp, 1024 );

if ($this->send_time < time() - $this->timeout) {
$this->error_out("Timed out waiting for a response from PayPal. ($this->timeout seconds)" , "");
}
}

fclose( $fp );

}

}

function is_verified() {
if( ereg("VERIFIED", $this->paypal_response) )
return true;
else
return false;
}

function get_payment_status() {
return $this->paypal_post_vars['payment_status'];
}

function error_out($message, $em_headers)
{

$date = date("D M j G:i:s T Y", time());
$message .= "\n\nThe following data was received from PayPal:\n\n";

@reset($this->paypal_post_vars);
while( @list($key,$value) = @each($this->paypal_post_vars)) {
$message .= $key . ':' . " \t$value\n";
}
mail($this->error_email, "[$date] paypay_ipn notification", $message, $em_headers);

}
}

?>


if that helps atall hehe

and the form im useing to test is



<center><form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="POST">
To pay with PayPal now please click on the PayPal
icon below:
<p>
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="bn" value="webasyst">
<input type="hidden" name="business" value="paypal@addy.co.uk">

<input type="hidden" name="item_name" value="0"><br />
Name: &nbsp;<input type="text" name="Name" value=""><br />
Email: &nbsp;<input type="text" name="email" value=""><br />
Link: &nbsp;<input type="text" name="link" value="http://"><br />
Title: &nbsp;<input type="text" name="title" value=""><br />
Desc1: &nbsp;<input type="text" name="desc1" value=""><br />
Desc2: &nbsp;<input type="text" name="desc2" value=""><br />
Desc3: &nbsp;<input type="text" name="desc3" value=""><br />
Bid: &nbsp;<input type="text" name="amount" value=""><br />
<input type="hidden" name="date" value="<?php echo date("d-M-Y"); ?>"><br />
<input type="hidden" name="udate" value="<?php echo date("d-M-Y"); ?>"><br />
<input type="image" name="submit" src="http://images.paypal.com/images/x-click-but01.gif" alt="Pay with PayPal">
</form></center>



If any 1 could help it would be great.

Kalyse
Mar 6th 2007, 1:04 pm
Just enter details.

If its the sandbox it wont charge you.

I use all my legit details on Sandbox.

Louis11
Mar 6th 2007, 1:26 pm
Though your script may have an error (I didn't check it), chances are it's not your script. It's the sandbox. What sandbox are you using?

I believe if you put in fake information it will work, and get you passed the CC screen. You then have to add funds in your account window. Make sure you 'clear the transaction' after you have added them :)

joesgraphics
Mar 7th 2007, 8:48 am
UMm i did use all the right detials but i will sign up again with other details and try again hehe thanks for your help and the script works as far as i no of.

joesgraphics
Mar 7th 2007, 12:02 pm
Are you ment to get an email if you use the sandbox when u sign up iv signed up 3 times now and it still asking for credit card details and if i do it takes the money how can this happen i fort sandbox is not a working model.

Choller
Mar 7th 2007, 12:28 pm
There is a generic (fake) number you can use as creditcard number. Don't know what this number is anymore, I'd search the paypal forum if I was you. It there somewhere.

ericeric
Mar 7th 2007, 1:33 pm
Hey,
just go to your sanbox account.
goto profile.
select credit cards.
the cc number will be assigned automaticaly.
click save
u r done;)

joesgraphics
Mar 7th 2007, 3:34 pm
Ok done that and tested it im geting the email saying every think is payed for from the script but it does not submit the data to the database could any of you see if there is sumink wrong with the script and iv sore on other sites once u have pages u can click return to site i dont get that what do u do to get that showing asfar as i no of it is a hidden input but i cant remeber what you call it.