Plugin Directory

Changeset 3371879


Ignore:
Timestamp:
10/02/2025 03:24:19 PM (5 months ago)
Author:
cryptapi
Message:

v5.1.4 - minor bugfixes

Location:
cryptapi-payment-gateway-for-woocommerce
Files:
2 deleted
6 edited
53 copied

Legend:

Unmodified
Added
Removed
  • cryptapi-payment-gateway-for-woocommerce/tags/5.1.4/CryptAPI.php

    r3329630 r3371879  
    44Plugin URI: https://github.com/cryptapi/woocommerce-cryptapi
    55Description: Accept cryptocurrency payments on your WooCommerce website
    6 Version: 5.1.3
     6Version: 5.1.4
    77Requires at least: 5.8
    8 Tested up to: 6.8.2
     8Tested up to: 6.8.3
    99WC requires at least: 5.8
    10 WC tested up to: 10.0.2
     10WC tested up to: 10.2.2
    1111Requires PHP: 7.2
    1212Author: cryptapi
     
    1818}
    1919
    20 define('CRYPTAPI_PLUGIN_VERSION', '5.1.3');
     20define('CRYPTAPI_PLUGIN_VERSION', '5.1.4');
    2121define('CRYPTAPI_PLUGIN_PATH', plugin_dir_path(__FILE__));
    2222define('CRYPTAPI_PLUGIN_URL', plugin_dir_url(__FILE__));
  • cryptapi-payment-gateway-for-woocommerce/tags/5.1.4/README.md

    r3329630 r3371879  
    418418* Minor bugfixes
    419419
     420#### 5.1.4
     421* Minor bugfixes
     422* Add a refresh coins option
     423
    420424### Upgrade Notice
    421425#### 4.3
  • cryptapi-payment-gateway-for-woocommerce/tags/5.1.4/blocks/CryptAPI.php

    r3286205 r3371879  
    6464        $output_coins = [];
    6565
    66         foreach ($this->get_setting('coins') as $coin) {
    67             $output_coins[] = array_merge(
    68                 ['ticker' => $coin],
    69                 $load_coins[$coin]
    70             );
     66        if ($load_coins) {
     67            foreach ($this->get_setting('coins') as $coin) {
     68                $output_coins[] = array_merge(
     69                    ['ticker' => $coin],
     70                    $load_coins[$coin]
     71                );
     72            }
    7173        }
    7274
  • cryptapi-payment-gateway-for-woocommerce/tags/5.1.4/controllers/CryptAPI.php

    r3260984 r3371879  
    8484
    8585        add_action('woocommerce_admin_order_data_after_order_details', array($this, 'order_detail_validate_logs'));
     86
     87        add_action('admin_post_cryptapi_refresh_coins', [$this, 'handle_admin_refresh_coins']);
    8688    }
    8789
    8890    function reset_load_coins() {
    89         delete_transient('cryptapi_coins');
    90         self::load_coins();
    91     }
    92 
    93     static function load_coins()
    94     {
    95         $transient = get_transient('cryptapi_coins');
    96 
    97         if (!empty($transient)) {
    98             $coins = $transient;
    99         } else {
     91        $now   = time();
     92
     93        try {
    10094            $coins = \CryptAPI\Utils\Api::get_supported_coins();
    101             set_transient('cryptapi_coins', $coins, 86400);
    102 
    10395            if (empty($coins)) {
    104                 throw new Exception(__('No cryptocurrencies available at the moment. Please choose a different payment method or try again later.', 'cryptapi'));
    105             }
    106         }
    107 
    108         # Disabling XMR since it is not supported anymore.
    109         unset($coins['xmr']);
    110 
    111         return $coins;
     96                throw new Exception('No cryptocurrencies available at the moment. Please choose a different payment method or try again later.');
     97            }
     98
     99            update_option('cryptapi_coins_cache', [
     100                'coins'   => $coins,
     101                'expires' => $now + 3600,
     102            ], false);
     103        } catch (Exception $e) {
     104            // We don't want to reset the cache if we can't load the coins.
     105        }
     106    }
     107
     108    static function load_coins() {
     109        $cache = get_option('cryptapi_coins_cache', []);
     110        $now   = time();
     111
     112        try {
     113            if (!empty($cache['coins']) && isset($cache['expires']) && $cache['expires'] > $now) {
     114                $coins = $cache['coins'];
     115            } else {
     116                $coins = \CryptAPI\Utils\Api::get_supported_coins();
     117
     118                if (empty($coins)) {
     119                    throw new Exception('No cryptocurrencies available at the moment. Please choose a different payment method or try again later.');
     120                }
     121
     122                update_option('cryptapi_coins_cache', [
     123                    'coins'   => $coins,
     124                    'expires' => $now + 3600,
     125                ], false);
     126            }
     127
     128            if (isset($coins['xmr'])) {
     129                unset($coins['xmr']);
     130            }
     131
     132            return $coins;
     133        } catch (Exception $e) {
     134            if (!empty($cache['coins'])) {
     135                return $cache['coins'];
     136            }
     137            return [];
     138        }
     139    }
     140
     141    public function handle_admin_refresh_coins() {
     142        if ( ! current_user_can('manage_woocommerce') ) {
     143            wp_die(__('You do not have permission to do this.', 'cryptapi'));
     144        }
     145
     146        check_admin_referer('cryptapi_refresh_coins');
     147
     148        $this->reset_load_coins();
     149
     150        $back = wp_get_referer();
     151        if (!$back) {
     152            $back = admin_url('admin.php?page=wc-settings&tab=checkout&section=' . $this->id);
     153        }
     154        $back = add_query_arg('cryptapi_refreshed', '1', $back);
     155        wp_safe_redirect($back);
     156        exit;
    112157    }
    113158
     
    115160    {
    116161        parent::admin_options();
     162        if (!empty($_GET['cryptapi_refreshed'])) {
     163            echo '<div class="notice notice-success is-dismissible"><p>' .
     164                esc_html__('Cryptocurrency cache refreshed successfully', 'cryptapi') .
     165                '</p></div>';
     166        }
     167        $refresh_url = wp_nonce_url(
     168            admin_url('admin-post.php?action=cryptapi_refresh_coins'),
     169            'cryptapi_refresh_coins'
     170        );
    117171        ?>
     172        <div style="margin-top:1rem; display:flex; gap:.5rem; align-items:center; flex-wrap:wrap;">
     173            <a href="<?php echo esc_url($refresh_url); ?>" class="button button-secondary">
     174                <?php echo esc_html__('Refresh Cryptocurrencies', 'cryptapi'); ?>
     175            </a>
     176            <span class="description">
     177            <?php echo esc_html__('Update the cryptocurrency cache fetching the latest cryptocurrencies. Use this if there is a new token on CryptAPI and you can\'t find in the plugin.', 'cryptapi'); ?>
     178        </span>
     179        </div>
    118180        <div style='margin-top: 2rem;'>
    119181            <?php echo __("If you need any help or have any suggestion, contact us via the <b>live chat</b> on our <b><a href='https://cryptapi.io' target='_blank'>website</a></b> or join our <b><a href='https://discord.gg/cryptapi' target='_blank'>Discord server</a></b>", "cryptapi"); ?>
  • cryptapi-payment-gateway-for-woocommerce/tags/5.1.4/readme.txt

    r3329630 r3371879  
    33Tags: crypto payments, woocommerce, payment gateway, crypto, payment, pay with crypto, payment request, bitcoin, bnb, usdt, ethereum, litecoin, bitcoin cash, shib, doge, solana
    44Requires at least: 5.8
    5 Tested up to: 6.8.2
    6 Stable tag: 5.1.3
     5Tested up to: 6.8.3
     6Stable tag: 5.1.4
    77Requires PHP: 7.2
    88WC requires at least: 5.8
    9 WC tested up to: 10.0.2
     9WC tested up to: 10.2.2
    1010License: MIT
    1111
     
    416416* Minor bugfixes
    417417
     418= 5.1.4 =
     419* Minor bugfixes
     420* Add a refresh coins option
     421
    418422== Upgrade Notice ==
    419423
  • cryptapi-payment-gateway-for-woocommerce/tags/5.1.4/utils/Api.php

    r3257090 r3371879  
    283283        for ($y = 0; $y < 5; $y++) {
    284284            try {
    285                 $response = json_decode(wp_remote_retrieve_body(wp_remote_get($url)), $assoc);
    286 
    287                 if (isset($response->status) && $response->status === 'error') {
     285                $ch = curl_init();
     286                curl_setopt($ch, CURLOPT_URL, $url);
     287                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     288                $response = curl_exec($ch);
     289                curl_close($ch);
     290
     291                $response_json = json_decode($response, $assoc);
     292
     293                if (isset($response_json->status) && $response_json->status === 'error') {
    288294                    // If API is giving error, no point is keeping retrying since result will be the same.
    289                     return $response;
     295                    return $response_json;
    290296                }
    291297
    292                 if ($assoc && !empty($response['btc'])) {
    293                     return $response;
     298                if ($assoc && !empty($response_json['btc'])) {
     299                    return $response_json;
    294300                }
    295301
    296                 if ($response && $response->status === 'success') {
    297                     return $response;
     302                if ($response_json && $response_json->status === 'success') {
     303                    return $response_json;
    298304                }
    299305            } catch (Exception $e) {
  • cryptapi-payment-gateway-for-woocommerce/trunk/CryptAPI.php

    r3329630 r3371879  
    44Plugin URI: https://github.com/cryptapi/woocommerce-cryptapi
    55Description: Accept cryptocurrency payments on your WooCommerce website
    6 Version: 5.1.3
     6Version: 5.1.4
    77Requires at least: 5.8
    8 Tested up to: 6.8.2
     8Tested up to: 6.8.3
    99WC requires at least: 5.8
    10 WC tested up to: 10.0.2
     10WC tested up to: 10.2.2
    1111Requires PHP: 7.2
    1212Author: cryptapi
     
    1818}
    1919
    20 define('CRYPTAPI_PLUGIN_VERSION', '5.1.3');
     20define('CRYPTAPI_PLUGIN_VERSION', '5.1.4');
    2121define('CRYPTAPI_PLUGIN_PATH', plugin_dir_path(__FILE__));
    2222define('CRYPTAPI_PLUGIN_URL', plugin_dir_url(__FILE__));
  • cryptapi-payment-gateway-for-woocommerce/trunk/README.md

    r3329630 r3371879  
    418418* Minor bugfixes
    419419
     420#### 5.1.4
     421* Minor bugfixes
     422* Add a refresh coins option
     423
    420424### Upgrade Notice
    421425#### 4.3
  • cryptapi-payment-gateway-for-woocommerce/trunk/blocks/CryptAPI.php

    r3286205 r3371879  
    6464        $output_coins = [];
    6565
    66         foreach ($this->get_setting('coins') as $coin) {
    67             $output_coins[] = array_merge(
    68                 ['ticker' => $coin],
    69                 $load_coins[$coin]
    70             );
     66        if ($load_coins) {
     67            foreach ($this->get_setting('coins') as $coin) {
     68                $output_coins[] = array_merge(
     69                    ['ticker' => $coin],
     70                    $load_coins[$coin]
     71                );
     72            }
    7173        }
    7274
  • cryptapi-payment-gateway-for-woocommerce/trunk/controllers/CryptAPI.php

    r3260984 r3371879  
    8484
    8585        add_action('woocommerce_admin_order_data_after_order_details', array($this, 'order_detail_validate_logs'));
     86
     87        add_action('admin_post_cryptapi_refresh_coins', [$this, 'handle_admin_refresh_coins']);
    8688    }
    8789
    8890    function reset_load_coins() {
    89         delete_transient('cryptapi_coins');
    90         self::load_coins();
    91     }
    92 
    93     static function load_coins()
    94     {
    95         $transient = get_transient('cryptapi_coins');
    96 
    97         if (!empty($transient)) {
    98             $coins = $transient;
    99         } else {
     91        $now   = time();
     92
     93        try {
    10094            $coins = \CryptAPI\Utils\Api::get_supported_coins();
    101             set_transient('cryptapi_coins', $coins, 86400);
    102 
    10395            if (empty($coins)) {
    104                 throw new Exception(__('No cryptocurrencies available at the moment. Please choose a different payment method or try again later.', 'cryptapi'));
    105             }
    106         }
    107 
    108         # Disabling XMR since it is not supported anymore.
    109         unset($coins['xmr']);
    110 
    111         return $coins;
     96                throw new Exception('No cryptocurrencies available at the moment. Please choose a different payment method or try again later.');
     97            }
     98
     99            update_option('cryptapi_coins_cache', [
     100                'coins'   => $coins,
     101                'expires' => $now + 3600,
     102            ], false);
     103        } catch (Exception $e) {
     104            // We don't want to reset the cache if we can't load the coins.
     105        }
     106    }
     107
     108    static function load_coins() {
     109        $cache = get_option('cryptapi_coins_cache', []);
     110        $now   = time();
     111
     112        try {
     113            if (!empty($cache['coins']) && isset($cache['expires']) && $cache['expires'] > $now) {
     114                $coins = $cache['coins'];
     115            } else {
     116                $coins = \CryptAPI\Utils\Api::get_supported_coins();
     117
     118                if (empty($coins)) {
     119                    throw new Exception('No cryptocurrencies available at the moment. Please choose a different payment method or try again later.');
     120                }
     121
     122                update_option('cryptapi_coins_cache', [
     123                    'coins'   => $coins,
     124                    'expires' => $now + 3600,
     125                ], false);
     126            }
     127
     128            if (isset($coins['xmr'])) {
     129                unset($coins['xmr']);
     130            }
     131
     132            return $coins;
     133        } catch (Exception $e) {
     134            if (!empty($cache['coins'])) {
     135                return $cache['coins'];
     136            }
     137            return [];
     138        }
     139    }
     140
     141    public function handle_admin_refresh_coins() {
     142        if ( ! current_user_can('manage_woocommerce') ) {
     143            wp_die(__('You do not have permission to do this.', 'cryptapi'));
     144        }
     145
     146        check_admin_referer('cryptapi_refresh_coins');
     147
     148        $this->reset_load_coins();
     149
     150        $back = wp_get_referer();
     151        if (!$back) {
     152            $back = admin_url('admin.php?page=wc-settings&tab=checkout&section=' . $this->id);
     153        }
     154        $back = add_query_arg('cryptapi_refreshed', '1', $back);
     155        wp_safe_redirect($back);
     156        exit;
    112157    }
    113158
     
    115160    {
    116161        parent::admin_options();
     162        if (!empty($_GET['cryptapi_refreshed'])) {
     163            echo '<div class="notice notice-success is-dismissible"><p>' .
     164                esc_html__('Cryptocurrency cache refreshed successfully', 'cryptapi') .
     165                '</p></div>';
     166        }
     167        $refresh_url = wp_nonce_url(
     168            admin_url('admin-post.php?action=cryptapi_refresh_coins'),
     169            'cryptapi_refresh_coins'
     170        );
    117171        ?>
     172        <div style="margin-top:1rem; display:flex; gap:.5rem; align-items:center; flex-wrap:wrap;">
     173            <a href="<?php echo esc_url($refresh_url); ?>" class="button button-secondary">
     174                <?php echo esc_html__('Refresh Cryptocurrencies', 'cryptapi'); ?>
     175            </a>
     176            <span class="description">
     177            <?php echo esc_html__('Update the cryptocurrency cache fetching the latest cryptocurrencies. Use this if there is a new token on CryptAPI and you can\'t find in the plugin.', 'cryptapi'); ?>
     178        </span>
     179        </div>
    118180        <div style='margin-top: 2rem;'>
    119181            <?php echo __("If you need any help or have any suggestion, contact us via the <b>live chat</b> on our <b><a href='https://cryptapi.io' target='_blank'>website</a></b> or join our <b><a href='https://discord.gg/cryptapi' target='_blank'>Discord server</a></b>", "cryptapi"); ?>
  • cryptapi-payment-gateway-for-woocommerce/trunk/readme.txt

    r3329630 r3371879  
    33Tags: crypto payments, woocommerce, payment gateway, crypto, payment, pay with crypto, payment request, bitcoin, bnb, usdt, ethereum, litecoin, bitcoin cash, shib, doge, solana
    44Requires at least: 5.8
    5 Tested up to: 6.8.2
    6 Stable tag: 5.1.3
     5Tested up to: 6.8.3
     6Stable tag: 5.1.4
    77Requires PHP: 7.2
    88WC requires at least: 5.8
    9 WC tested up to: 10.0.2
     9WC tested up to: 10.2.2
    1010License: MIT
    1111
     
    416416* Minor bugfixes
    417417
     418= 5.1.4 =
     419* Minor bugfixes
     420* Add a refresh coins option
     421
    418422== Upgrade Notice ==
    419423
  • cryptapi-payment-gateway-for-woocommerce/trunk/utils/Api.php

    r3257090 r3371879  
    283283        for ($y = 0; $y < 5; $y++) {
    284284            try {
    285                 $response = json_decode(wp_remote_retrieve_body(wp_remote_get($url)), $assoc);
    286 
    287                 if (isset($response->status) && $response->status === 'error') {
     285                $ch = curl_init();
     286                curl_setopt($ch, CURLOPT_URL, $url);
     287                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     288                $response = curl_exec($ch);
     289                curl_close($ch);
     290
     291                $response_json = json_decode($response, $assoc);
     292
     293                if (isset($response_json->status) && $response_json->status === 'error') {
    288294                    // If API is giving error, no point is keeping retrying since result will be the same.
    289                     return $response;
     295                    return $response_json;
    290296                }
    291297
    292                 if ($assoc && !empty($response['btc'])) {
    293                     return $response;
     298                if ($assoc && !empty($response_json['btc'])) {
     299                    return $response_json;
    294300                }
    295301
    296                 if ($response && $response->status === 'success') {
    297                     return $response;
     302                if ($response_json && $response_json->status === 'success') {
     303                    return $response_json;
    298304                }
    299305            } catch (Exception $e) {
Note: See TracChangeset for help on using the changeset viewer.