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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
<?php //Change these with your information $paypalmode = ''; //Sandbox for testing or empty '' // $paypalmode = 'sandbox'; //Sandbox for testing or empty '' /* $dbusername = 'patterns'; //db username $dbpassword = 'patterns'; //db password $dbhost = 'localhost'; //db host $dbname = 'patterns'; //db name */ include("../schnitte/connect.php"); if($_POST) { if($paypalmode=='sandbox') { $paypalmode = '.sandbox'; } $req = 'cmd=' . urlencode('_notify-validate'); foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://www'.$paypalmode.'.paypal.com/cgi-bin/webscr'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $req); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www'.$paypalmode.'.paypal.com')); $res = curl_exec($ch); curl_close($ch);
if (strcmp ($res, "VERIFIED") == 0) { $transaction_id = $_POST['txn_id']; $payerid = $_POST['payer_id']; $firstname = $_POST['first_name']; $lastname = $_POST['last_name']; $payeremail = $_POST['payer_email']; $paymentdate = $_POST['payment_date']; $paymentstatus = $_POST['payment_status']; $itemnumber = $_POST['item_number1']; $country = $_POST['address_country_code']; $mdate= date('Y-m-d h:i:s',strtotime($paymentdate)); $otherstuff = json_encode($_POST);
/* $conn = mysql_connect($dbhost,$dbusername,$dbpassword); if (!$conn) { die('Could not connect: ' . mysql_error()); }
mysql_select_db($dbname, $conn);*/ $query = MYSQL_QUERY("SELECT * FROM $pptabelle WHERE TransactionID = '$transaction_id'"); $check = mysql_fetch_array($query); switch($paymentstatus){ case 'Completed': if($check['pending'] == 1){ $empfaenger = "$payeremail"; //$empfaenger = "art.domino@aon.at"; $absendername = "Black Snail"; $absendermail = "blacksnailpatterns@gmx.at"; /*$empfaenger = $check['BuyerEmail'];*/ $crypted = hash('sha512', $transaction_id); $link = "http://patterns.bplaced.net/pp/getpattern.php?code=$crypted&id=$transaction_id"; /* DEUTSCHE AUSGABE */ if($country == 'DE' || $country == 'CH' || $country == 'AT'){ $betreff = "Kauf erfolgreich!"; $text = "Hallo!\r\nDeine Bestellung mit der Transaktions-ID $transaction_id war erfolgreich!\r\nDer IPN-Status ist: $paymentstatus !!!!\r\nDie Produktnummer: $itemnumber\r\nVielen Dank!\r\nZum Download deiner Datei folge bitte dem Link: $link"; } else { $betreff = "Purchase successful!"; $text = "Thank you very much for your purchase!\r\nYour order with the transaction-ID $transaction_id was successful!\r\nThe IPN-status is: $paymentstatus !!!!\r\nProductnumber: $itemnumber\r\nThank you very much!\r\nFollow this link for your download: $link"; } mail($payeremail, $betreff, $text, "From: $absendername <$absendermail>"); MYSQL_QUERY("UPDATE BuyerTable SET pending='0' WHERE TransactionID = '$transaction_id'"); } else {exit;} break; case 'Pending': $headers = "Return-Path: blacksnailpatterns@gmx.at". "\n"; $headers .= "MIME-Version: 1.0" . "\n"; $headers .= "Content-type:text/html;charset=utf-8" . "\n"; $headers .= "Content-Transfer-Encoding: quoted-printable" . "\n"; $headers .= 'From: Black Snail<blacksnailpatterns@gmx.at>' . "\n"; $empfaenger = "$payeremail"; //$empfaenger = "art.domino@aon.at"; /*$crypted = hash('sha512', $transaction_id); $link = "http://patterns.bplaced.net/pp/getpattern.php?code=$crypted&id=$transaction_id";*/ /* DEUTSCHE AUSGABE */ if($country == 'DE' || $country == 'CH' || $country == 'AT'){ $betreff = "Bezahlung wird bearbeitet!"; $text = "Hallo!<br/>Die Bezahlung deiner Bestellung mit der Transaktions-ID $transaction_id ist noch in Bearbeitung!<br/>Der IPN-Status ist: $paymentstatus !!!!<br/>Sobald die Zahlung erfolgreich abgeschlossen ist erhältst du eine Mail mit dem Download-Link!";} else { $betreff = "Payment pending!"; $text = "Thank you very much for your purchase!>br/>The payment of your order with the transaction-ID $transaction_id is pending!<br/>IPN-status: $paymentstatus !!!!<br/>As soon as payment is completed you will receive a mail containing your download-link!"; } mail($payeremail, $betreff, $text, $headers); break; case 'Denied': $headers = "Return-Path: blacksnailpatterns@gmx.at". "\n"; $headers .= "MIME-Version: 1.0" . "\n"; $headers .= "Content-type:text/html;charset=utf-8" . "\n"; $headers .= "Content-Transfer-Encoding: quoted-printable" . "\n"; $headers .= 'From: Black Snail<blacksnailpatterns@gmx.at>' . "\n"; $empfaenger = "$payeremail"; /*$absendername = "Black Snail";*/ /*$absendermail = "blacksnailpatterns@gmx.at";*/ /*$crypted = hash('sha512', $transaction_id);*/ /*$link = "http://patterns.bplaced.net/pp/getpattern.php?code=$crypted&id=$transaction_id";*/ /* DEUTSCHE AUSGABE */ if($country == 'DE' || $country == 'CH' || $country == 'AT'){ $betreff = "IPNBezahlung verweigert!"; $text = 'Hallo!<br/>Deine Bestellung mit der Transaktions-ID $transaction_id wurde leider abgelehnt!<br/>Der IPN-Status ist: $paymentstatus !!!!<br/>Bitte überprüfe die Einstellungen/Benachrichtigungen in deinem <a href="www.paypal.com">PayPal-Konto</a>!'; } else { $betreff = "Payment denied!"; $text = 'Sorry, the payment of your order with the transaction-ID $transaction_id was denied!<br/>IPN-status: $paymentstatus !!!!<br/>Please check the preferences/messages in your <a href="www.paypal.com">PayPal-account</a>!'; } mail($payeremail, $betreff, $text, $headers); break; }
// insert in our IPN record table /* $query = "INSERT INTO ibn_table (itransaction_id,ipayerid,iname,iemail,itransaction_date, ipaymentstatus,ieverything_else) VALUES ('$transaction_id','$payerid','$firstname $lastname','$payeremail','$mdate', '$paymentstatus','$otherstuff')";
/* if(!mysql_query($query)) { //mysql error..! } mysql_close($conn);*/
} else if (strcmp ($res, "INVALID") == 0) { // IPN invalid, log for manual investigation echo "The response from IPN was: <b>" .$res ."</b>"; }
} ?>
|