forked from kestasjk/webDiplomacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paypal-ipn.php
41 lines (32 loc) · 1.46 KB
/
paypal-ipn.php
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
<?php namespace Listener;
/* Receive donation receipts automatically, to ensure donations are acknowledged and processed quickly and transparently */
// Watch out as this will catch any errors and return 200, which paypal will consider a successful acknowledgement
require('header.php');
require('contrib/PaypalIPN.php');
use PaypalIPN;
$ipn = new PaypalIPN();
function getPaypalVarOrDefault($var, $default)
{
if( isset($_POST) && isset($_POST[$var]) ) return $_POST[$var];
else return $default;
}
$verified = $ipn->verifyIPN();
if ($verified) {
$userID = (int)(getPaypalVarOrDefault('custom','1'));
$email = $DB->escape(getPaypalVarOrDefault('payer_email',''));
$gross = (float)(getPaypalVarOrDefault('mc_gross','0'));
$currency = $DB->escape(getPaypalVarOrDefault('mc_currency',''));
$filteredStatus = 'Unknown';
$status = strtolower(getPaypalVarOrDefault('payment_status','Unknown'));
foreach(array('Canceled_Reversal','Completed','Created','Denied','Expired','Failed','Pending','Refunded','Reversed','Processed','Voided') as $validStatus)
{
if( $status === strtolower($validStatus) )
{
$filteredStatus = $validStatus;
}
}
$DB->sql_put("INSERT INTO wD_PaypalIPN (userID, email, value, currency, status, receivedTime) VALUES (".$userID.",'".$email."',".$gross.",'".$currency."','".$filteredStatus."',".time().")");
$DB->sql_put("COMMIT");
}
// Reply with an empty 200 response to indicate to paypal the IPN was received correctly.
header("HTTP/1.1 200 OK");