Plugin Directory

Changeset 3457136


Ignore:
Timestamp:
02/09/2026 01:54:16 PM (7 weeks ago)
Author:
jacobo1
Message:

Release 1.0.4: CryptoCompare fallback, safe rate fail, cache docs

Location:
kaspa-payments-gateway-woocommerce
Files:
22 added
3 edited

Legend:

Unmodified
Added
Removed
  • kaspa-payments-gateway-woocommerce/trunk/includes/class-wc-kaspa-gateway.php

    r3446118 r3457136  
    109109
    110110    /**
    111      * Get current KAS rate with caching
     111     * Get current KAS rate with caching.
     112     * Primary: CoinGecko. Fallback: CryptoCompare. If both fail, returns false (checkout shows error).
     113     * Cache TTL is 5 minutes to stay within CoinGecko free tier (10,000 calls/month).
    112114     */
    113115    public function get_kas_rate()
    114116    {
    115         // Check cache first
    116117        $cached_rate = get_transient('kaspa_rate_cache');
    117118        if ($cached_rate !== false) {
     
    119120        }
    120121
    121         // Fetch from API
     122        // Primary: CoinGecko
    122123        $response = wp_remote_get('https://api.coingecko.com/api/v3/simple/price?ids=kaspa&vs_currencies=usd', array(
    123124            'timeout' => 10
    124125        ));
    125126
     127        if (!is_wp_error($response)) {
     128            $body = wp_remote_retrieve_body($response);
     129            $data = json_decode($body, true);
     130            if (isset($data['kaspa']['usd'])) {
     131                $rate = floatval($data['kaspa']['usd']);
     132                set_transient('kaspa_rate_cache', $rate, 300); // 5 min: within CoinGecko free tier 10k calls/month
     133                return $rate;
     134            }
     135        } else {
     136            error_log('Kaspa rate fetch (CoinGecko): ' . $response->get_error_message());
     137        }
     138
     139        // Fallback: CryptoCompare (no API key required for price endpoint)
     140        $response = wp_remote_get('https://min-api.cryptocompare.com/data/price?fsym=KAS&tsyms=USD', array(
     141            'timeout' => 10
     142        ));
     143
    126144        if (is_wp_error($response)) {
    127             error_log('Kaspa rate fetch error: ' . $response->get_error_message());
     145            error_log('Kaspa rate fetch (CryptoCompare): ' . $response->get_error_message());
    128146            return false;
    129147        }
     
    131149        $body = wp_remote_retrieve_body($response);
    132150        $data = json_decode($body, true);
    133 
    134         if (isset($data['kaspa']['usd'])) {
    135             $rate = floatval($data['kaspa']['usd']);
    136             // Cache for 5 minutes
    137             set_transient('kaspa_rate_cache', $rate, 300);
     151        if (isset($data['USD'])) {
     152            $rate = floatval($data['USD']);
     153            set_transient('kaspa_rate_cache', $rate, 300); // 5 min: within CoinGecko free tier 10k calls/month
    138154            return $rate;
    139155        }
     
    148164    {
    149165        $rate = $this->get_kas_rate();
    150         if (!$rate) {
    151             $rate = 0.08; // Fallback rate
     166        if (!$rate || $rate <= 0) {
     167            return 0; // Caller must check rate; do not use a hardcoded fallback
    152168        }
    153169
     
    278294            $kas_rate = $this->get_kas_rate();
    279295
    280             if (!$kas_rate) {
    281                 $kas_rate = 0.08; // Fallback rate
     296            if (!$kas_rate || $kas_rate <= 0) {
     297                throw new Exception(__('Unable to fetch current exchange rate. Please try again or choose another payment method.', 'kaspa-payments-gateway-woocommerce'));
    282298            }
    283299
  • kaspa-payments-gateway-woocommerce/trunk/kaspa-payments-gateway-woocommerce.php

    r3446119 r3457136  
    44 * Plugin URI: https://kaspawoo.com/
    55 * Description: Accept Kaspa (KAS) cryptocurrency payments in WooCommerce with automatic order confirmation and real-time verification. KPUB watch-only wallet for secure, non-custodial payments. This plugin is not officially affiliated with Kaspa or WooCommerce.
    6  * Version: 1.0.3
     6 * Version: 1.0.4
    77 * Requires at least: 5.0
    88 * Requires PHP: 7.4
     
    1212 * License: GPL v2 or later
    1313 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
     14 * Copyright (C) 2024–2025 Jorbach
    1415 * Text Domain: kaspa-payments-gateway-woocommerce
    1516 * Requires Plugins: woocommerce
     
    429430 */
    430431register_activation_hook(__FILE__, 'kasppaga_plugin_activate');
    431 function kasppaga_plugin_activate() {
     432function kasppaga_plugin_activate()
     433{
    432434    // Add the rewrite rule first
    433435    kasppaga_add_payment_rewrite_rule();
     
    440442 */
    441443register_deactivation_hook(__FILE__, 'kasppaga_plugin_deactivate');
    442 function kasppaga_plugin_deactivate() {
     444function kasppaga_plugin_deactivate()
     445{
    443446    flush_rewrite_rules();
    444447}
  • kaspa-payments-gateway-woocommerce/trunk/readme.txt

    r3446119 r3457136  
    44Requires at least: 5.0
    55Tested up to: 6.8
    6 Stable tag: 1.0.3
     6Stable tag: 1.0.4
    77Requires PHP: 7.4
    88License: GPLv2 or later
     
    106106
    107107**CoinGecko API (https://api.coingecko.com)**
    108 * **Purpose**: Provides real-time exchange rates to convert USD order amounts to Kaspa (KAS) cryptocurrency.
     108* **Purpose**: Primary source for real-time exchange rates to convert USD order amounts to Kaspa (KAS) cryptocurrency.
    109109* **Data Sent**: API request for Kaspa/USD exchange rate (no user data).
    110 * **When**: When displaying payment amounts on checkout pages and updating live prices.
     110* **When**: When displaying payment amounts on checkout pages and updating live prices. If CoinGecko is unavailable, the plugin tries CryptoCompare as fallback.
    111111* **Terms of Service**: https://www.coingecko.com/en/terms
    112112* **Privacy Policy**: https://www.coingecko.com/en/privacy
     113
     114**CryptoCompare API (https://min-api.cryptocompare.com)**
     115* **Purpose**: Fallback source for KAS/USD exchange rate when CoinGecko is unavailable.
     116* **Data Sent**: API request for KAS/USD price (no user data).
     117* **When**: Only when CoinGecko fails (e.g. timeout or down). No API key required for the price endpoint used.
     118* **Terms of Service**: https://www.cryptocompare.com/terms
     119* **Privacy Policy**: https://www.cryptocompare.com/privacy-policy
    113120
    114121**QR Server API (https://api.qrserver.com)**
     
    120127
    121128= Changelog =
     129
     130= 1.0.4 =
     131* Added: CryptoCompare as fallback when CoinGecko rate API is unavailable
     132* Changed: Rate fetch now fails safely (no hardcoded fallback) if both APIs fail
     133* Improved: Documented 5-minute rate cache (CoinGecko free tier 10k calls/month)
    122134
    123135= 1.0.3 =
     
    147159== Upgrade Notice ==
    148160
     161= 1.0.4 =
     162Adds CryptoCompare as fallback when CoinGecko is unavailable; rate fetch fails safely if both are down.
     163
    149164= 1.0.3 =
    150165Fixes wallet reset, status display, and payment page routing.
Note: See TracChangeset for help on using the changeset viewer.