PayPal website payment Standard Edition (for PHP), paypal Standard Edition

Source: Internet
Author: User

PayPal website payment Standard Edition (for PHP), paypal Standard Edition

Simply sort out the PHP project and integrate the PayPal payment function.

1. form construction:

<Form method = "post" name = "form" action = "https://www.paypal.com/cgi-bin/webscr"> <input type = "hidden" name = "rm" value = "2"/> <input type = "hidden" name = "cmd" value = "_ xclick"/> <input type = "hidden" name = "business" value = "merchant account"/> <input type = "hidden" name = "return" value = ""/> <input type = "hidden" name = "cancel_return" value = ""/> <input type = "hidden" name = "yy_url" value = "is the URL used to receive the instant payment notification sent by PayPal, must be a valid URL "/> <input type =" hidden "name =" item_name "value =" item name "/> <input type =" hidden "name =" item_number" value = "can be used to track transfer variables for purchase or donation, <input type = "hidden" name = "amount" value = "item price (total price of all items in the shopping cart"/> <input type = "hidden" name = "currency_code" value = "currency"/> </form>

Ii. IPN Verification

<? Phpclass paypal {var $ ipn_data = array (); // array contains the POST values for IPN var $ fields = array (); // after PayPal accepts the customer's payment, paypal will POST the form information submitted by the customer to the website,
// You must return the original POST information to PayPal for verification,
// The content includes item_name = iPhone 6, quantity = 1, amount = 499, currency_code = USD, and other form information,
// Initialize var $ paypal_url = 'https: // callback function validate_ipn () before calling IPN verification () {// verify IPN // parse the paypal URL $ url_par = parse_url ($ this-> paypal_url ); // generate the post string from the _ POST vars aswell as load the // _ POST vars into an arry so we can play with them from the calling // script. $ post_str = ''; foreac H ($ _ POST as $ field =>$ value) {$ this-> ipn_data ["$ field"] = $ value; $ post_str. = $ field. '= '. urlencode (stripslashes ($ value )). '&';} $ post_str. = "cmd = _ policy-validate"; // append ipn command // open the connection to paypal $ fp = fsockopen ($ url_par [host], "80", $ errnum, $ errstr, 30); if (! $ Fp) {// cocould not open the connection. return false;} else {// Post the data back to paypal fputs ($ fp, "POST ". $ url_par [path]. "HTTP/1.1 \ r \ n"); fputs ($ fp, "Host :". $ url_par [host]. "\ r \ n"); fputs ($ fp, "Content-type: application/x-www-form-urlencoded \ r \ n"); fputs ($ fp, "Content-length :". strlen ($ post_str ). "\ r \ n"); fputs ($ fp, "Connection: close \ r \ n"); fputs ($ fp, $ post_str. "\ r \ n"); // loop Through the response from the server and append to variable while (! Feof ($ fp) {$ this-> validate_ipn_response. = fgets ($ fp, 1024);} fclose ($ fp); // close connection} if (eregi ("VERIFIED", $ this-> validate_ipn_response )) {return true;} else {return false ;}}}?>

The instant payment notification (IPN) is as follows:

 

1) The customer clicks the "Payment" button to pay for your account;

2) After receiving the payment from the customer, PayPal sends IPN to the URL specified by your server through POST;

3) after your server receives the IPN, you must return the received POST information to PayPal for verification. PayPal uses this method to prevent spoofing or "man-in-the-middle" attacks; (The verification process for IPN information is called notification confirmation)

4) PayPal returns the verification information. If it passes verification, it is VERIFIED. If it fails, it is INVALD;

5) process the payment details based on the verification information.

Related information:

Developer: https://developer.paypal.com/
Instant payment notification: https://www.paypal-biz.com/development/documentation/PayPal_IPN&PDT_Guide_V1.0.pdf
Paypal Standard Edition: https://www.paypal-biz.com/development/documentation/PayPal_WPS_Guide_CN_V2.0.pdf

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.