Prototype website for VPN service, Bitcoin payments via the Blockchain.info API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
4.0 KiB

11 years ago
  1. {% extends "layout.html" %}
  2. {% block title %}Confirming purchase - packetcrypt{% endblock %}
  3. {% block content %}
  4. <div id="form-container" class="uk-width-1-2 uk-panel uk-panel-box uk-container-center">
  5. <h2>Invoice Created</h2>
  6. Please send {{ invoice.total_btc - invoice.value_paid}} BTC to: <a href="bitcoin:{{invoice.address}}?amount={{invoice.total_btc}}">{{ invoice.address }}</a>
  7. <br/><br/>
  8. <img src="https://chart.googleapis.com/chart?cht=qr&chs=300x300&chl=bitcoin:{{invoice.address}}?amount={{invoice.total_btc}}&callback=?" id="btc_qr" />
  9. <button class="uk-button uk-button-primary uk-button-expand" id="confirm">Confirm Payment <i class="uk-icon-spinner"></i></button>
  10. <form action="{{url_for('confirm_purchase', invoice_id=invoice.id)}}" method="POST" name="delete_ticket" style="width:100%;">
  11. <button type="submit" class="uk-button uk-button-expand" id="cancel">Cancel Payment</button>
  12. </form>
  13. </div>
  14. <div id="modal" class="uk-modal">
  15. <div class="uk-modal-dialog uk-modal-dialog-slide">
  16. <a class="uk-modal-close uk-close"></a>
  17. <h1>Thank you!</h1>
  18. <p>Your payment of <label id="valuepaid"></label> <i class="uk-icon-btc"></i> has been confirmed.</p>
  19. <p id="paid">Your VPN service is being configured and should be available from your dashboard in the next 5-10 minutes.</p>
  20. <p id="notpaid">
  21. However, this does not cover the total cost for your PacketCrypt service.
  22. Please send <label id="remaining"></label> <i class="uk-icon-btc"></i> to: <a id="btcaddy" >{{invoice.address}}</a>
  23. </p>
  24. <p>Transaction: <a id="hashlink"></a></p>
  25. <a class="uk-button uk-button-success uk-button-expand" href="{{url_for('dashboard')}}">Return to Dashboard</a>
  26. </div>
  27. </div>
  28. {% endblock %}
  29. {% block postscript %}
  30. <script>
  31. var amountPaidOnLoad = {{invoice.value_paid}};
  32. $(document).ready(function(){
  33. var confirmButton = $('#confirm');
  34. var cancelButton = $('#cancel');
  35. confirmButton.click(checkPayment);
  36. checkPayment();
  37. });
  38. var checkPayment = function (arg){
  39. $('#confirm > i').addClass('uk-icon-spin');
  40. $.post('/invoice_status', {
  41. invoice_id: {{invoice.id}}
  42. }).done(function(d){
  43. var paidInFull = (d['value_paid'] >= d['total_btc']);
  44. var transactionHash = d['input_transaction_hash'];
  45. var confirmations = d['confirmations'];
  46. window.setTimeout(stopSpin, 3500);
  47. if(confirmations == null || amountPaidOnLoad == d['value_paid']){
  48. //$('#flash-wrapper').children(":first").append("<div class='uk-alert uk-alert-warning' data-uk-alert><a class='uk-alert-close uk-close'></a>Unable to confirm payment. Wait a few seconds and try again.</div>");
  49. window.setTimeout(checkPayment, 10000);
  50. } else {
  51. // Setup the modal before display
  52. var priceLeft = (d['total_btc'] - d['value_paid']);
  53. var btcLink = "bitcoin:{{invoice.address}}?amount="+priceLeft;
  54. var hashLink = "https://blockchain.info/tx/"+transactionHash;
  55. $('#valuepaid').html(d['value_paid']);
  56. $('#remaining').html(d['total_btc'] - d['value_paid']);
  57. (paidInFull) ? $('#notpaid').css('display', 'none') : $('#paid').css('display', 'none');
  58. $('#btcaddy').attr('href', btcLink);
  59. $('#hashlink').attr('href', hashLink).html(transactionHash);
  60. // Display teh modal
  61. var modal = new $.UIkit.modal.Modal('#modal');
  62. modal.show();
  63. }
  64. }).fail(function(){
  65. $('#flash-wrapper').children(":first").append("<div class='uk-alert uk-alert-danger' data-uk-alert><a href='' class='uk-alert-close uk-close'></a>An error occured while trying to confirm your payment.</div>");
  66. });
  67. };
  68. var stopSpin = function (arg){
  69. $('#confirm > i').removeClass('uk-icon-spin');
  70. };
  71. </script>
  72. {% endblock %}