SHARE
TWEET

Untitled

a guest Sep 20th, 2019 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php  
  2.         if(isset($_GET['addr']) && !empty($_GET['addr'])) $addr=$_GET['addr'];
  3.         else $addr='qqvppp5pe4sce8qyvyncdrhekgkxcyw2hczvervmp8';
  4. ?>
  5. <html>
  6. <head>
  7. <title>Donate BCH</title>
  8. <style>
  9.         body { font:16pt arial; }
  10.         #address { font:18pt arial; }
  11.         #receivedText { font:18pt arial; color:green; }
  12. </style>
  13. </head>
  14. <body>
  15. <center>
  16. Send your donation to:<br>
  17. <br>
  18. <div id="address"><?=$addr?></div>
  19. <br>
  20. <img src="https://chart.googleapis.com/chart?cht=qr&chs=240x240&chld=L|0&chl=<?=$addr?>"><br>
  21. <br>
  22. <div id="receivedText"></div>
  23.  
  24. <script>
  25. var addr='<?=$addr?>',startBalance=0;
  26.  
  27. // run immediately and get initial balance
  28. checkPayment(1);
  29. // run every 12s
  30. setInterval(checkPayment,12000);
  31.  
  32. // check payment
  33. function checkPayment(start){
  34.         console.log('checkPayment()');
  35.         // ajax
  36.         var xhr = new XMLHttpRequest();
  37.         xhr.timeout = 12000;
  38.         xhr.open('GET','https://rest.bitcoin.com/v2/address/details/'+addr);
  39.         xhr.onreadystatechange = function () {
  40.                 if (xhr.readyState === 4) { // request is done
  41.                         if (xhr.status === 200) { // success
  42.                                 try { var r=JSON.parse(xhr.responseText); } catch(e){}
  43.                                 console.log('api response=', r);
  44.                                 if(r && r.balance && r.unconfirmedBalance){
  45.                                         var total=r.balance+r.unconfirmedBalance;
  46.                                         if(start){
  47.                                                 startBalance=total;
  48.                                                 return;
  49.                                         }
  50.                                         if(total>startBalance){
  51.                                                 console.log('payment received');
  52.                                                 document.querySelector('#receivedText').innerHTML='Thank you for your donation!';
  53.                                                 startBalance=total;
  54.                                         } else {
  55.                                                 document.querySelector('#receivedText').innerHTML='';
  56.                                         }
  57.                                 } else console.log('no payment received');
  58.                         } else console.log('ajax error: ' + xhr.status);
  59.                 }
  60.         }
  61.         xhr.send();
  62. }
  63. </script>
  64. </body>
  65. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top