forked from H3Gi/tatar-wars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paypal.php
95 lines (68 loc) · 2.22 KB
/
paypal.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
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
<?php
require( '.' . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'boot.php' );
require_once( MODEL_PATH . 'payment.php' );
class GPage extends WebService {
function load() {
$AppConfig = $GLOBALS['AppConfig'];
if ($this->isPost () ) {
$usedPackage = NULL;
foreach ($AppConfig['plus']['packages'] as $package) {
if ($package['name'] == $_POST['PayPal']) {
$usedPackage = $package;
}
}
// now this is just only for cashu
$merchant_id = $AppConfig['plus']['payments']['paypal']['merchant_id'];
$usedPayment = NULL;
foreach ($AppConfig['plus']['payments'] as $payment) {
if ($payment['merchant_id'] == $merchant_id) {
$usedPayment = $payment;
}
}
$sub_dom='sandbox';// www or sandbox
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}//end for
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl:https://www.paypal.com', 443, $errno, $errstr, 30);
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
if (!$fp) {
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// check the payment_status is Completed
if (strtoupper($payment_status)=='COMPLETED'){ //payment is completed
if ( $usedPackage != NULL
&& $usedPayment != NULL ){
$OID=base64_decode($_POST['option_selection1']);
$goldNumber = $usedPackage['gold'];
$m = new PaymentModel();
$m->incrementPlayerGold ($playerId, $goldNumber);
$m->dispose();
}
}//end if payment completed
}//end if verified
}//end while
fclose ($fp);
}//end if fp
///////////////////////////////////////////////////////////////
}
}
}
$p = new GPage();
$p->run ();