Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 37 additions & 12 deletions blockonomics-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,7 @@ function blockonomics_enqueue_custom_admin_style() {
function blockonomics_test_setup() {
include_once plugin_dir_path(__FILE__) . 'php' . DIRECTORY_SEPARATOR . 'Blockonomics.php';
$blockonomics = new Blockonomics;
$result = array();

$result['crypto'] = $blockonomics->testSetup();

wp_send_json($result);
wp_send_json($blockonomics->testSetup());
wp_die();
}

Expand Down Expand Up @@ -386,10 +382,18 @@ function bnomics_display_payment_details($order, $transactions, $email=false)
$total_paid_fiat = $blockonomics->calculate_total_paid_fiat($transactions);
foreach ($transactions as $transaction) {

$base_url = ($transaction['crypto'] === 'btc') ? Blockonomics::BASE_URL . '/#/search?q=' : Blockonomics::BCH_BASE_URL . '/api/tx?txid=';
$crypto = strtolower($transaction['crypto']);
if ( $crypto === 'bch' ) {
$txid_url = Blockonomics::BCH_BASE_URL . '/api/tx?txid=' . $transaction['txid'] . '&addr=' . $transaction['address'];
} elseif ( $crypto === 'usdt' ) {
$subdomain = $blockonomics->is_usdt_tenstnet_active() ? 'sepolia' : 'www';
$txid_url = 'https://' . $subdomain . '.etherscan.io/tx/' . $transaction['txid'];
} else {
$txid_url = Blockonomics::BASE_URL . '/#/search?q=' . $transaction['txid'] . '&addr=' . $transaction['address'];
}

$output .= '<tr><td scope="row">';
$output .= '<a style="word-wrap: break-word;word-break: break-all;" href="' . $base_url . $transaction['txid'] . '&addr=' . $transaction['address'] . '">' . $transaction['txid'] . '</a></td>';
$output .= '<a style="word-wrap: break-word;word-break: break-all;" href="' . $txid_url . '">' . $transaction['txid'] . '</a></td>';
$formatted_paid_fiat = ($transaction['payment_status'] == '2') ? wc_price($transaction['paid_fiat']) : 'Processing';
$output .= '<td>' . $formatted_paid_fiat . '</td></tr>';

Expand Down Expand Up @@ -439,6 +443,7 @@ function bnomics_register_scripts(){
wp_register_script( 'qrious', plugins_url('js/vendors/qrious.min.js', __FILE__), array(), get_plugin_data( __FILE__ )['Version'], array( 'strategy' => 'defer' ) );
wp_register_script( 'copytoclipboard', plugins_url('js/vendors/copytoclipboard.js', __FILE__), array(), get_plugin_data( __FILE__ )['Version'], array( 'strategy' => 'defer' ) );
wp_register_script( 'bnomics-checkout', plugins_url('js/checkout.js', __FILE__), array('reconnecting-websocket', 'qrious','copytoclipboard'), get_plugin_data( __FILE__ )['Version'], array('in_footer' => true, 'strategy' => 'defer' ) );
wp_register_script( 'bnomics-web3-checkout', "https://www.blockonomics.co/js/web3-payment.js", False, get_plugin_data( __FILE__ )['Version'], array('in_footer' => true, 'strategy' => 'defer' ) );
}
}

Expand All @@ -455,7 +460,7 @@ function bnomics_register_scripts(){
} );

global $blockonomics_db_version;
$blockonomics_db_version = '1.4';
$blockonomics_db_version = '1.5';

