-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
130 lines (120 loc) · 3.58 KB
/
index.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
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
<?php
header("Access-Control-Allow-Origin: *");
require_once('vendor/autoload.php');
use DOGECModule\DOGECModule;
$dogec = new DOGECModule();
if (!array_key_exists("address", $_GET) and array_key_exists("rate", $_GET)) {
if (!isset($_GET['rate']) or $_GET['rate'] == '') {
echo json_encode([
"result" => "",
"error" => "Rate has not been passed"
]);
return;
}
$currency = strtolower($_GET['rate']);
$price = $dogec->getPrice($currency);
echo json_encode([
"result" => $price,
"error" => ""
]);
}
else if (!array_key_exists("rate", $_GET) and array_key_exists("address", $_GET)) {
if (!isset($_GET['address']) or $_GET['address'] == '') {
echo json_encode([
"status" => "invalid",
"error" => "Address has not been passed :("
]);
return;
}
else if (!isset($_GET['amount']) or $_GET['amount'] == '') {
echo json_encode([
"status" => "invalid",
"error" => "Amount value has not been passed :("
]);
return;
}
else if (!isset($_GET['otime']) or $_GET['otime'] == '') {
echo json_encode([
"status" => "invalid",
"error" => "Timestamp Value has not been passed :("
]);
return;
}
else if (!isset($_GET['tx']) or $_GET['tx'] == '') {
echo json_encode([
"status" => "invalid",
"error" => "Transaction has not been passed :("
]);
return;
}
else if (!isset($_GET['conf']) or $_GET['conf'] == '') {
echo json_encode([
"status" => "invalid",
"error" => "Min Confirmations has not been passed :("
]);
return;
}
else if (!isset($_GET['mtime']) or $_GET['mtime'] == '') {
echo json_encode([
"status" => "invalid",
"error" => "Max time not has not been passed :("
]);
return;
}
$address = $_GET['address'];
$amount = $_GET['amount'];
$timestamp = $_GET['otime'];
$txid = $_GET['tx'];
$mconf = $_GET['conf'];
$max_time = $_GET['mtime'];
$current_timestamp = time();
if ($current_timestamp > $timestamp + ($max_time * 60)) {
echo json_encode([
"status" => "expired",
]);
return;
}
$response = $dogec->existsTransaction($address, $amount, $timestamp);
if (!is_array($response)) {
echo json_encode([
"status" => "failed"
]);
return;
}
else if ($response['exists']) {
$trasaction = $response['txid'];
$confirmations = $dogec->checkConfirmations($trasaction);
if ($confirmations >= $mconf) {
echo json_encode([
"status" => "confirmed",
"message" => "Transaction successfully confirmed.",
"transaction_id" => $trasaction,
"confirmations" => $confirmations
]);
return;
}
else {
echo json_encode([
"status" => "detected",
"message" => "Transaction detected. Waiting for confirmations - "
. $confirmations . "/" . $mconf,
"transaction_id" => $trasaction,
"confirmations" => $confirmations
]);
return;
}
}
else {
echo json_encode([
"status" => "waiting",
"message" => "Waiting for payment..."
]);
return;
}
}
else {
echo json_encode([
"result" => "",
"error" => "Invalid Request"
]);
}