PHP integrated PayPal Payment _php Tutorial

Source: Internet
Author: User
Tags vars

PHP Integrated PayPal payment


Simply organize your PHP project to integrate PayPal payment functionality.

One, the construction of the form:

1

2

3

4

5

6

7

8

9

10

11

12

Second, the IPN verification part

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

Class PayPal {

var $ipn _data = Array (); Array contains the POST values for IPN

var $fields = array (); Form parameters submitted to PayPal, for example: Item_name=iphone 6,QUANTITY=1,AMOUNT=499,CURRENCY_CODE=USD all form information,

Pre-initialization is required prior to calling validation IPN.

var $paypal _url = ' https://www.paypal.com/cgi-bin/webscr ';//sandbox:https://www.sandbox.paypal.com/cgi-bin/webscr

  

function VALIDATE_IPN () {//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 a arry so we can play with them from the calling

Script.

$post _str = ";

foreach ($_post as $field = = $value) {

$this->ipn_data["$field"] = $value;

$post _str. = $field. ' = '. UrlEncode (Stripslashes ($value)). ' & ';

}

$post _str.= "Cmd=_notify-validate"; Append IPN command

Open the connection to PayPal

$fp = Fsockopen ($url _par[host], "n", $errnum, $errstr, 30);

if (! $fp) {

Could 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\r\n");

Fputs ($fp, $post _str. "\r\n\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 above mentioned is the whole content of this article, I hope you can like.

http://www.bkjia.com/PHPjc/1015337.html www.bkjia.com true http://www.bkjia.com/PHPjc/1015337.html techarticle PHP Integrated PayPal payment Simple collation PHP project integrated paypal payment function. First, form construction: 1 2 3 4 5 6 7 8 9 Ten form Method=post name=form Action=https://www.paypa ...

  • 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.