retrieve value of paypal custom var
does anyone know how to retrieve hidden input custom var of the paypal express checkout once the payment redirects back the user to the thank you page ?, here's my code
<form action="https://sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="test@gmail.com">
<input type="hidden" name="item_name" value="<?php echo $this->input->get('GeneralHealth').'test'; ?>">
<input type="hidden" name="item_number" value="<?php echo $this->input->get('GeneralHealth'); ?>">
&开发者_JAVA技巧lt;input type="hidden" name="amount" value="<?php foreach($query3->result() as $row){echo $row->price; } ?>">
<input type="hidden" name="quantity" value="1" disabled="disabled">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="custom" value="<?php $id = $this->ion_auth->get_user(); echo $id->id; ?>" />
<input type=hidden name=notify_url value="http://ci/paragon/site/thankyou" />
<input type="hidden" name="return" value="http://ci/paragon/index.php/site/thankyou" / >
<input type="image" id="checkout" src="https://www.paypal.com/images/x-click-but6.gif" Border="0" name=submit><br>
<input type="hidden" name="add" value="1"></form>
there, based fromt he code above, how will I get the value of the custom hidden field ?
From my experience, you execute one of PayPal's API calls to receive the transaction details based on your PayPal credentials and a token generated by PayPal as a result of a successful purchase. Check out Step 2C.
In your own PayPal account, you should have specified a script PayPal will contact upon confirmation of the transaction. That same page should open another connection with PayPal again, to confirm that the source is valid. From the first request, you should receive all of the information you would need.
Here is the code that I use:
//posts transaction data using fsockopen.
function fsockPost($url,$data) {
//Parse url
$web=parse_url($url);
//build post string
foreach($data as $i=>$v) {
$postdata.= $i . "=" . urlencode($v) . "&";
}
$postdata.="cmd=_notify-validate";
//Set the port number
if($web[scheme] == "https") {
$web[port]="443";
$ssl="ssl://";
} else {
$web[port]="80";
}
//Create paypal connection
$fp=@fsockopen($ssl . $web[host],$web[port],$errnum,$errstr,30);
//Error checking
if(!$fp) {
echo "$errnum: $errstr";
} else { //Post Data
fputs($fp, "POST $web[path] HTTP/1.1\r\n");
fputs($fp, "Host: $web[host]\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($postdata)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $postdata . "\r\n\r\n");
//loop through the response from the server
while(!feof($fp)) {
$info[]=@fgets($fp, 1024);
}
//close fp - we are done with it
fclose($fp);
//break up results into a string
$info=implode(",",$info);
}
return $info;
}
$result=fsockPost("http://www.paypal.com/cgi-bin/webscr", $_POST);
The $result variable (bottom) is filled with the response text (which serves as a verification that it is from PayPal). The POST values that come from the first call of this scrip (which should be from PayPal) should contain all of the information you need. Here is a sample dump of that ($postdata) (details have been altered...duh):
mc_gross=15.00&protection_eligibility=Ineligible&address_status=confirmed&payer_id=123456789T4JL&tax=0.00&address_street=23+23rd+Ave&payment_date=39%3A42%3A34+Feb+23%2C+2011+PST&payment_status=Completed&charset=windows-1252&address_zip=12345&first_name=John&mc_fee=0.81&address_country_code=US&address_name=John+Doe¬ify_version=3.0&custom=&payer_status=verified&business=yourbusiness.com&address_country=United+States&address_city=NYC&quantity=1&verify_sign=AShYUCI1AJfCySIHj5coaxvlUU.RAHLmp.bWuPpa4vyNvWgV9qowpF3f&payer_email=payer_mail%40gmail.com&txn_id=48661819D0514811P&payment_type=instant&last_name=Doe&address_state=NY&receiver_email=your%40mail.com&payment_fee=0.81&receiver_id=RVBKNFXM3HCQL&txn_type=web_accept&item_name=Donation+-+23j&mc_currency=USD&item_number=d565ef66e70&residence_country=US&handling_amount=0.00&transaction_subject=Donation+-+23j&payment_gross=15.00&shipping=0.00&cmd=_notify-validate
Let me know if that helped.
The cm GET var holds the value of the custom hidden field, when PayPal redirects back to your site.
精彩评论