diff --git a/assets/js/main.js b/assets/js/main.js index 1677d7a..58270c2 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -7,9 +7,6 @@ $(window).on('click', function(e) { if (e.target == modal[0]) { modal.hide(); - if (CryptoPayApp.reset) { - CryptoPayApp.reset(); - } } }); @@ -58,28 +55,33 @@ }); }); } else if (key == 'dokan_cryptopay_lite') { - CryptoPayLite.networks = [ - details.network, - ]; - - CryptoPayApp = CryptoPayLite.startPayment({ + let order = { amount, currency, - }, { + } + + let params = { receiver: details.receiver, - }); + } - CryptoPayLite.hooks.transactionSent = (n, tx) => { + if (!CryptoPayApp) { + CryptoPayApp = window.CryptoPayLiteApp.start(order, params); + } else { + CryptoPayApp.reStart(order, params); + } + + CryptoPayApp.store.config.set('networks', [details.network]); + + window.CryptoPayLiteApp.events.add('transactionReceived', ({transaction}) => { approve.trigger('click'); - cpHelpers.successPopup(CryptoPayLite.lang.transactionSent, ` - - ${CryptoPayLite.lang.openInExplorer} + cplHelpers.successPopup(window.CryptoPayLiteLang.transactionSent, ` + + ${window.CryptoPayLiteLang.openInExplorer} `).then(() => { modal.hide(); - CryptoPayApp.reset(); }); - } + }); } }); diff --git a/classes/DokanCryptoPayWithdrawal.php b/classes/DokanCryptoPayWithdrawal.php index 6035795..15f6eb7 100644 --- a/classes/DokanCryptoPayWithdrawal.php +++ b/classes/DokanCryptoPayWithdrawal.php @@ -11,8 +11,10 @@ use BeycanPress\CryptoPay\Helpers; use BeycanPress\CryptoPay\Payment; use BeycanPress\CryptoPay\PluginHero\Hook; -use BeycanPress\CryptoPay\Types\Data\PaymentDataType; -use BeycanPress\CryptoPayLite\Services as LiteServices; +// Lite +use BeycanPress\CryptoPayLite\Settings\EvmChains; +use BeycanPress\CryptoPayLite\Helpers as LiteHelpers; +use BeycanPress\CryptoPayLite\Payment as LitePayment; use BeycanPress\CryptoPayLite\PluginHero\Hook as LiteHook; // @phpcs:ignore @@ -28,6 +30,11 @@ class DokanCryptoPayWithdrawal */ private string $key; + /** + * @var array|null + */ + private ?array $networks = null; + /** * @var array|null */ @@ -59,7 +66,7 @@ public function __construct(string $title, string $key) if ($this->key == 'dokan_cryptopay') { Helpers::registerIntegration($this->key); Hook::addFilter('apply_discount_' . $this->key, '__return_false'); - Hook::addFilter('receiver_' . $this->key, function (string $receiver, PaymentDataType $data) { + Hook::addFilter('receiver_' . $this->key, function (string $receiver, object $data) { if ($data->getParams()->get('receiver')) { return $data->getParams()->get('receiver'); } @@ -67,7 +74,7 @@ public function __construct(string $title, string $key) return $receiver; }, 10, 2); } else { - LiteServices::registerAddon($this->key); + LiteHelpers::registerIntegration($this->key); LiteHook::addFilter('apply_discount_' . $this->key, '__return_false'); LiteHook::addFilter('receiver_' . $this->key, function (string $receiver, object $data) { if (isset($data->params->receiver)) { @@ -123,7 +130,7 @@ private function isSelected(object $network, array $networkItem): bool return false; } - if ($networkItem['code'] == 'evmBased') { + if ($networkItem['code'] == 'evmchains') { $res = $networkItem['id'] == $network->id; } else { $res = $networkItem['code'] == $network->code; @@ -136,6 +143,24 @@ private function isSelected(object $network, array $networkItem): bool return $res; } + /** + * @return array + */ + private function getNetworksById(): array + { + if (LiteHelpers::getTestnetStatus()) { + $networks = file_get_contents(DOKAN_CRYPTOPAY_PATH . '/resources/testnets.json'); + } else { + $networks = file_get_contents(DOKAN_CRYPTOPAY_PATH . '/resources/mainnets.json'); + } + + $networks = json_decode($networks, true); + + return array_filter($networks, function ($network) { + return in_array($network['id'], EvmChains::getNetworks()); + }); + } + /** * @param array $args * @return void @@ -148,9 +173,9 @@ public function userSettingForm(array $args): void $address = isset($settings['address']) ? $settings['address'] : ''; if ($this->key == 'dokan_cryptopay') { - $networks = Helpers::getNetworks()->toArray(); + $this->networks = Helpers::getNetworks()->toArray(); } else { - $networks = LiteServices::getNetworks(); + $this->networks = $this->getNetworksById(); } ?> @@ -162,7 +187,7 @@ public function userSettingForm(array $args): void
- currentNetwork['currencies'] as $currencyItem) : ?> + currentNetwork) { + $this->currentNetwork = $this->networks[0]; + } + foreach ($this->currentNetwork['currencies'] as $currencyItem) : ?> - +
@@ -370,7 +400,7 @@ public function runCryptoPay(): string if ($this->key == 'dokan_cryptopay') { return (new Payment($this->key))->setConfirmation(false)->html(); } else { - return LiteServices::preparePaymentProcess($this->key, false); + return (new LitePayment($this->key))->setConfirmation(false)->html(); } } } diff --git a/dokan-cryptopay-withdrawal.php b/dokan-cryptopay-withdrawal.php index 28e6610..c9f8d3b 100644 --- a/dokan-cryptopay-withdrawal.php +++ b/dokan-cryptopay-withdrawal.php @@ -10,7 +10,7 @@ /** * Plugin Name: Dokan - CryptoPay Withdrawal - * Version: 1.0.2 + * Version: 1.0.3 * Plugin URI: https://beycanpress.com/cryptopay/ * Description: Add custom cryptocurrency withdrawal method to Dokan plugin * Author: BeycanPress LLC @@ -29,8 +29,9 @@ use BeycanPress\CryptoPayLite\Loader as LiteLoader; define('DOKAN_CRYPTOPAY_FILE', __FILE__); -define('DOKAN_CRYPTOPAY_VERSION', '1.0.2'); +define('DOKAN_CRYPTOPAY_VERSION', '1.0.3'); define('DOKAN_CRYPTOPAY_URL', plugin_dir_url(__FILE__)); +define('DOKAN_CRYPTOPAY_PATH', plugin_dir_path(__FILE__)); add_action('plugins_loaded', function (): void { require_once __DIR__ . '/classes/DokanCryptoPayWithdrawal.php'; diff --git a/readme.txt b/readme.txt index 9ee39f7..49ff725 100644 --- a/readme.txt +++ b/readme.txt @@ -4,8 +4,8 @@ Tags: Bitcoin, Ethereum, Binance Smart Chain, Blockchain, Networks, Cryptocurren Requires at least: 5.0 Tested up to: 6.4.2 Requires PHP: 8.1 -Stable Tag: 1.0.2 -Version: 1.0.2 +Stable Tag: 1.0.3 +Version: 1.0.3 License: GPLv3 License URI: https://www.gnu.org/licenses/gpl-3.0.html diff --git a/resources/mainnets.json b/resources/mainnets.json new file mode 100644 index 0000000..cfc0d71 --- /dev/null +++ b/resources/mainnets.json @@ -0,0 +1,155 @@ +[ + { + "id" : 1, + "hexId" : "0x1", + "name" : "Ethereum", + "code" : "evmchains", + "rpcUrl" : "https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161", + "explorerUrl" : "https://etherscan.io/", + "nativeCurrency" : { + "symbol" : "ETH", + "decimals" : 18 + }, + "wallets": [ + "metamask", + "trustwallet", + "bitget", + "okx", + "xdefi" + ], + "currencies": [ + { + "symbol" : "ETH" + }, + { + "symbol" : "USDT", + "address" : "0xdac17f958d2ee523a2206206994597c13d831ec7" + }, + { + "symbol" : "USDC", + "address" : "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" + }, + { + "symbol" : "BUSD", + "address" : "0x4Fabb145d64652a948d72533023f6E7A623C7C53" + } + ] + }, + { + "id" : 56, + "hexId" : "0x38", + "name" : "BNB Smart Chain", + "code" : "evmchains", + "rpcUrl" : "https://bsc-dataseed.binance.org/", + "explorerUrl" : "https://bscscan.com/", + "nativeCurrency" : { + "symbol" : "BNB", + "decimals" : 18 + }, + "wallets": [ + "metamask", + "trustwallet", + "bitget", + "okx", + "xdefi", + "binancewallet" + ], + "currencies": [ + { + "symbol" : "BNB" + }, + { + "symbol" : "BUSD", + "address" : "0xe9e7cea3dedca5984780bafc599bd69add087d56" + }, + { + "symbol" : "USDT", + "address" : "0x55d398326f99059ff775485246999027b3197955" + }, + { + "symbol" : "USDC", + "address" : "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d" + } + ] + }, + { + "id" : 43114, + "hexId" : "0xa86a", + "name" : "Avalanche C-Chain", + "code" : "evmchains", + "rpcUrl" : "https://api.avax.network/ext/bc/C/rpc", + "explorerUrl" : "https://cchain.explorer.avax.network/", + "nativeCurrency" : { + "symbol" : "AVAX", + "decimals" : 18 + }, + "wallets": [ + "metamask", + "trustwallet", + "bitget", + "okx", + "xdefi" + ], + "currencies": [ + { + "symbol" : "AVAX" + }, + { + "symbol" : "USDT", + "address" : "0xde3a24028580884448a5397872046a019649b084" + } + ] + }, + { + "id" : 137, + "hexId" : "0x89", + "name" : "Polygon", + "code" : "evmchains", + "rpcUrl" : "https://polygon-rpc.com/", + "explorerUrl" : "https://polygonscan.com/", + "nativeCurrency" : { + "symbol" : "MATIC", + "decimals" : 18 + }, + "wallets": [ + "metamask", + "trustwallet", + "bitget", + "okx", + "xdefi" + ], + "currencies": [ + { + "symbol" : "MATIC" + }, + { + "symbol" : "USDT", + "address" : "0xc2132d05d31c914a87c6611c10748aeb04b58e8f" + } + ] + }, + { + "id" : 250, + "hexId" : "0xfa", + "name" : "Fantom", + "code" : "evmchains", + "rpcUrl" : "https://rpc.fantom.network", + "explorerUrl" : "https://ftmscan.com/", + "nativeCurrency" : { + "symbol" : "FTM", + "decimals" : 18 + }, + "wallets": [ + "metamask", + "trustwallet", + "bitget", + "okx", + "xdefi" + ], + "currencies": [ + { + "symbol" : "FTM" + } + ] + } +] \ No newline at end of file diff --git a/resources/testnets.json b/resources/testnets.json new file mode 100644 index 0000000..06e25a1 --- /dev/null +++ b/resources/testnets.json @@ -0,0 +1,144 @@ +[ + { + "id" : 11155111, + "hexId" : "0xaa36a7", + "mainnetId" : 1, + "code" : "evmchains", + "name" : "Ethereum Sepolia Testnet", + "rpcUrl" : "https://sepolia.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161", + "explorerUrl" : "https://sepolia.etherscan.io/", + "nativeCurrency" : { + "symbol" : "ETH", + "decimals" : 18 + }, + "wallets": [ + "metamask", + "trustwallet", + "bitget", + "okx", + "xdefi" + ], + "currencies": [ + { + "symbol" : "ETH" + } + ] + }, + { + "id" : 97, + "hexId" : "0x61", + "mainnetId" : 56, + "code" : "evmchains", + "name" : "BNB Smart Chain Testnet", + "rpcUrl" : "https://bsc-testnet.publicnode.com", + "explorerUrl" : "https://testnet.bscscan.com/", + "nativeCurrency" : { + "symbol" : "BNB", + "decimals" : 18 + }, + "wallets": [ + "metamask", + "trustwallet", + "bitget", + "okx", + "xdefi", + "binancewallet" + ], + "currencies": [ + { + "symbol" : "BNB" + }, + { + "symbol" : "BUSD", + "address" : "0xeD24FC36d5Ee211Ea25A80239Fb8C4Cfd80f12Ee" + }, + { + "symbol" : "USDT", + "address" : "0xba6670261a05b8504e8ab9c45d97a8ed42573822" + } + ] + }, + { + "id" : 43113, + "hexId" : "0xa869", + "mainnetId" : 43114, + "code" : "evmchains", + "name" : "Avalanche FUJI C-Chain Testnet", + "rpcUrl" : "https://api.avax-test.network/ext/bc/C/rpc", + "explorerUrl" : "https://cchain.explorer.avax-test.network", + "nativeCurrency" : { + "symbol" : "AVAX", + "decimals" : 18 + }, + "wallets": [ + "metamask", + "trustwallet", + "bitget", + "okx", + "xdefi" + ], + "currencies": [ + { + "symbol" : "AVAX" + }, + { + "symbol" : "USDT", + "address" : "0xFe143522938e253e5Feef14DB0732e9d96221D72" + } + ] + }, + { + "id" : 80001, + "hexId" : "0x13881", + "mainnetId" : 137, + "code" : "evmchains", + "name" : "Polygon Mumbai Testnet", + "rpcUrl" : "https://rpc-mumbai.maticvigil.com/", + "explorerUrl" : "https://mumbai.polygonscan.com/", + "nativeCurrency" : { + "symbol" : "MATIC", + "decimals" : 18 + }, + "wallets": [ + "metamask", + "trustwallet", + "bitget", + "okx", + "xdefi" + ], + "currencies": [ + { + "symbol" : "MATIC" + }, + { + "symbol" : "USDT", + "address" : "0xa02f6adc7926efebbd59fd43a84f4e0c0c91e832" + } + ] + }, + { + "id" : 4002, + "hexId" : "0xfa2", + "mainnetId" : 250, + "code" : "evmchains", + "name" : "Fantom Testnet", + "rpcUrl" : "https://rpc.testnet.fantom.network/", + "explorerUrl" : "https://testnet.ftmscan.com/", + "nativeCurrency" : { + "symbol" : "FTM", + "decimals" : 18 + }, + "wallets": [ + "metamask", + "trustwallet", + "bitget", + "okx", + "xdefi" + ], + "currencies": [ + { + "symbol" : "FTM" + } + ] + } +] \ No newline at end of file