-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuy.php
More file actions
180 lines (113 loc) · 4.71 KB
/
buy.php
File metadata and controls
180 lines (113 loc) · 4.71 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
session_start();
include("global.php");
include("config.php");
if( checklogin() == true ) {
$user = $_SESSION['discord_user'];
$pterodactyl_panelinfo = $conn->query("SELECT * FROM users WHERE discord_id='" . mysqli_real_escape_string($conn, $user->id) . "'")->fetch_assoc();
$pterodactyl_username = $pterodactyl_panelinfo['pterodactyl_username'];
$pterodactyl_password = $pterodactyl_panelinfo['pterodactyl_password'];
} else {
header("Location: /");
die();
}
include("plans.php");
if( !isset($_GET['level']) ) {
die("ERROR: `level` is required.");
}
if( !isset($_GET['method']) || empty($_GET['method']) || !in_array($_GET['method'], array("xsolla", "paypal")) ) {
die("ERROR: invalid method.");
}
// Check if the specificied level exists
$checkLevel = $conn->query("SELECT * FROM levels WHERE level=" . mysqli_real_escape_string($conn, $_GET['level']))->num_rows;
if( $checkLevel == 0 ) {
die("ERROR: invalid level.");
}
// Check if user have current level or higher
if( $GET_USER_LEVEL >= intval($_GET['level']) ) {
ShowError("You already have this plan or a higher one.");
}
// Get level info
$level_info = $conn->query("SELECT * FROM levels WHERE level=" . mysqli_real_escape_string($conn, $_GET['level']))->fetch_assoc();
if( $level_info['price'] == 0 ) {
ShowError("You can't buy a free plan.");
}
// Create payment handler
$pHandler['id'] = substr(md5(mt_rand()), 0, 7);
$pHandler['parameters'] = mysqli_real_escape_string($conn, $user->id) . ":" . mysqli_real_escape_string($conn, $_GET['level']); // discordid:level
$conn->query("INSERT INTO payment_handlers (id, parameters) VALUES ('" . $pHandler['id'] . "', '" . $pHandler['parameters'] . "')");
if( $_GET['method'] == "xsolla" ) {
if( intval($_GET['level']) !== 13 ) {
ShowError("Sorry, Xsolla is available for the 40EUR plan only.");
}
$MerchantId = "51721"; // string value
$ApiKey = "fc145acdffdf5b0f56d9da87d5b3c986"; // string value
$ProjectId = 45183; // int value
// Create user (dont touch this)
$userid = "u" . strval( mt_rand(0,9) . mt_rand(0,9) . mt_rand(0,9) . mt_rand(0,9) . mt_rand(0,9) . mt_rand(0,9) . mt_rand(0,9) . mt_rand(0,9) . mt_rand(0,9) );
$uemail = "u" . strval( mt_rand(0,9) . mt_rand(0,9) . mt_rand(0,9) . mt_rand(0,9) . mt_rand(0,9) . mt_rand(0,9) . mt_rand(0,9) . mt_rand(0,9) . mt_rand(0,9) ) . "@nomail.com";
$ch = curl_init("https://api.xsolla.com/merchant/v2/projects/" . $ProjectId . "/users");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array("user_id" => $userid, "user_name" => $userid, "email" => $uemail)));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"content-type: application/json",
"authorization: Basic " . base64_encode($MerchantId . ":" . $ApiKey)
));
$result = curl_exec($ch);
curl_close($ch);
// ---------------------------------
$ch = curl_init("https://api.xsolla.com/merchant/v2/merchants/" . $MerchantId . "/token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array(
"user" => array(
"id" => array("value" => $userid), //dont touch this
"email" => array("value" => $user->email)
),
"settings" => array(
"project_id" => $ProjectId, //dont touch this
"return_url" => "https://falixnodes.host", //set this to your return URL
"external_id" => strval($pHandler['id'])
),
"purchase" => array(
"checkout" => array(
// change the amount and the currency if needed
"amount" => intval($level_info['price']),
"currency" => "EUR"
)
)
)));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"content-type: application/json",
"Accept: application/json",
"authorization: Basic " . base64_encode($MerchantId . ":" . $ApiKey)
));
$result = curl_exec($ch);
curl_close($ch);
$token = json_decode($result, true)['token'];
header("Location: https://secure.xsolla.com/paystation2/?access_token=" . $token);
die();
}
if( $_GET['method'] == "paypal" ) {
echo '
<noscript>
JavaScript is required.
</noscript>
<script>
window.onload = function(){
document.forms[\'buyform\'].submit();
}
</script>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" name="buyform" id="buyform">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="notify_url" value="http://falixnodes.host/ipn/paypal.php">
<input type="hidden" name="business" value="' . $paypal['email'] . '">
<input type="hidden" name="item_name" value="FalixNodes">
<input type="hidden" name="amount" value="' . $level_info['price'] . '">
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="custom" value="' . $pHandler['id'] . '">
</form>
';
}
?>