Skip to content

Conversation

@DarrenWestwood
Copy link
Collaborator

@DarrenWestwood DarrenWestwood commented Sep 1, 2025

Includes USDT payments.
Done:

  • All db, checkout, payment, and callback functionality

Still todo:

  • Update the test setup/checkout to check the store setup and enable/disable USDT accordingly
  • Refactor multiplier functionality to a single location in the supported crypto data:
'usdt' => array(
        'code' => 'usdt',
        'name' => 'USDT',
        'decimals' => 6
)
  • Include USDT specific tests
  • Testnet check missing from callbacks

@anktd
Copy link
Collaborator

anktd commented Oct 13, 2025

There is another issue. After completing USDT payment in MetaMask, users are redirected to an error page instead of order confirmation:

Error updating transaction! Please contact support with your order id and transaction hash.
Order ID: 170
Transaction Hash: 0xb9d7b9cb54af5c616ffcee14085284d9cd6b6d3d50c3b590ed97e2ce8ad2081a

This is a direct consequence of earlier bug. Here's the failure chain:

  1. User creates checkout → process_order(170, 'usdt') called
  2. Address generation succeeds → Returns 0x8f82... (same address as a previous order)
  3. insert_order() fails silently due to duplicate PRIMARY KEY on address $this->insert_order($order)
  4. Order row never inserted, but function continues executing
  5. Checkout page loads successfully (no error displayed)
  6. User pays via MetaMask → Transaction 0xb9d7b9cb... confirmed
  7. Redirect triggers process_token_order(170, 'usdt', '0xb9d7b9...')
  8. update_order_txhash() searches for order 170 → Finds nothing (row doesn't exist)
  9. Returns false → Error message displayed

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

Comment on lines +911 to +913
SELECT 1 FROM $table_name
WHERE (crypto = 'BTC' AND address = %s)
OR (crypto = 'USDT' AND txid <> '' AND txid = %s)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The check never prevents duplicate USDT addresses with empty txids. Thus, for same USDT wallet on server, attempting USDT checkout produces duplicate key error. For ex.

WordPress database error: [Duplicate entry '0x8f8210db9eEADD080Bbf45108f15106a3C4636A2' for key 'PRIMARY']
INSERT INTO wp_blockonomics_payments (order_id, crypto, address, txid, payment_status, currency, expected_fiat, expected_satoshi)
SELECT 68, 'usdt', '0x8f8210db9eEADD080Bbf45108f15106a3C4636A2', '', 0, 'USD', 0, 99906
FROM DUAL WHERE NOT EXISTS (...)

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.

This error also looks related to the primary key not being updated. Should be resolved now, but included error handling for insert_order() to avoid cases like this in the future: 01454a2

@anktd
Copy link
Collaborator

anktd commented Oct 13, 2025

USDT Checkout shows amounts like $0.999006 instead of $1 creating bad UX. We can add USDT specific 2 decimal rounding to fix_displaying_small_values() so amounts on checkout are cleaner. How this is handled in whmcs

@DarrenWestwood
Copy link
Collaborator Author

USDT Checkout shows amounts like $0.999006 instead of $1 creating bad UX. We can add USDT specific 2 decimal rounding to fix_displaying_small_values() so amounts on checkout are cleaner. How this is handled in whmcs

We should not round the values passed to the web3 payment component, as this will lead to the incorrect amount being paid. We can round values for display purposes, but this should be done in the web3 payment itself.

$error_messages = [];

foreach ($enabled_cryptos as $code) {
$response = $this->new_address($code, true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We are using the reset=1 param when doing test setup, this has problems with BTC:

  1. Primary key error on subsequent checkout
  2. Test setup resulting in false positives (say, instead of displaying gap limit error)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this is a known issue where gap limit issues are not tested in Test Setup.

  1. Reset parameter in test setup should not create any issues with primary key, since this address will not be saved to the database.
  2. This is the same as existing behaviour and the WHMCS.

@anktd
Copy link
Collaborator

anktd commented Oct 26, 2025

Additional things we need fix before merging this PR:

  1. USDT txn link on Order Confirmation page incorrectly point to Blockonomics BCH Explorer instead of etherscan.io
  2. During test setup, error parsing do not handle nested error object structures. API returns error in format {"status": 500, "error": {"message": "...", "code": 1008}} and we are only checking for $body->message and $body->error_code, missing $body->error->message. This causes error like gap limit to be ignored on test setup.

@DarrenWestwood
Copy link
Collaborator Author

  1. Updated usdt txn link on Order Confirmation page
  2. Updated handling of error messages. This will also be required in the WHMCS module: https://github.com/blockonomics/whmcs-bitcoin-plugin/blob/master/modules/gateways/blockonomics/blockonomics.php#L465-L472
  3. Removed auto update callback url if partial match

@shivaenigma
Copy link
Collaborator

image

@shivaenigma
Copy link
Collaborator

image

@shivaenigma shivaenigma merged commit 7c51e17 into master Oct 30, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants