-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_balance.php
36 lines (29 loc) · 1.01 KB
/
get_balance.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
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require 'vendor/autoload.php';
require 'config.php';
use MongoDB\Client;
header('Content-Type: application/json');
function getBalance($user_id) {
$uri = 'mongodb+srv://likhonsheikhbd:[email protected]/?retryWrites=true&w=majority&appName=Havencoin';
$client = new Client($uri);
try {
$collection = $client->havencoin->user_balances;
$user = $collection->findOne(['user_id' => (int)$user_id]);
if ($user) {
echo json_encode(['success' => true, 'balance' => $user['balance']]);
} else {
echo json_encode(['success' => false, 'error' => 'User not found']);
}
} catch (Exception $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
}
if (isset($_GET['user_id'])) {
getBalance($_GET['user_id']);
} else {
echo json_encode(['success' => false, 'error' => 'Missing parameters']);
}
?>