-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
102 lines (81 loc) · 2.29 KB
/
functions.php
File metadata and controls
102 lines (81 loc) · 2.29 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
<?php
declare(strict_types=1);
function isValidUuid(string $uuid): bool
{
if (!is_string($uuid) || (preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/', $uuid) !== 1)) {
return false;
}
return true;
}
function sendTransferRequest(string $transferCode, int $totalCost): int
{
$url = "https://www.yrgopelago.se/centralbank/transferCode";
$data = json_encode([
'transferCode' => $transferCode,
'totalcost' => $totalCost
]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
$error = curl_error($ch);
curl_close($ch);
return 'Error: ' . $error;
}
curl_close($ch);
$decodedResponse = json_decode($response, true);
return $decodedResponse['totalCost'] ?? 0;
}
function depositTransfer(string $user, string $transferCode): string
{
$url = "https://www.yrgopelago.se/centralbank/deposit";
$data = [
'user' => $user,
'transferCode' => $transferCode
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'application/x-www-form-urlencoded',
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
$error = curl_error($ch);
curl_close($ch);
return 'Error: ' . $error;
}
curl_close($ch);
return $response;
}
function calculateRoomCost(string $roomType, float $totalDays): float {
if ($totalDays > 3) {
switch ($roomType) {
case 'economy':
return round(1 * $totalDays * 0.70);
case 'standard':
return round(2 * $totalDays * 0.70);
case 'luxury':
return round(4 * $totalDays * 0.70);
default:
return 0;
}
} else {
switch ($roomType) {
case 'economy':
return 1 * $totalDays;
case 'standard':
return 2 * $totalDays;
case 'luxury':
return 4 * $totalDays;
default:
return 0;
}
}
}