-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvoice.php
More file actions
135 lines (112 loc) · 4.67 KB
/
invoice.php
File metadata and controls
135 lines (112 loc) · 4.67 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
<?php include 'partials/header.php'; ?>
<style type="text/css">
.bar {
border:1px solid #222;
padding: 1px;
margin-bottom: 12px;
overflow: hidden;
width: 250px;
}
.bar__percent {
background: #222;
float: right;
height: 12px;
width:100%;
}
</style>
<?php
include("partials/PDO/Db.class.php");
$id = $_GET['id'];
$db = new Db();
$db->bind("id", $id);
$invoice = $db->query("SELECT * FROM invoices WHERE invoice_id = :id");
echo "<pre>";
print_r($invoice);
echo "</pre>";
?>
<?php foreach ($invoice as $key) : ?>
<header>
<h1>Fatura # <?php echo $id; ?></h1>
</header>
Valor em <?php echo $key["invoice_fiat"]; ?>: <?php echo $key["invoice_fiat_value"]; ?><br>
Transfira exatamente: <?php echo $key["invoice_btc_value"]; ?> BTC<br>
<a href=""><?php echo $key["invoice_address"]; ?></a><br>
<img src="https://blockchain.info/qr?data=bitcoin:<?php echo $key["invoice_address"]; ?>?amount=<?php echo $key["invoice_btc_value"]; ?>&size=200" alt=""><br>
Expira em: <br>
Data: <br>
<div class="bar">
<div id="bar" class="bar__percent"></div>
</div>
<div id="countdown"></div>
<div id="result">Esperando pagamento...</div>
<script type="text/javascript">
$(document).ready(function() {
var url = "https://blockchain.info/";
var bal;
function checkBalance() {
$.ajax({
type: "GET",
url: url + "q/getreceivedbyaddress/<?php echo $key["invoice_address"]; ?>?confirmations=0",
data: {format : 'plain'},
success: function(response) {
if (!response) return;
var value = parseInt(response);
if (value > 0) {
$('#result').text("Recebido!");
$('#countdown').text('');
$('#bar').css("width", 0 + "%");
clearInterval(timer);
clearInterval(bal);
$.ajax({
type: "POST",
url: "save-tx.php",
data: {addr : "<?php echo $key["invoice_address"]; ?>"},
success: function(response) {
console.log(response);
}
});
} else {
bal = setTimeout(checkBalance, 5000);
}
}
});
}
///Check for incoming payment
bal = setTimeout(checkBalance, 5000);
var timer;
var end = new Date('<?php echo $key["invoice_date_expiry"]; ?>');
var barWidth = 100;
var secondsToEnd = parseInt((end - new Date()) / 1000);
var percent = (100 / secondsToEnd);
function countDown() {
var second = 1000;
var minute = second * 60;
var hour = minute * 60;
var day = hour * 24;
var now = new Date();
var distance = end - now;
if (distance < 0) {
clearInterval(timer);
clearInterval(bal);
$('#bar').css("width", 0 + "%");
$('#countdown').text('Expirou!');
$('#result').text('');
return;
}
var days = Math.floor(distance / day);
var hours = Math.floor((distance % day) / hour);
var minutes = Math.floor((distance % hour) / minute);
var seconds = Math.floor((distance % minute) / second);
var expire = "Expira em: " + minutes + ':';
expire += (seconds < 10 ? '0' : '') + seconds;
barWidth = barWidth - percent;
$('#bar').css("width", barWidth + "%");
$('#countdown').text(expire);
}
// inicia funcao countDown
countDown();
timer = setInterval(countDown, 1000);
});
</script>
<?php endForeach; ?>
<?php include 'partials/footer.php'; ?>