@@ -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}
0 commit comments