-
Notifications
You must be signed in to change notification settings - Fork 1
/
create.php
106 lines (82 loc) · 3.43 KB
/
create.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
<?php include 'partials/header.php'; ?>
<?php
$currencies = json_decode(file_get_contents("https://blockchain.info/ticker"), true);
?>
<?php if (isset($_POST["invoice"])) : ?>
<?php
include("partials/PDO/Db.class.php");
$receivingAddress = "19UvhEdjQbhnJrUtDcMLvpRN5nk3axBAJu";
$user_id = 1;
$newAddr = json_decode(file_get_contents("https://blockchain.info/api/receive?method=create&address=$receivingAddress"), true)[input_address];
$currency = $_POST['currency'];
$currency_value = number_format($_POST['value'], 2);
$invoice_btc_value = file_get_contents("https://blockchain.info/tobtc?currency=$currency&value=$currency_value");
$date = date("D M d Y H:i:s O");
$date_expiry = date("D M d Y H:i:s O", strtotime($date) + 900);
$db = new Db();
$db->query("INSERT INTO
invoices(invoice_user_id, invoice_address, invoice_fiat, invoice_fiat_value, invoice_btc_value, invoice_paid, invoice_date, invoice_date_expiry)
VALUES('$user_id', '$newAddr', '$currency', '$currency_value', '$invoice_btc_value', '0', '$date', '$date_expiry')"
);
header('Location: invoice.php?id=' . $db->lastInsertId());
?>
<?php else : ?>
<?php
$currency_default = "BRL";
if (isset($_GET["currency"])) {
$currency_default = $_GET["currency"];
}
$quote = $currencies[$currency_default]["sell"];
$symbol = $currencies[$currency_default]["symbol"];
?>
<header>
<h1>Criar Fatura</h1>
</header>
<form action="<?php $_SERVER["PHP_SELF"] ?>" method="POST">
<div style="margin-bottom:12px;">
<label>Cotação:</label>
<div>
<?php echo $symbol . ' ' . $quote; ?>
</div>
</div>
<div style="margin-bottom:12px;">
<label>Moeda:</label>
<select id="select-currency" name="currency">
<?php foreach ($currencies as $currency => $value) : ?>
<option value="<?php echo $currency; ?>" <?php if ($currency == $currency_default) : ?>selected<?php endIf; ?>><?php echo $currency; ?></option>
<?php endforeach; ?>
</select>
</div>
<div style="margin-bottom:12px;">
<label>Valor:</label>
<input id="value" name="value" data-quote="<?php echo $quote; ?>" type="text">
</div>
<div style="margin-bottom:12px;">
<label>Total em BTC:</label>
<div id="total">
</div>
</div>
<div style="margin-bottom:12px;">
<label>Notas:</label>
<textarea name="note" rows="3"></textarea>
</div>
<button type="submit" name="invoice">Gerar Fatura</button>
</form>
<a href="report.php">Relatórios de Pagamento</a>
<script type="text/javascript">
$(document).ready(function() {
$("#value").on("change paste keyup", function() {
var val = $(this).val(),
quote = $(this).data("quote"),
oneFiatinSatoshis = 100000000 / quote,
valInSatoshis = val * oneFiatinSatoshis,
valInBTC = valInSatoshis / 100000000;
$("#total").text(valInBTC.toFixed(8));
});
$("#select-currency").on("change", function() {
window.location = "create.php?currency=" + $(this).val();
});
});
</script>
<?php endif; ?>
<?php include 'partials/footer.php'; ?>