-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaypal.php
83 lines (74 loc) · 2.47 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
<?php
// fetch bootloader
require('bootloader.php');
// user access (simple)
if (!$user->_logged_in) {
user_login();
}
try {
if ($_GET['status'] == 'success') {
switch ($_GET['handle']) {
case 'packages':
// valid inputs
if (!isset($_GET['paymentId']) || !isset($_GET['PayerID'])) {
_error(404);
}
if (!isset($_GET['package_id']) || !is_numeric($_GET['package_id'])) {
_error(404);
}
// check package
$package = $user->get_package($_GET['package_id']);
if (!$package) {
_error(404);
}
// check payment
$payment = paypal_check($_GET['paymentId'], $_GET['PayerID']);
if ($payment) {
/* update user package */
$user->update_user_package($package['package_id'], $package['name'], $package['price'], $package['verification_badge_enabled']);
/* redirect */
redirect("/upgraded");
}
break;
case 'wallet':
// valid inputs
if (!isset($_GET['paymentId']) || !isset($_GET['PayerID'])) {
_error(404);
}
// check payment
$payment = paypal_check($_GET['paymentId'], $_GET['PayerID']);
if ($payment) {
/* update user wallet balance */
$db->query(sprintf("UPDATE users SET user_wallet_balance = user_wallet_balance + %s WHERE user_id = %s", secure($_SESSION['wallet_replenish_amount']), secure($user->_data['user_id'], 'int'))) or _error("SQL_ERROR_THROWEN");
/* wallet transaction */
$user->wallet_set_transaction($user->_data['user_id'], 'recharge', 0, $_SESSION['wallet_replenish_amount'], 'in');
/* redirect */
redirect("/wallet?replenish_succeed");
}
break;
case 'donate':
// valid inputs
if (!isset($_GET['paymentId']) || !isset($_GET['PayerID'])) {
_error(404);
}
if (!isset($_GET['post_id']) || !is_numeric($_GET['post_id'])) {
_error(404);
}
// check payment
$payment = paypal_check($_GET['paymentId'], $_GET['PayerID']);
if ($payment) {
/* funding donation */
$user->funding_donation($_GET['post_id'], $_SESSION['donation_amount']);
/* redirect */
redirect("/posts/" . $_GET['post_id']);
}
break;
default:
_error(404);
break;
}
}
redirect();
} catch (Exception $e) {
_error('System Message', $e->getMessage());
}