Changeset 3457136
- Timestamp:
- 02/09/2026 01:54:16 PM (7 weeks ago)
- Location:
- kaspa-payments-gateway-woocommerce
- Files:
-
- 22 added
- 3 edited
-
tags/1.0.4 (added)
-
tags/1.0.4/LICENSE (added)
-
tags/1.0.4/assets (added)
-
tags/1.0.4/assets/js (added)
-
tags/1.0.4/assets/js/index.asset.php (added)
-
tags/1.0.4/assets/js/index.js (added)
-
tags/1.0.4/assets/kaspa-admin.css (added)
-
tags/1.0.4/assets/kaspa-admin.js (added)
-
tags/1.0.4/assets/kaspa-checkout.css (added)
-
tags/1.0.4/assets/kaspa-checkout.js (added)
-
tags/1.0.4/assets/kaspa-crypto-bundle.js (added)
-
tags/1.0.4/assets/kaspa-wallet-setup.css (added)
-
tags/1.0.4/assets/kaspa-wallet-setup.js (added)
-
tags/1.0.4/assets/kaspa-wallet.js (added)
-
tags/1.0.4/includes (added)
-
tags/1.0.4/includes/class-kaspa-admin-dashboard.php (added)
-
tags/1.0.4/includes/class-wc-kaspa-gateway.php (added)
-
tags/1.0.4/includes/kaspa-frontend-assets.php (added)
-
tags/1.0.4/includes/kaspa-transaction-polling.php (added)
-
tags/1.0.4/includes/kaspa-wallet-setup.php (added)
-
tags/1.0.4/kaspa-payments-gateway-woocommerce.php (added)
-
tags/1.0.4/readme.txt (added)
-
trunk/includes/class-wc-kaspa-gateway.php (modified) (5 diffs)
-
trunk/kaspa-payments-gateway-woocommerce.php (modified) (4 diffs)
-
trunk/readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
kaspa-payments-gateway-woocommerce/trunk/includes/class-wc-kaspa-gateway.php
r3446118 r3457136 109 109 110 110 /** 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). 112 114 */ 113 115 public function get_kas_rate() 114 116 { 115 // Check cache first116 117 $cached_rate = get_transient('kaspa_rate_cache'); 117 118 if ($cached_rate !== false) { … … 119 120 } 120 121 121 // Fetch from API122 // Primary: CoinGecko 122 123 $response = wp_remote_get('https://api.coingecko.com/api/v3/simple/price?ids=kaspa&vs_currencies=usd', array( 123 124 'timeout' => 10 124 125 )); 125 126 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 126 144 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()); 128 146 return false; 129 147 } … … 131 149 $body = wp_remote_retrieve_body($response); 132 150 $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 138 154 return $rate; 139 155 } … … 148 164 { 149 165 $rate = $this->get_kas_rate(); 150 if (!$rate ) {151 $rate = 0.08; // Fallback rate166 if (!$rate || $rate <= 0) { 167 return 0; // Caller must check rate; do not use a hardcoded fallback 152 168 } 153 169 … … 278 294 $kas_rate = $this->get_kas_rate(); 279 295 280 if (!$kas_rate ) {281 $kas_rate = 0.08; // Fallback rate296 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')); 282 298 } 283 299 -
kaspa-payments-gateway-woocommerce/trunk/kaspa-payments-gateway-woocommerce.php
r3446119 r3457136 4 4 * Plugin URI: https://kaspawoo.com/ 5 5 * 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. 36 * Version: 1.0.4 7 7 * Requires at least: 5.0 8 8 * Requires PHP: 7.4 … … 12 12 * License: GPL v2 or later 13 13 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 14 * Copyright (C) 2024–2025 Jorbach 14 15 * Text Domain: kaspa-payments-gateway-woocommerce 15 16 * Requires Plugins: woocommerce … … 429 430 */ 430 431 register_activation_hook(__FILE__, 'kasppaga_plugin_activate'); 431 function kasppaga_plugin_activate() { 432 function kasppaga_plugin_activate() 433 { 432 434 // Add the rewrite rule first 433 435 kasppaga_add_payment_rewrite_rule(); … … 440 442 */ 441 443 register_deactivation_hook(__FILE__, 'kasppaga_plugin_deactivate'); 442 function kasppaga_plugin_deactivate() { 444 function kasppaga_plugin_deactivate() 445 { 443 446 flush_rewrite_rules(); 444 447 } -
kaspa-payments-gateway-woocommerce/trunk/readme.txt
r3446119 r3457136 4 4 Requires at least: 5.0 5 5 Tested up to: 6.8 6 Stable tag: 1.0. 36 Stable tag: 1.0.4 7 7 Requires PHP: 7.4 8 8 License: GPLv2 or later … … 106 106 107 107 **CoinGecko API (https://api.coingecko.com)** 108 * **Purpose**: Pr ovidesreal-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. 109 109 * **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. 111 111 * **Terms of Service**: https://www.coingecko.com/en/terms 112 112 * **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 113 120 114 121 **QR Server API (https://api.qrserver.com)** … … 120 127 121 128 = 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) 122 134 123 135 = 1.0.3 = … … 147 159 == Upgrade Notice == 148 160 161 = 1.0.4 = 162 Adds CryptoCompare as fallback when CoinGecko is unavailable; rate fetch fails safely if both are down. 163 149 164 = 1.0.3 = 150 165 Fixes wallet reset, status display, and payment page routing.
Note: See TracChangeset
for help on using the changeset viewer.