PayPal Instant to account PHP implementation code

Source: Internet
Author: User
Tags header variables strcmp
Http://paypal.ebay.cn/integrationcenter/list__resource_2.html

Introduction to Chinese PHP Development: http://www.paypal-china.org/wangzhai/197.html
The following is the PayPal payment code in Ecshop

This code is submitted to the PayPal payment interface
{{{

<form target= "_blank" method= "post" action= "HTTPS://WWW.PAYPAL.COM/CGI-BIN/WEBSCR" style= "Text-align:center"; ><input type= "hidden" value= "_xclick" name= "cmd"/><input type= "hidden" value= "xfuajiao@hotmail.com" name = "Business"/>//Merchant registered mailbox
<input type= "hidden" value= "2009102370175" "Name=" Item_name "/><input type=" hidden "value=" 2888.00 "Name=" Amount "/><input type=" hidden "value=" USD "name=" Currency_code "/><input type=" hidden "value=" http:// 127.0.0.1/ecshop/respond.php?code=paypal "Name=" return "/><input type=" hidden "value=" 3 "name=" Invoice "/> <input type= "hidden" value= "Utf-8" Name= "CharSet"/><input type= "hidden" value= "1" name= "no_shipping"/> <input type= "hidden" value= "name=" No_note "/><input type=" hidden "value=" http://127.0.0.1/ecshop/ Respond.php?code=paypal "Name=" Notify_url "/><input type=" hidden "value=" 2 "name=" rm "/><input type=" Hidden "value=" http://127.0.0.1/ecshop/"name=" Cancel_return "/><input type=" submit "value=" pay immediately using PayPal "/ ></form>

}}}

The following is an official offer to receive the parameters from PayPal and determine if payment is successful.

Support was successful after the submission of the form


<input type= "hidden" value= "Http://127.0.0.1/ecshop/respond.php?code=paypal" name= "return"/>

PayPal will take the initiative to jump to espond.php?code=paypal this page, the page can be real below the post obtained some data.



Copy CodeThe code is as follows:
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 (' ssl://www.paypal.com ', 443, $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) {
HTTP ERROR
else {
Fputs ($FP, $header. $req);
while (!feof ($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "verified") = = 0) {
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) {
Log for manual investigation
}
}
Fclose ($FP);
}
?>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.