function blockonomics_create_table() {
// Create blockonomics_payments table
Expand All @@ -473,15 +478,15 @@ function blockonomics_create_table() {
$sql = "CREATE TABLE $table_name (
order_id int NOT NULL,
payment_status int NOT NULL,
crypto varchar(3) NOT NULL,
crypto varchar(4) NOT NULL,
address varchar(191) NOT NULL,
expected_satoshi bigint,
expected_fiat double,
currency varchar(3),
paid_satoshi bigint,
paid_fiat double,
txid text,
PRIMARY KEY (address),
txid varchar(191),
PRIMARY KEY (order_id,crypto,address,txid),
KEY orderkey (order_id,crypto)
) $charset_collate;";
dbDelta( $sql );
Expand Down Expand Up @@ -539,10 +544,20 @@ function blockonomics_run_db_updates($installed_ver){
if (version_compare($installed_ver, '1.2', '<')){
blockonomics_create_table();
}
if (version_compare($installed_ver, '1.4', '<')){ // Plugin version should be 1.4
if (version_compare($installed_ver, '1.4', '<')){
include_once(WC()->plugin_path().'/includes/admin/wc-admin-functions.php');
blockonomics_create_payment_page();
}
if (version_compare($installed_ver, '1.5', '<')){
blockonomics_create_table();
blockonomics_update_primary_key();
// 6. MySQL 8+ only: add partial unique indexes for BTC/USDT
$mysql_version = $wpdb->get_var("SELECT VERSION()");
if (version_compare($mysql_version, '8.0.0', '>=')) {
$wpdb->query("CREATE UNIQUE INDEX unique_btc_address ON $table_name (address) WHERE crypto = 'BTC'");
$wpdb->query("CREATE UNIQUE INDEX unique_usdt_txid ON $table_name (txid) WHERE crypto = 'USDT' AND txid <> ''");
}
}
update_option( 'blockonomics_db_version', $blockonomics_db_version );
}

Expand All @@ -554,6 +569,15 @@ function blockonomics_plugin_setup() {
blockonomics_create_payment_page();
}

function blockonomics_update_primary_key() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Existing installations upgrading from < v1.5 may have BTC/BCH orders with txid = NULL. The migration tries to add txid to the PRIMARY KEY, which fails silently and as a result db stays in old schema while blockonomics_db_version claims "1.5".

Copy link
Collaborator Author

@DarrenWestwood DarrenWestwood Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated function to replace NULL txid with empty string before altering the primary key: 405a638

global $wpdb;
$table_name = $wpdb->prefix . 'blockonomics_payments';
// First replace NULL txid values with empty strings
$wpdb->query("UPDATE $table_name SET txid = '' WHERE txid IS NULL");
$wpdb->query("ALTER TABLE $table_name DROP PRIMARY KEY");
$wpdb->query("ALTER TABLE $table_name ADD PRIMARY KEY (order_id, crypto, address, txid)");
}

//Show message when plugin is activated
function blockonomics_plugin_activation() {
if(!is_plugin_active('woocommerce/woocommerce.php'))
Expand Down Expand Up @@ -589,6 +613,7 @@ function blockonomics_uninstall_hook() {
delete_option('blockonomics_bch');
delete_option('blockonomics_btc');
delete_option('blockonomics_underpayment_slack');
delete_option('blockonomics_usdt_testnet');
// blockonomics_lite is only for db version below 1.3
delete_option('blockonomics_lite');
delete_option('blockonomics_nojs');
Expand Down
6 changes: 5 additions & 1 deletion css/order.css
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ svg {
content: '\e901';
}

.bnomics-icon-usdt:before {
content: "\e902";
}

.bnomics-select-options {
cursor: pointer;
width: 100%;
Expand Down Expand Up @@ -394,7 +398,7 @@ svg {
justify-content: center;
}

.bnomics-order-panel {
.bnomics-order-panel, .bnomics-web3-order-panel {
display: flex;
flex-direction: column;
align-items: center;
Expand Down
Binary file modified fonts/cryptos.woff
Binary file not shown.
Binary file removed img/bch-icon.png
Binary file not shown.
Binary file added img/bch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed img/bitcoin-bch-icon.png
Binary file not shown.
Binary file removed img/bitcoin-icon.png
Binary file not shown.
Binary file added img/btc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/usdt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 40 additions & 22 deletions js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ class BlockonomicsAdmin {

// Initialize crypto DOM elements
this.cryptoElements = {
btc: {
success: document.querySelector('.btc-success-notice'),
error: document.querySelector('.btc-error-notice'),
errorText: document.querySelector('.btc-error-notice .errorText')
}
success: document.querySelector('.notice-success'),
successText: document.querySelector('.notice-success .successText'),
error: document.querySelector('.notice-error'),
errorText: document.querySelector('.notice-error .errorText')
};
}

Expand Down Expand Up @@ -82,7 +81,11 @@ class BlockonomicsAdmin {
if (this.state.apiKeyChanged) {
await this.saveApiKey();
}

const cryptoElements = this.cryptoElements;
cryptoElements.success.style.display = 'none';
cryptoElements.successText.innerHTML = '';
cryptoElements.error.style.display = 'none';
cryptoElements.errorText.innerHTML = '';
const result = await this.performTestSetup();
this.handleTestSetupResponse(result);
} catch (error) {
Expand Down Expand Up @@ -147,26 +150,41 @@ class BlockonomicsAdmin {
}

handleTestSetupResponse(result) {
this.updateCryptoStatus(result.crypto);
this.updateCryptoStatus(result);
this.updateMetadata(result);
}

updateCryptoStatus(cryptoResults) {
const btcResult = cryptoResults.btc;
const btcElements = this.cryptoElements.btc;

if (!btcElements) return;

if (btcResult === false) {
// Success case
btcElements.error.style.display = 'none';
btcElements.success.style.display = 'block';
} else {
// Error case
btcElements.success.style.display = 'none';
btcElements.error.style.display = 'block';
if (typeof btcResult === 'string') {
btcElements.errorText.innerHTML = btcResult;
const cryptoElements = this.cryptoElements;

if (cryptoResults && cryptoResults.error) {
// Handle string error message
cryptoElements.error.style.display = 'block';
cryptoElements.errorText.innerHTML = cryptoResults.error;
return;
}

if (cryptoResults.success_messages) {
// Success cases
cryptoElements.success.style.display = 'block';
for (let index = 0; index < cryptoResults.success_messages.length; index++) {
const crypto = cryptoResults.success_messages[index];
cryptoElements.successText.innerHTML += crypto;
if (index < cryptoResults.success_messages.length - 1) {
cryptoElements.successText.innerHTML += '</br>';
}
}
}

if (cryptoResults.error_messages) {
// Error cases
cryptoElements.error.style.display = 'block';
for (let index = 0; index < cryptoResults.error_messages.length; index++) {
const crypto = cryptoResults.error_messages[index];
cryptoElements.errorText.innerHTML += crypto;
if (index < cryptoResults.error_messages.length - 1) {
cryptoElements.errorText.innerHTML += '</br>';
}
}
}
}
Expand Down
Loading