-
Notifications
You must be signed in to change notification settings - Fork 0
/
payment.php
52 lines (47 loc) · 1.82 KB
/
payment.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
<?php
require 'config.php';
$productName = $_GET['name'];
$productValue = $_GET['value'];
$oneBTCinSatoshis = 100000000;
$askBtcAverage = json_decode(file_get_contents("https://api.bitcoinaverage.com/ticker/USD/"), true)[ask];
$oneUSDinSatoshis = ($oneBTCinSatoshis / $askBtcAverage);
$productInSatoshis = ceil($productValue * $oneUSDinSatoshis);
$productInBTC = number_format($productInSatoshis / $oneBTCinSatoshis, 8);
$newAddy = json_decode(file_get_contents("https://blockchain.info/merchant/$ID/new_address?password=$PW"), true);
$parseAddy = $newAddy[address];
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Payment</title>
</head>
<body>
<form action="">
<h1><?php echo $productName; ?></h1>
<ul>
<li><?php echo $productValue; ?></li>
<li><?php echo $productInBTC; ?></li>
<li><?php echo $parseAddy; ?></li>
<li id="qrcode"></li>
</ul>
</form>
<script type="text/javascript" src="bower_components/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="bower_components/jquery-qrcode/jquery.qrcode.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#qrcode').qrcode({"text": "bitcoin:<?php echo $parseAddy; ?>?amount=<?php echo $productInBTC; ?>", "height": 100, "width": 100});
var json = { "address": "<?php echo $parseAddy; ?>" };
setInterval(function() {
$.post("checkpayment.php", json, function(data) {
if (data == <?php echo $productInSatoshis; ?>) {
window.location.href = "success.php";
} else {
console.log('Waiting...');
}
});
}, 1000);
});
</script>
</body>
</html>