Real-time paypal account php implementation code

Source: Internet
Author: User

Http://paypal.ebay.cn/integrationcenter/list__resource_2.html

Php development Introduction: http://www.paypal-china.org/wangzhai/197.html
The following is the payment code for paypal 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 "/> // the email address registered by the merchant
<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 =" yy_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 now with paypal "/> </form>

}}}

The following are officially provided parameters that are received by paypal and whether the payment is successful.

After successful submission

<Input type = "hidden" value = "http: // 127.0.0.1/ecshop/respond. php? Code = paypal "name =" return "/>

Paypal will automatically jump to espond. php? Code = paypal: The page shows the following POST data.

Copy codeThe Code is as follows: // read the post from PayPal system and add 'cmd'
$ Req = 'cmd = _ policy-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 ";
$ 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 previusly 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.