@@ -142,11 +142,7 @@ function blockonomics_enqueue_custom_admin_style() {
142142 function blockonomics_test_setup () {
143143 include_once plugin_dir_path (__FILE__ ) . 'php ' . DIRECTORY_SEPARATOR . 'Blockonomics.php ' ;
144144 $ blockonomics = new Blockonomics ;
145- $ result = array ();
146-
147- $ result ['crypto ' ] = $ blockonomics ->testSetup ();
148-
149- wp_send_json ($ result );
145+ wp_send_json ($ blockonomics ->testSetup ());
150146 wp_die ();
151147 }
152148
@@ -386,10 +382,18 @@ function bnomics_display_payment_details($order, $transactions, $email=false)
386382 $ total_paid_fiat = $ blockonomics ->calculate_total_paid_fiat ($ transactions );
387383 foreach ($ transactions as $ transaction ) {
388384
389- $ base_url = ($ transaction ['crypto ' ] === 'btc ' ) ? Blockonomics::BASE_URL . '/#/search?q= ' : Blockonomics::BCH_BASE_URL . '/api/tx?txid= ' ;
385+ $ crypto = strtolower ($ transaction ['crypto ' ]);
386+ if ( $ crypto === 'bch ' ) {
387+ $ txid_url = Blockonomics::BCH_BASE_URL . '/api/tx?txid= ' . $ transaction ['txid ' ] . '&addr= ' . $ transaction ['address ' ];
388+ } elseif ( $ crypto === 'usdt ' ) {
389+ $ subdomain = $ blockonomics ->is_usdt_tenstnet_active () ? 'sepolia ' : 'www ' ;
390+ $ txid_url = 'https:// ' . $ subdomain . '.etherscan.io/tx/ ' . $ transaction ['txid ' ];
391+ } else {
392+ $ txid_url = Blockonomics::BASE_URL . '/#/search?q= ' . $ transaction ['txid ' ] . '&addr= ' . $ transaction ['address ' ];
393+ }
390394
391395 $ output .= '<tr><td scope="row"> ' ;
392- $ output .= '<a style="word-wrap: break-word;word-break: break-all;" href=" ' . $ base_url . $ transaction [ ' txid ' ] . ' &addr= ' . $ transaction [ ' address ' ] . '"> ' . $ transaction ['txid ' ] . '</a></td> ' ;
396+ $ output .= '<a style="word-wrap: break-word;word-break: break-all;" href=" ' . $ txid_url . '"> ' . $ transaction ['txid ' ] . '</a></td> ' ;
393397 $ formatted_paid_fiat = ($ transaction ['payment_status ' ] == '2 ' ) ? wc_price ($ transaction ['paid_fiat ' ]) : 'Processing ' ;
394398 $ output .= '<td> ' . $ formatted_paid_fiat . '</td></tr> ' ;
395399
@@ -439,6 +443,7 @@ function bnomics_register_scripts(){
439443 wp_register_script ( 'qrious ' , plugins_url ('js/vendors/qrious.min.js ' , __FILE__ ), array (), get_plugin_data ( __FILE__ )['Version ' ], array ( 'strategy ' => 'defer ' ) );
440444 wp_register_script ( 'copytoclipboard ' , plugins_url ('js/vendors/copytoclipboard.js ' , __FILE__ ), array (), get_plugin_data ( __FILE__ )['Version ' ], array ( 'strategy ' => 'defer ' ) );
441445 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 ' ) );
446+ 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 ' ) );
442447 }
443448}
444449
@@ -455,7 +460,7 @@ function bnomics_register_scripts(){
455460} );
456461
457462global $ blockonomics_db_version ;
458- $ blockonomics_db_version = '1.4 ' ;
463+ $ blockonomics_db_version = '1.5 ' ;
459464
460465function blockonomics_create_table () {
461466 // Create blockonomics_payments table
@@ -473,15 +478,15 @@ function blockonomics_create_table() {
473478 $ sql = "CREATE TABLE $ table_name (
474479 order_id int NOT NULL,
475480 payment_status int NOT NULL,
476- crypto varchar(3 ) NOT NULL,
481+ crypto varchar(4 ) NOT NULL,
477482 address varchar(191) NOT NULL,
478483 expected_satoshi bigint,
479484 expected_fiat double,
480485 currency varchar(3),
481486 paid_satoshi bigint,
482487 paid_fiat double,
483- txid text ,
484- PRIMARY KEY (address),
488+ txid varchar(191) ,
489+ PRIMARY KEY (order_id,crypto, address,txid ),
485490 KEY orderkey (order_id,crypto)
486491 ) $ charset_collate; " ;
487492 dbDelta ( $ sql );
@@ -539,10 +544,20 @@ function blockonomics_run_db_updates($installed_ver){
539544 if (version_compare ($ installed_ver , '1.2 ' , '< ' )){
540545 blockonomics_create_table ();
541546 }
542- if (version_compare ($ installed_ver , '1.4 ' , '< ' )){ // Plugin version should be 1.4
547+ if (version_compare ($ installed_ver , '1.4 ' , '< ' )){
543548 include_once (WC ()->plugin_path ().'/includes/admin/wc-admin-functions.php ' );
544549 blockonomics_create_payment_page ();
545550 }
551+ if (version_compare ($ installed_ver , '1.5 ' , '< ' )){
552+ blockonomics_create_table ();
553+ blockonomics_update_primary_key ();
554+ // 6. MySQL 8+ only: add partial unique indexes for BTC/USDT
555+ $ mysql_version = $ wpdb ->get_var ("SELECT VERSION() " );
556+ if (version_compare ($ mysql_version , '8.0.0 ' , '>= ' )) {
557+ $ wpdb ->query ("CREATE UNIQUE INDEX unique_btc_address ON $ table_name (address) WHERE crypto = 'BTC' " );
558+ $ wpdb ->query ("CREATE UNIQUE INDEX unique_usdt_txid ON $ table_name (txid) WHERE crypto = 'USDT' AND txid <> '' " );
559+ }
560+ }
546561 update_option ( 'blockonomics_db_version ' , $ blockonomics_db_version );
547562}
548563
@@ -554,6 +569,15 @@ function blockonomics_plugin_setup() {
554569 blockonomics_create_payment_page ();
555570}
556571
572+ function blockonomics_update_primary_key () {
573+ global $ wpdb ;
574+ $ table_name = $ wpdb ->prefix . 'blockonomics_payments ' ;
575+ // First replace NULL txid values with empty strings
576+ $ wpdb ->query ("UPDATE $ table_name SET txid = '' WHERE txid IS NULL " );
577+ $ wpdb ->query ("ALTER TABLE $ table_name DROP PRIMARY KEY " );
578+ $ wpdb ->query ("ALTER TABLE $ table_name ADD PRIMARY KEY (order_id, crypto, address, txid) " );
579+ }
580+
557581//Show message when plugin is activated
558582function blockonomics_plugin_activation () {
559583 if (!is_plugin_active ('woocommerce/woocommerce.php ' ))
@@ -589,6 +613,7 @@ function blockonomics_uninstall_hook() {
589613 delete_option ('blockonomics_bch ' );
590614 delete_option ('blockonomics_btc ' );
591615 delete_option ('blockonomics_underpayment_slack ' );
616+ delete_option ('blockonomics_usdt_testnet ' );
592617 // blockonomics_lite is only for db version below 1.3
593618 delete_option ('blockonomics_lite ' );
594619 delete_option ('blockonomics_nojs ' );
0 commit comments