Skip to content

Commit cb4220b

Browse files
committed
5.2.2
* Minor improvements
1 parent 2c79111 commit cb4220b

5 files changed

Lines changed: 55 additions & 26 deletions

File tree

CryptAPI.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: CryptAPI Payment Gateway for WooCommerce
44
Plugin URI: https://github.com/cryptapi/woocommerce-cryptapi
55
Description: Accept cryptocurrency payments on your WooCommerce website
6-
Version: 5.2.1
6+
Version: 5.2.2
77
Requires at least: 5.8
88
Tested up to: 6.9.4
99
WC requires at least: 5.8
@@ -19,7 +19,7 @@
1919
exit; // Exit if accessed directly.
2020
}
2121

22-
define('CRYPTAPI_PLUGIN_VERSION', '5.2.1');
22+
define('CRYPTAPI_PLUGIN_VERSION', '5.2.2');
2323
define('CRYPTAPI_PLUGIN_PATH', plugin_dir_path(__FILE__));
2424
define('CRYPTAPI_PLUGIN_URL', plugin_dir_url(__FILE__));
2525

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,9 @@ The easiest and fastest way is via our live chat on our [website](https://crypta
436436
#### 5.2.1
437437
* Version bump
438438

439+
#### 5.2.2
440+
* Minor improvements
441+
439442
### Upgrade Notice
440443
#### 4.3
441444
* Please be sure to enable the PHP extension BCMath before upgrading to this version.

controllers/CryptAPI.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ function order_status()
929929
'coin' => strtoupper($order->get_meta('cryptapi_currency')),
930930
'show_min_fee' => $showMinFee,
931931
'order_history' => json_decode($order->get_meta('cryptapi_history'), true),
932-
'counter' => (string)$counter_calc,
932+
'counter' => (string) max(0, $counter_calc),
933933
'crypto_total' => (float)$order->get_meta('cryptapi_total'),
934934
'already_paid' => $already_paid,
935935
'remaining' => (float)$remaining_pending <= 0 ? 0 : $remaining_pending,
@@ -1189,7 +1189,7 @@ function thankyou_page($order_id)
11891189

11901190
$crypto_allowed_value = false;
11911191

1192-
$conversion_timer = ((int)$order->get_meta('cryptapi_last_price_update') + (int)$this->refresh_value_interval) - time();
1192+
$conversion_timer = max(0, ((int)$order->get_meta('cryptapi_last_price_update') + (int)$this->refresh_value_interval) - time());
11931193
$cancel_timer = $order->get_date_created()->getTimestamp() + (int)$this->order_cancelation_timeout - time();
11941194

11951195
if (in_array($crypto_coin, $allowed_to_value, true)) {
@@ -1333,7 +1333,7 @@ function thankyou_page($order_id)
13331333
); ?>
13341334
<span class="ca_time_seconds_count"
13351335
data-soon="<?php echo esc_attr(__('a moment', 'cryptapi')); ?>"
1336-
data-seconds="<?php echo esc_attr($conversion_timer); ?>"><?php echo esc_attr(date('i:s', $conversion_timer)); ?></span>
1336+
data-seconds="<?php echo esc_attr($conversion_timer); ?>"><?php echo esc_html($conversion_timer >= 3600 ? sprintf('%02d:%02d:%02d', intdiv($conversion_timer, 3600), intdiv($conversion_timer % 3600, 60), $conversion_timer % 60) : sprintf('%02d:%02d', intdiv($conversion_timer, 60), $conversion_timer % 60)); ?></span>
13371337
</div>
13381338
<?php
13391339
}
@@ -1948,11 +1948,21 @@ function refresh_value($order)
19481948
$cryptapi_total = $order->get_meta('cryptapi_total');
19491949
$order_total = $order->get_total('edit');
19501950

1951+
// Nothing to do until a full refresh interval has actually elapsed.
1952+
if (empty($last_price_update) || (int)$last_price_update + $value_refresh >= time()) {
1953+
return false;
1954+
}
1955+
19511956
$calc = $this->calc_order($history, $cryptapi_total, $order_total);
19521957
$remaining = $calc['remaining'];
19531958
$remaining_pending = $calc['remaining_pending'];
19541959

1955-
if ((int)$last_price_update + $value_refresh < time() && !empty($last_price_update) && $remaining === $remaining_pending && $remaining_pending > 0) {
1960+
// Re-quote the conversion rate only when it is safe to change the amount
1961+
// owed — i.e. no unconfirmed/partial payment is in flight. $remaining
1962+
// counts confirmed txs only; $remaining_pending counts pending ones too,
1963+
// so they differ exactly while a payment is unconfirmed. Re-quoting then
1964+
// would move the total a customer is part-way through paying.
1965+
if ($remaining === $remaining_pending && $remaining_pending > 0) {
19561966
$cryptapi_coin = $order->get_meta('cryptapi_currency');
19571967

19581968
$crypto_conversion = (float)\CryptAPI\Utils\Api::get_conversion($woocommerce_currency, $cryptapi_coin, $order_total, $this->disable_conversion);
@@ -1969,13 +1979,16 @@ function refresh_value($order)
19691979
}
19701980

19711981
$order->update_meta_data('cryptapi_qr_code_value', $qr_code_data_value['qr_code']);
1972-
1973-
$order->update_meta_data('cryptapi_last_price_update', time());
1974-
$order->save_meta_data();
1975-
1976-
return true;
19771982
}
19781983

