Jump to content


Photo

ipn handler is responding always invalid?


  • This topic is locked This topic is locked
1 reply to this topic

#1 webdyn

webdyn

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 07 February 2003 - 02:37 AM

Hi
I am using the following code as an ipn handler. but when some one do transaction, data is not posted back to this page, kindly help me... otherwise i will get fired..
language= PHP

// here is the form sending data to pay pal
========================================================
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="payments@paybyus.com">
<input type="hidden" name="notify_url" value="http://www.paybyus.com/validate_transaction.php">
<input type="hidden" name="cancel_return" value="http://www.paybyus.com/cancel_transaction.php">
<input type="hidden" name="return" value="http://www.paybyus.com/cardgift_detail.php">
<input type="hidden" name="image_url"
value="https://www.paybyus.com/s_images/s_logo.jpg">
<input type="hidden" name="item_name" value="Card Gifts">
<input type="hidden" name="item_number" value="CGT">
<input type="hidden" name="amount" value="<?=$grossDollarAmount?>">
<input type="hidden" name="custom" value="<?=$customValue?>">
<input type="hidden" name="invoice" value="<?=$bid?>">
<input type="image" src="images/sendnow.gif" border="0" name="submit" alt="Send Card Gift">
</form>
=========================================================================
// here is the ipn handler code i am getting invalid every time.
=========================================================================
<?PHP

// include class
include("form_validator.inc");
include_once("db_connector.inc");
include_once("email_handler.inc");
include("logger.inc");


$formValidator = new form_validator();
$dbConnector = new db_connector();
$eHandler = new email_handler();
$commissionPercent=5;

// Read the Posted IPN, filter Restricted vars and Add "cmd" for Post back Validation
$postvars = array();
$restrict = array ('receiver_email','item_name','item_number','quantity','invoice','custom','option_name1','option_selection1','option_name2','option_selection2','num_cart_items','payment_status','pending_reason','payment_date','settle_amount','settle_currency','exchange_rate','payment_gross','payment_fee','mc_gross','mc_fee','mc_currency','txn_id','txn_type','first_name','last_name','address_street','address_city','address_state','address_zip','address_country','address_status','payer_email','payer_id','payer_status','payment_type','notify_version','verify_sign','subscr_date','period1','period2','period3','amount1','amount2','amount3','recurring','reattempt','retry_at','recur_times','username','password','subscr_id');
$ppdata="";
while (list ($key, $value) = each ($_POST)){
if (in_array ($key, $restrict)) {
$postvars[] = $key;
$ppdata.=$key." ";
}
}

$req = 'cmd=_notify-validate';
for($var = 0; $var < count ($postvars); $var++){
$postkey = $postvars[$var];
$postvalue = $$postvars[$var];
$req .= "&" . $postkey . "=" . urlencode ($postvalue);
}

$fp = fsockopen ("www.paypal.com", 80, $errno, $errstr, 30);
$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";
if (!$fp && !$pme){
//Problem:
include("error_reporter.inc");


exit;
}else{//1
$receiver_email = trim($_POST['receiver_email']);
$item_name = trim($_POST['item_name']);
$item_number = trim($_POST['item_number']);
$invoice = trim($_POST['invoice']);
$custom = trim($_POST['custom']);
$payment_status = $_POST['payment_status'];
$pending_reason = $_POST['pending_reason'];
$payment_date = $_POST['payment_date'];
$payment_gross = $_POST['payment_gross'];
$payment_fee = $_POST['payment_fee'];
$txn_id = $_POST['txn_id'];
$txn_type = $_POST['txn_type'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$address_street = $_POST['address_street'];
$address_city = $_POST['address_city'];
$address_state = $_POST['address_state'];
$address_zip = $_POST['address_zip'];
$address_country = $_POST['address_country'];
$address_status = $_POST['address_status'];
$payer_email = $_POST['payer_email'];
$payer_status = $_POST['payer_status'];
$payment_type = $_POST['payment_type'];
$notify_version = $_POST['notify_version'];
$verify_sign = $_POST['verify_sign'];
$amount = $_POST['amount'];

//Getting Response about transaction VERIFIED OR INVALID
fputs ($fp, $header . $req);
while (!feof($fp)){//while
$res = fgets ($fp, 1024);
$res = trim ($res); // Required on some Environments
if (strcmp ($res, "VERIFIED") == 0){//valid
if($payment_status =="Completed"){
if($item_number=="CSH"){//casg gifts
include("cashgift_handler.inc");
}elseif ($item_number=="EDU"){
include("education_handler.inc");
}elseif ($item_number=="DON"){
include("donation_handler.inc");
}elseif ($item_number=="CGT"){
include("cardgift_handler.inc");
}
}elseif ($payment_status =="Pending") {
include("pending_payments_handler.inc");
}
}//validae
elseif (strcmp($res, "INVALID")== 0){
include("invalid_payments_handler.inc");
}//
}// while
// Terminate the Socket connection and Exit
fclose ($fp);
exit;
}//1

?>
================================================================

Waiting a kind reply

regards
dyn

#2 paypal_pb

paypal_pb

    Advanced Member

  • Members
  • 2,960 posts

Posted 07 February 2003 - 12:23 PM

Test with this:

<form method="post" action="http://www.paybyus.com/validate_transaction.php">
<input type="submit" name="" value="Test IPN">
<input type="hidden" name="payment_date" value="17:53:45 Nov 5, 2002 PST">
<input type="hidden" name="txn_type" value="web_accept">
<input type="hidden" name="last_name" value="Breitenbach">
<input type="hidden" name="item_name" value="">
<input type="hidden" name="payment_gross" value="0.01">
<input type="hidden" name="mc_currency" value="USD">
<input type="hidden" name="payment_type" value="instant">
<input type="hidden" name="verify_sign" value="AlWncXKLadIepzMosHhM.VWxC0Z6AZYI0ynXRnEUma0d3RMC.TXWaJro">
<input type="hidden" name="payer_status" value="unverified">
<input type="hidden" name="payer_email" value="pb-test@paypal.com">
<input type="hidden" name="txn_id" value="01G32341KC3727119">
<input type="hidden" name="first_name" value="Patrick">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="receiver_email" value="pb-sell@paypal.com">
<input type="hidden" name="payer_id" value="QGVDAFGZ9XHLJ">
<input type="hidden" name="payment_method" value="non_cc">
<input type="hidden" name="item_number" value="">
<input type="hidden" name="payment_status" value="Completed">
<input type="hidden" name="mc_gross" value="0.01">
<input type="hidden" name="custom" value="">
<input type="hidden" name="notify_version" value="1.4">
</form>


Patrick Breitenbach
PayPal, Inc.
Dev Net: https://www.paypal.com/pdn




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users