-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipn.php
More file actions
76 lines (62 loc) · 1.99 KB
/
ipn.php
File metadata and controls
76 lines (62 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
define('WP_USE_THEMES', false);
require("../../../wp-blog-header.php");
status_header(200);
nocache_headers();
require_once('class.phpmailer.php');
include_once('class.smtp.php');
require('send_confirmation.php');
//require('bookingclass.php');
/*
Simple IPN processing script
based on code from the "PHP Toolkit" provided by PayPal
*/
// Send
$url = 'https://www.paypal.com/cgi-bin/webscr';
$postdata = '';
foreach($_POST as $i => $v) {
$postdata .= $i.'='.urlencode($v).'&';
}
$postdata .= 'cmd=_notify-validate';
$web = parse_url($url);
if ($web['scheme'] == 'https') {
$web['port'] = 443;
$ssl = 'ssl://';
} else {
$web['port'] = 80;
$ssl = '';
}
$fp = @fsockopen($ssl.$web['host'], $web['port'], $errnum, $errstr, 30);
if (!$fp) {
echo $errnum.': '.$errstr;
} else {
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");
while(!feof($fp)) {
$info[] = @fgets($fp, 1024);
}
fclose($fp);
$info = implode(',', $info);
if (eregi('VERIFIED', $info)) {
global $wpdb;
$table_request = $wpdb->prefix . "request";
$id=$postdata['option_selection1'];
$update=$wpdb->query("update $table_request set payment_status = 'Completed' where id_request = '$_POST[option_selection1]'");
// yes valid, f.e. change payment status and send confirmation voucher
send_confirmation($_POST['option_selection1']);
} else {
// invalid, log error or something
$to = get_bloginfo('admin_email');
$subject = get_bloginfo('url').' IPN script error'.print_r($_POST);
$message = get_bloginfo('url').' dormireinbedandbreakfast fault'.$_POST['st'];
$headers = 'From: '.get_bloginfo('admin_email'). '\r\n'.
'Reply-To: '.get_bloginfo('admin_email'). '\r\n'.
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
}
?>