Skip to content

Commit

Permalink
timer implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
btcgear committed May 10, 2013
1 parent bb7bbcd commit eb888fd
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 33 deletions.
14 changes: 14 additions & 0 deletions upload/admin/controller/payment/bitcoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ private function validate() {
if (!$this->request->post['bitcoin_prefix']) {
$this->error['prefix'] = $this->language->get('error_prefix');
}
if (!$this->request->post['bitcoin_countdown_timer']) {
$this->error['countdown_timer'] = $this->language->get('error_countdown_timer');
}

if (!$this->error) {
return TRUE;
Expand Down Expand Up @@ -83,6 +86,7 @@ public function index() {
$this->data['entry_prefix'] = $this->language->get('entry_prefix');
$this->data['entry_order_status'] = $this->language->get('entry_order_status');
$this->data['entry_show_btc'] = $this->language->get('entry_show_btc');
$this->data['entry_countdown_timer'] = $this->language->get('entry_countdown_timer');
$this->data['entry_status'] = $this->language->get('entry_status');
$this->data['entry_sort_order'] = $this->language->get('entry_sort_order');

Expand Down Expand Up @@ -118,6 +122,11 @@ public function index() {
} else {
$this->data['error_prefix'] = '';
}
if (isset($this->error['countdown_timer'])) {
$this->data['error_countdown_timer'] = $this->error['countdown_timer'];
} else {
$this->data['error_countdown_timer'] = '';
}

$this->data['breadcrumbs'] = array();

Expand Down Expand Up @@ -175,6 +184,11 @@ public function index() {
} else {
$this->data[$this->payment_module_name.'_show_btc'] = $this->config->get($this->payment_module_name.'_show_btc');
}
if (isset($this->request->post[$this->payment_module_name.'_countdown_timer'])) {
$this->data[$this->payment_module_name.'_countdown_timer'] = $this->request->post[$this->payment_module_name.'_countdown_timer'];
} else {
$this->data[$this->payment_module_name.'_countdown_timer'] = $this->config->get($this->payment_module_name.'_countdown_timer');
}
if (isset($this->request->post[$this->payment_module_name.'_order_status_id'])) {
$this->data[$this->payment_module_name.'_order_status_id'] = $this->request->post[$this->payment_module_name.'_order_status_id'];
} else {
Expand Down
2 changes: 2 additions & 0 deletions upload/admin/language/english/payment/bitcoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
$_['entry_prefix'] = 'The prefix for the address labels:<br /><span class="help">The account will be in the form [prefix]_[order_id]</span>';
$_['entry_order_status'] = 'Status of a new order:';
$_['entry_show_btc'] = 'Show BTC as a store currency:';
$_['entry_countdown_timer'] = 'Time to complete order:<br /><span class="help">In seconds</span>';
$_['entry_status'] = 'Status:';
$_['entry_sort_order'] = 'Sort Order:';

Expand All @@ -46,4 +47,5 @@
$_['error_password'] = 'Warning: Bitcoin RPC Password is required';
$_['error_port'] = 'Warning: Bitcoin RPC Port is required';
$_['error_prefix'] = 'Warning: Label prefix is required';
$_['error_countdown_timer'] = 'Warning: Countdown timer is required';
?>
7 changes: 7 additions & 0 deletions upload/admin/view/template/payment/bitcoin.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ DEALINGS IN THE SOFTWARE.
<option value="0" selected="selected"><?php echo $text_no; ?></option>
<?php } ?>
</select></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_countdown_timer; ?></td>
<td><input type="text" name="bitcoin_countdown_timer" value="<?php echo $bitcoin_countdown_timer; ?>" style="width:300px;" />
<?php if ($error_countdown_timer) { ?>
<span class="error"><?php echo $error_countdown_timer; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><?php echo $entry_order_status; ?></td>
Expand Down
4 changes: 4 additions & 0 deletions upload/catalog/controller/payment/bitcoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ protected function index() {
$this->data['text_click_pay'] = $this->language->get('text_click_pay');
$this->data['text_uri_compatible'] = $this->language->get('text_uri_compatible');
$this->data['text_click_here'] = $this->language->get('text_click_here');
$this->data['text_pre_timer'] = $this->language->get('text_pre_timer');
$this->data['text_post_timer'] = $this->language->get('text_post_timer');
$this->data['text_countdown_expired'] = $this->language->get('text_countdown_expired');
$this->data['text_if_not_redirect'] = $this->language->get('text_if_not_redirect');
$this->data['error_msg'] = $this->language->get('error_msg');
$this->data['error_confirm'] = $this->language->get('error_confirm');
$this->data['error_incomplete_pay'] = $this->language->get('error_incomplete_pay');
$this->data['bitcoin_countdown_timer'] = $this->config->get('bitcoin_countdown_timer');

$this->checkUpdate();

Expand Down
3 changes: 3 additions & 0 deletions upload/catalog/language/english/payment/bitcoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
$_['text_click_pay'] = 'Click to pay';
$_['text_uri_compatible'] = '(URI-compatible wallets only)';
$_['text_click_here'] = 'Click here';
$_['text_pre_timer'] = 'You have ';
$_['text_post_timer'] = ' remaining to complete your transaction.';
$_['text_countdown_expired'] = 'Your time to complete this transaction has expired. Please refresh the page and attempt to checkout again.';
$_['text_if_not_redirect'] = 'if you are not redirected automatically a few seconds after payment.';
$_['error_msg'] = 'Error communicating with payment provider. Please contact the store for assistance.';
$_['error_confirm'] = 'That didn\\\'t quite work. Please try again. If you receive this message multiple times, please contact us so we can help finalize your order.';
Expand Down
95 changes: 62 additions & 33 deletions upload/catalog/view/theme/default/template/payment/bitcoin.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ DEALINGS IN THE SOFTWARE.
-->

<?php if(!$error) { ?>
<div class="buttons">
<div class="right"><a id="button-pay" class="button"><span><?php echo $button_bitcoin_pay; ?></span></a></div>
</div>
<div class="buttons">
<div class="right"><a id="button-pay" class="button"><span><?php echo $button_bitcoin_pay; ?></span></a></div>
</div>
<?php } else { ?>
<div class="warning">
<?php echo $error_msg; ?>
</div>
<div class="warning">
<?php echo $error_msg; ?>
</div>
<?php } ?>
<script type="text/javascript"><!--
if (typeof colorbox == 'undefined') {
Expand All @@ -43,24 +42,52 @@ if (typeof colorbox == 'undefined') {
e.media = "screen"
document.getElementsByTagName("head")[0].appendChild(e);
}
var countdown;
var timeleft = <?php echo $bitcoin_countdown_timer; ?>;
var checker = 0;
var expired_countdown_content = '<div style="font-size:16px; padding:6px; text-align:center;"><?php echo $text_countdown_expired ?></div>';
function timer () {
timeleft = timeleft -1;
if(timeleft <= 0)
{
clearInterval(countdown);
countdown = 0;
document.getElementById("cboxLoadedContent").innerHTML = expired_countdown_content;
clearInterval(checker);
checker = 0;
}
var minutes = Math.floor(timeleft/60);
var seconds = timeleft%60;
var seconds_string = "0" + seconds;
seconds_string = seconds_string.substr(seconds_string.length - 2)
document.getElementById("timer").innerHTML = minutes + ":" + seconds_string;
}
countdown = setInterval(timer, 1000);
$('#button-pay').on('click', function() {
var checker = 0;
html = '<div id="payment-wrapper" style="position:relative;">';
html += ' <div id="payment-left" style="float:left; margin-top:20px;">';
html += ' <div style="font-size:16px; padding:6px; text-align:center;"><?php echo $text_please_send ?> <span style="font-size:18px; border-style:solid; border-width: 1px; border-radius:3px; padding-top:3px; padding-right:6px; padding-left:6px; padding-bottom:3px;"><?php echo $bitcoin_total; ?></span> <?php echo $text_btc_to ?> </div>';
html += ' <div style="font-size:16px; padding:6px; text-align:center;"><span style="font-size:18px; border-style:solid; border-width: 1px; border-radius:3px; padding-top:3px; padding-right:6px; padding-left:6px; padding-bottom:3px;"><?php echo $bitcoin_send_address; ?></span></div>';
html += ' <div style="font-size:16px; padding:6px; text-align:center;"> <?php echo $text_to_complete ?></div>';
html += ' <div style="font-size:16px; padding:6px; text-align:center;"><a style="font-size: 16px;" href="bitcoin:<?php echo $bitcoin_send_address; ?>?amount=<?php echo $bitcoin_total; ?>"><?php echo $text_click_pay ?></a> <?php echo $text_uri_compatible ?></div>';
html += ' </div>';
html += '<div id="payment-right" style="float: right;"><img src="http://chart.apis.google.com/chart?cht=qr&chl=bitcoin:<?php echo $bitcoin_send_address; ?>?amount=<?php echo $bitcoin_total; ?>&chs=160x160"></div></div>';
html += '<div class="buttons" style="clear: both; margin-bottom:6px; margin-top:12px;">';
html += ' <div class="center"><a id="button-confirm"><span><?php echo $text_click_here ?></span></a> <?php echo $text_if_not_redirect ?></div>';
html += '</div>';
if(timeleft > 0) {
html = '<div id="payment-wrapper" style="position:relative;">';
html += ' <div id="payment-left" style="float:left; margin-top:20px;">';
html += ' <div style="font-size:16px; padding:6px; text-align:center;"><?php echo $text_please_send ?> <span style="font-size:18px; border-style:solid; border-width: 1px; border-radius:3px; padding-top:3px; padding-right:6px; padding-left:6px; padding-bottom:3px;"><?php echo $bitcoin_total; ?></span> <?php echo $text_btc_to ?> </div>';
html += ' <div style="font-size:16px; padding:6px; text-align:center;"><span style="font-size:18px; border-style:solid; border-width: 1px; border-radius:3px; padding-top:3px; padding-right:6px; padding-left:6px; padding-bottom:3px;"><?php echo $bitcoin_send_address; ?></span></div>';
html += ' <div style="font-size:16px; padding:6px; text-align:center;"> <?php echo $text_to_complete ?></div>';
html += ' <div style="font-size:16px; padding:6px; text-align:center;"><a style="font-size: 16px;" href="bitcoin:<?php echo $bitcoin_send_address; ?>?amount=<?php echo $bitcoin_total; ?>"><?php echo $text_click_pay ?></a> <?php echo $text_uri_compatible ?></div>';
html += ' </div>';
html += '<div id="payment-right" style="float: right;"><img src="http://chart.apis.google.com/chart?cht=qr&chl=bitcoin:<?php echo $bitcoin_send_address; ?>?amount=<?php echo $bitcoin_total; ?>&chs=160x160"></div></div>';
html += '<div class="buttons" style="clear: both; margin-bottom:6px; margin-top:12px;">';
html += ' <div class="center" style="font-size: 16px;"><?php echo $text_pre_timer ?><span id="timer" style="font-size:18px; font-weight:bold;"></span><?php echo $text_post_timer ?></div>';
html += '</div>';
html += '<div class="buttons" style="clear: both; margin-bottom:6px; margin-top:12px;">';
html += ' <div class="center"><a id="button-confirm"><span><?php echo $text_click_here ?></span></a> <?php echo $text_if_not_redirect ?></div>';
html += '</div>';
}
else {
html = expired_countdown_content;
}
$.colorbox({
overlayClose: true,
opacity: 0.5,
width: '650px',
height: '275px',
height: '375px',
href: false,
html: html,
onComplete: function() {
Expand All @@ -71,29 +98,31 @@ $('#button-pay').on('click', function() {
url: 'index.php?route=payment/bitcoin/confirm_sent',
timeout: 5000,
error: function() {
alert('<?php echo $error_confirm; ?>');
document.getElementById("cboxLoadedContent").innerHTML = document.getElementById("cboxLoadedContent").innerHTML + '<div class="warning"><?php echo $error_confirm; ?></div>';
},
success: function(received) {
if(!received) {
alert('<?php echo $error_incomplete_pay; ?>');
document.getElementById("cboxLoadedContent").innerHTML = document.getElementById("cboxLoadedContent").innerHTML + '<div class="warning"><?php echo $error_incomplete_pay; ?></div>';
}
else {
location.href = 'index.php?route=checkout/success';
}
}
});
});
function bitcoin_check () {
$.ajax({
type: 'GET',
url: 'index.php?route=payment/bitcoin/confirm_sent',
timeout: 5000,
success: function(received) {
if(received) {
location.href = 'index.php?route=checkout/success';
}
}
});
function bitcoin_check () {
if(timeleft > 0) {
$.ajax({
type: 'GET',
url: 'index.php?route=payment/bitcoin/confirm_sent',
timeout: 5000,
success: function(received) {
if(received) {
location.href = 'index.php?route=checkout/success';
}
}
});
}
}
},
onCleanup: function() {
Expand Down

0 comments on commit eb888fd

Please sign in to comment.