I reply to all queries on the forums and via email, once per day, Monday to Friday (not weekends).

If you are new here, please see some information on how to ask for support. Thank you!

Use of the plugin’s front end without the need for JavaScript

dashed-slug.net Forums General discussion Use of the plugin’s front end without the need for JavaScript

Tagged: , ,

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #13598
    dev_wpwork
    Participant

    Hello, I am using this plugin; however, there has arisen a need for everything to work on the client side, including deposits, withdrawals, etc., without the use of JavaScript, i.e., using the Tor browser with maximum security. Is this possible? Is there any function or possibility for customization?

    #13599
    alexg
    Keymaster

    Hello,

    Unfortunately there are no UIs currently that do not require JavaScript.

    I understand the need to avoid JavaScript in cases where tor must be used.

    If you can create your own forms and PHP handlers, then it’s very straightforward to interact with the plugin from PHP using the PHP API. Please see the following link for details and sample code on how to create transactions:

    https://wallets-phpdoc.dashed-slug.net/wallets/classes/DSWallets-Transaction.html

    For example, initiating a withdrawal would require you to create a new withdrawal transaction, and save it on the DB.

    There are also other ways to communicate with the plugin, but I think this is the one that’s relevant to your use case.

    I remain available to answer any questions you may have about this.

    Hope this helps.

    with regards

    #13604
    dev_wpwork
    Participant

    Could you create an example of a plugin that connects to the Wallet and lists the balance? This way, I can follow the same parameters.

    #13605
    alexg
    Keymaster

    Hello,

    You can use the functions in helpers/balances.php to get the balances.

    PHPdocumentor page:

    https://wallets-phpdoc.dashed-slug.net/wallets/files/build-helpers-balances.html

    Note that these functions are all under the DSWallets namespace. So you either need to be in that namespace, or prefix the functions with the namespace. e.g. $balances = DSWallets\get_all_balances_assoc_for_user( $user_id );

    You can see this particular function in action at the plugin’s user profile page code:

    https://github.com/dashed-slug/wallets/blob/6.2.4/admin/profile.php#L97-L216

    To be clear, this is the code that displays user balances in the user profile admin screen.

    Note the difference between balances and available_balances. The links point to the glossary.

    Please let me know if you have any more questions about anything.

    with regards

    #13606
    dev_wpwork
    Participant

    Thank you for this, it helped a lot, I was able to display the customer’s balance on the customer’s page through a plugin using your documentation, but now I’m having difficulty generating an address, I used the parameter described in this topic: https://wallets- phpdoc.dashed-slug.net/wallets/classes/DSWallets-Wallet-Adapter.html#method_get_new_address but I was not successful in returning the wallet adapter, is there any topic that helps in communicating with the bitcoin wallet adapter?

    but thank you for your attention

    Here is the plugin code, just for testing I left the code with both features together

    add_shortcode(‘exibir_saldos’, ‘exibir_saldos_usuario’);

    function exibir_saldos_usuario() {
    if (!function_exists(‘DSWallets\get_all_currencies’) || !function_exists(‘DSWallets\get_balance_for_user_and_currency_id’)) {
    return ‘As funções necessárias do plugin não estão disponíveis.’;
    }

    $user_id = get_current_user_id();
    if (!$user_id) {
    return ‘Usuário não identificado.’;
    }

    $currencies = DSWallets\get_all_currencies();
    $output = ‘<div class=”saldos-de-moedas”>’;

    foreach ($currencies as $currency) {
    // Certifique-se de que o objeto $currency tem a propriedade ou método esperado para obter o currency_id
    // Esta linha é um palpite sobre como você poderia acessar o currency_id corretamente
    $currency_id = property_exists($currency, ‘post_id’) ? $currency->post_id : 0; // Ajuste conforme necessário

    $saldo = DSWallets\get_balance_for_user_and_currency_id($user_id, $currency_id);
    $formatted_balance = number_format($saldo * pow(10, -$currency->decimals), $currency->decimals, ‘.’, ”);

    $output .= ‘<div class=”moeda”>’;
    $output .= ‘<span class=”nome-moeda”>’ . esc_html($currency->name) . ‘</span>: ‘;
    $output .= ‘<span class=”saldo-moeda”>’ . esc_html($formatted_balance) . ‘ ‘ . esc_html($currency->symbol) . ‘</span>’;
    $output .= ‘</div>’;
    }

    $output .= ‘</div>’;
    return $output;
    }

    function gerar_novo_endereco() {
    $currency = null;
    $wallets = new Wallets();
    $new_address = $wallets->get_new_address($currency);

    return $new_address->get_address();
    }

    add_shortcode(‘gerar_endereco’, ‘gerar_novo_endereco’);

    #13608
    alexg
    Keymaster

    Hello,

    The code you provided does not work because you are creating a class Wallets that does not exist. There is a DSWallets\Wallet class that contains an adapter object of DSWallets\Wallet_Adapter class. The wallet adapter is an object that holds the connection information to the wallet as well as the code to communicate with the wallet. You can call get_new_address on the wallet adapter to get a new address.

    Once you have a $currency object, here’s how to generate a new address:

    $new_address = $currency->wallet->adapter->get_new_address( $currency );

    (It’s necessary to pass the currency into the method because there are wallets with multiple currencies e.g. CoinPayments wallet)

    It’s best to wrap this in a try..catch, because if there is any problem with communication with the wallet, this can throw.

    So, to put it all together:

    try {

    $new_address = $currency->wallet->adapter->get_new_address( $currency );

    } catch ( \Exception $e ) {
    error_log( “Could not generate a new address for $currency because: ” . $e.getMessage() );
    }

    In general, the UIs that require JavaScript, communicate with the plugin via its RESTful API, which is here and documented here.

    If you check out the code for the various API endpoints, you can see example code for the basic operations.

    Hope this helps.

    Please let me know if you have any more questions. I want to answer all of them and help you with your project.

    with regards

    #13610
    dev_wpwork
    Participant

    Hello friend,

    Thank you for all the help. I was able to adjust the code so that it generates the address in the wallet and creates a transaction in the “Wallet” plugin. The only point I still haven’t been able to resolve was that after making a deposit and crediting the user’s balance, I tried to make a withdrawal, but the process remains pending.

    In the log of the transaction itself, I verified that it passes all the checks successfully, but it seems that for some reason it does not actually perform the action of making the withdrawal. So, I activated the log and will perform a new withdrawal test to see what happens.

    An important point that I noticed is that as soon as I activated the log, I could notice an interesting error that talks about two tables missing in the database. Should I be worried about this?

    [11-Apr-2024 16:56:09 UTC] [1712854569] Bitcoin and Altcoin Wallets: Starting cron tasks!
    [11-Apr-2024 16:56:09 UTC] [1712854569] Bitcoin and Altcoin Wallets: DSWallets\Migration_Task: Task started.
    [11-Apr-2024 16:56:09 UTC] [1712854569] Bitcoin and Altcoin Wallets: DSWallets\Migration_Task: Running migration task: {“type”:”none”,”add_count”:false,”add_count_ok”:0,”add_count_fail”:0,”add_last_id”:false,”tx_count”:false,”tx_count_ok”:0,”tx_count_fail”:0,”tx_last_id”:false,”bal_last_uid”:0,”bal_pending”:[]}
    [11-Apr-2024 16:56:09 UTC] WordPress database error Table ‘website2.wp_wallets_adds’ doesn’t exist for query SELECT COUNT(*) FROM wp_wallets_adds WHERE 0 OR blog_id = 1 made by do_action_ref_array(‘wallets_cron_tasks’), WP_Hook->do_action, WP_Hook->apply_filters, DSWallets\Task->DSWallets\{closure}, DSWallets\Migration_Task->run
    [11-Apr-2024 16:56:09 UTC] WordPress database error Table ‘website2.wp_wallets_txs’ doesn’t exist for query SELECT COUNT(*) FROM wp_wallets_txs WHERE 0 OR blog_id = 1 made by do_action_ref_array(‘wallets_cron_tasks’), WP_Hook->do_action, WP_Hook->apply_filters, DSWallets\Task->DSWallets\{closure}, DSWallets\Migration_Task->run

    Another interesting point is that I acquired the plugin to finalize a purchase using the balance. However, to my surprise, after making the deposit and validating the user’s balance, I noticed that when reaching the checkout screen, the plugin announces that the user does not have an available balance.

    So, I left a version for testing with JavaScript and its original shortcodes to validate the functionalities. I verified that there seems to be some error, certainly in configuration on my part, as the shortcode itself seems to be relating the decimal places incorrectly. Thus, it appears that there is not enough balance to finalize a purchase.

    However, if I check the user’s balance in the WordPress management panel, the balance is there and matches exactly with the balance in the code I developed. I am sure this must be some wrong configuration on my part. If you could help me with this, it would be appreciated.

    I am also attaching some evidence to support everything I am saying.

    Attachments:
    You must be logged in to view attached files.
    #13612
    alexg
    Keymaster

    Hello,

    The error you mentioned is unavoidable. It’s simply the plugin checking whether there needs to be a migration from the old custom SQL tables that existed in versions before 6.0.0. Nothing to worry about.

    If you enable verbose logging in the settings, you will get more detail in the wordpress debug log on how the transactions are executed.

    The available balance does not count pending transactions, while the normal user balance does.

    Transactions, including deposits and withdrawals should be initiated in a pending state by your code, then they should either transition into a done or to a fail state by the wallet adapter. Does your transaction remain in a pending state?

    I am not sure what the problem you describe is. Can you please provide screenshots of the currency page and of the transaction page screens? You can either post them here or email me, whichever you prefer.

    Looking forward to your reply.

    with regards

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.