1979-
return false;
1984+
// Always advance the price-update timestamp once the interval has
1985+
// elapsed, so the on-page countdown resets to a fresh interval instead
1986+
// of running past zero into negative territory (which the UI otherwise
1987+
// renders as a stuck 00:00 / bogus 59:xx). The rate itself only changes
1988+
// inside the guard above.
1989+
$order->update_meta_data('cryptapi_last_price_update', time());
1990+
$order->save_meta_data();
1991+
1992+
return true;
19801993
}
19811994
}

readme.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: cryptapi
33
Tags: crypto payments, woocommerce, payment gateway, crypto, payment, pay with crypto, payment request, bitcoin, bnb, usdt, ethereum, litecoin, bitcoin cash, shib, doge, solana
44
Requires at least: 5.8
55
Tested up to: 6.9.4
6-
Stable tag: 5.2.1
6+
Stable tag: 5.2.2
77
Requires PHP: 7.2
88
WC requires at least: 5.8
99
WC tested up to: 10.7.0
@@ -434,6 +434,9 @@ The easiest and fastest way is via our live chat on our [website](https://crypta
434434
= 5.2.1 =
435435
* Version bump
436436

437+
= 5.2.2 =
438+
* Minor improvements
439+
437440
== Upgrade Notice ==
438441

439442
= 4.3 =

static/payment.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,12 @@ function check_status(ajax_url) {
9797
}
9898

9999
if (jQuery('.ca_time_refresh')[0]) {
100-
var timer = jQuery('.ca_time_seconds_count');
101-
102-
if (timer.attr('data-seconds') <= 0) {
103-
timer.attr('data-seconds', data.counter);
104-
}
100+
// Re-sync against the server's authoritative remaining seconds on
101+
// every poll by storing an absolute deadline; the 1s tick derives
102+
// the display from it, so drift / background-tab throttling and a
103+
// stale local value can never desync the countdown.
104+
var counter = Math.max(0, parseInt(data.counter, 10) || 0);
105+
jQuery('.ca_time_seconds_count').attr('data-deadline', Math.floor(Date.now() / 1000) + counter);
105106
}
106107
});
107108

@@ -139,20 +140,29 @@ jQuery(function ($) {
139140

140141
if ($('.ca_time_refresh')[0]) {
141142
var refresh_time_span = $('.ca_time_seconds_count'),
142-
refresh_time = refresh_time_span.attr('data-seconds') - 1;
143+
now = Math.floor(Date.now() / 1000),
144+
deadline = parseInt(refresh_time_span.attr('data-deadline'), 10);
145+
146+
if (isNaN(deadline)) {
147+
// Seed the absolute deadline from the server-rendered remaining
148+
// seconds on first run; polls keep it re-synced afterwards.
149+
deadline = now + Math.max(0, parseInt(refresh_time_span.attr('data-seconds'), 10) || 0);
150+
refresh_time_span.attr('data-deadline', deadline);
151+
}
152+
153+
var refresh_time = Math.max(0, deadline - now);
143154

144155
if (refresh_time <= 0) {
145156
refresh_time_span.html('00:00');
146-
refresh_time_span.attr('data-seconds', 0);
147-
return;
148157
} else if (refresh_time <= 30) {
149158
refresh_time_span.html(refresh_time_span.attr('data-soon'));
150-
}
151-
152-
var refresh_minutes = Math.floor(refresh_time % 3600 / 60).toString().padStart(2, '0'),
153-
refresh_seconds = Math.floor(refresh_time % 60).toString().padStart(2, '0');
159+
} else {
160+
var refresh_hours = Math.floor(refresh_time / 3600),
161+
refresh_minutes = Math.floor(refresh_time % 3600 / 60).toString().padStart(2, '0'),
162+
refresh_seconds = Math.floor(refresh_time % 60).toString().padStart(2, '0');
154163

155-
refresh_time_span.html(refresh_minutes + ':' + refresh_seconds);
164+
refresh_time_span.html((refresh_hours > 0 ? refresh_hours.toString().padStart(2, '0') + ':' : '') + refresh_minutes + ':' + refresh_seconds);
165+
}
156166

157167
refresh_time_span.attr('data-seconds', refresh_time);
158168
}

0 commit comments

Comments
 (0)