|
1 | 1 | <link rel="stylesheet" href="<?php echo plugins_url('css/payment.css', dirname(__FILE__))?>" type="text/css"> |
| 2 | +<noscript><style>.yesscript{display:none}</style></noscript> |
| 3 | + |
| 4 | +<?php $expiry_datestr = date('r', $invoice->expires_at); ?> |
2 | 5 |
|
3 | 6 | <div class="ln-pay"> |
4 | | - <h4> |
5 | | - <strong>Pay <?php echo $order->get_formatted_order_total() ?> with Lightning</strong> |
6 | | - (<?php echo number_format($invoice->msatoshi/100000000, 8) ?> mBTC) |
7 | | - </h4> |
| 7 | + <h1>Pay with Lightning</h1> |
| 8 | + <h3><?php echo $order->get_formatted_order_total() ?> = <?php echo number_format($invoice->msatoshi/100000000, 8) ?> mBTC</h3> |
8 | 9 | <img class="qr" src="<?php echo $qr_uri ?>"> |
9 | | - <div class="payreq"> |
10 | | - <code><?php echo $invoice->payreq ?></code> |
11 | | - <a class="checkout-button button alt" href="lightning:<?php echo $invoice->payreq ?>">Pay with Lightning</a> |
12 | | - </div> |
13 | | - |
| 10 | + <code class="payreq"><?php echo $invoice->payreq ?></code> |
| 11 | + <p> |
| 12 | + <noscript>Your browser has JavaScript turned off. Please refresh the page manually after making the payment.</noscript> |
| 13 | + <span class="yesscript"><img src="<?php echo plugins_url( '../img/loader.gif', __FILE__ ) ?>" class="loader" alt="loading"> Awaiting payment.</span> |
| 14 | + The invoice expires <span id="expiry-timer" title="<?php echo $expiry_datestr ?>"><?php echo $expiry_datestr ?></span>. |
| 15 | + </p> |
| 16 | + <a class="checkout-button button alt" href="lightning:<?php echo $invoice->payreq ?>">Pay with Lightning</a> |
14 | 17 | </div> |
15 | 18 |
|
16 | 19 | <script> |
17 | | -(function($, ajax_url, invoice_id, redir_url){ |
| 20 | +(function($, ajax_url, invoice_id, redir_url, expires_at){ |
18 | 21 | $(function poll() { |
19 | 22 | $.post(ajax_url, { action: 'ln_wait_invoice', invoice_id: invoice_id }) |
20 | 23 | .success((code, state, res) => { |
|
24 | 27 | throw new Error('succesful response, but not the expected one') |
25 | 28 | }) |
26 | 29 | .fail(res => { |
27 | | - // immediatly re-poll on 402 Payment Required |
| 30 | + // 402 Payment Required: timeout reached without payment, invoice is still payable |
28 | 31 | if (res.status === 402) return poll() |
| 32 | + // 410 Gone: invoice expired and can not longer be paid |
| 33 | + if (res.status === 410) return location.reload() |
29 | 34 |
|
30 | 35 | // for unknown errors, wait for a little while, then try again |
31 | 36 | setTimeout(poll, 10000); |
32 | 37 | throw new Error('unexpected status code '+res.status) |
33 | 38 | }) |
34 | 39 | }) |
| 40 | + |
| 41 | + ;(function updateExpiry() { |
| 42 | + var left = expires_at - (+new Date()/1000|0) |
| 43 | + if (left <= 0) return location.reload() |
| 44 | + $('#expiry-timer').text('in '+formatDur(left)) |
| 45 | + setTimeout(updateExpiry, 1000) |
| 46 | + })() |
| 47 | + |
| 48 | + function formatDur(x) { |
| 49 | + var h=x/3600|0, m=x%3600/60|0, s=x%60 |
| 50 | + return ''+(h>0?h+':':'')+(m<10&&h>0?'0':'')+m+':'+(s<10?'0':'')+s |
| 51 | + } |
35 | 52 | })(jQuery, <?php echo json_encode(admin_url( 'admin-ajax.php' )) ?>, <?php echo json_encode($invoice->id) ?>, |
36 | | - <?php echo json_encode($order->get_checkout_order_received_url()) ?>) |
| 53 | + <?php echo json_encode($order->get_checkout_order_received_url()) ?>, <?php echo $invoice->expires_at ?>) |
37 | 54 |
|
38 | 55 | </script> |
39 | 56 |
|
0 commit comments