From 5454e2eb2ae17e4f144481970f34e12811e72111 Mon Sep 17 00:00:00 2001 From: Halil Beycan <50718965+BeycanDeveloper@users.noreply.github.com> Date: Sat, 20 Jul 2024 23:01:47 +0800 Subject: [PATCH] updated --- assets/css/main.css | 23 ---------------- assets/js/main.js | 33 +++++++++++------------ classes/DokanCryptoPayWithdrawal.php | 6 +++-- cryptopay-withdrawal-for-dokan.php | 40 +++++++++++----------------- readme.txt | 9 ++++--- 5 files changed, 40 insertions(+), 71 deletions(-) delete mode 100644 assets/css/main.css diff --git a/assets/css/main.css b/assets/css/main.css deleted file mode 100644 index 01c45ee..0000000 --- a/assets/css/main.css +++ /dev/null @@ -1,23 +0,0 @@ -.dokan-cryptopay-modal { - width: 100%; - height: 100%; - position: fixed; - top: 0; - left: 0; - z-index: 999999; - background-color: rgba(0, 0, 0, 0.5); - display: none; -} - -.dokan-cryptopay-modal .dokan-cryptopay-modal-content { - width: auto; - height: auto; - background-color: #fff; - position: absolute; - top: 50%; - left: 50%; - transform: translate(-50%, -50%); - padding: 20px; - border-radius: 8px; - min-width: 400px; -} \ No newline at end of file diff --git a/assets/js/main.js b/assets/js/main.js index ffc0447..ed5e156 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -3,20 +3,15 @@ $(document).ready(() => { let CryptoPayApp; const __ = wp.i18n.__; - const modal = $(".dokan-cryptopay-modal"); - $(window).on('click', function(e) { - if (e.target == modal[0]) { - modal.hide(); - } - }); - - $(document).on('click', '.pay-with-cryptopay', function(e) { + $(document).on('click', '.pay-with-cryptopay', async function() { let key = $(this).data('key'); let parent = $(this).closest('tr'); let details = $(this).data('details'); let currency = DokanCryptoPay.currency; + let helpers = window.cpHelpers ?? window.cplHelpers; let approve = parent.find(".actions .button-group button:eq(0)"); + const modal = window.CryptoPayApp?.modal ?? window.CryptoPayLiteApp?.modal let amount = parseFloat(parent.find(".amount div").text().replace(/[^a-zA-Z0-9.,]/g, "").trim()); details = { @@ -25,8 +20,6 @@ currency: JSON.parse(details.currency), } - modal.show(); - if (key == 'dokan_cryptopay') { let order = { amount, @@ -40,23 +33,25 @@ if (!CryptoPayApp) { CryptoPayApp = window.CryptoPayApp.start(order, params); } else { - CryptoPayApp.reStart(order, params); + await CryptoPayApp.reStart(order, params); } + modal.open(); + CryptoPayApp.store.config.set('networks', [details.network]); window.CryptoPayApp.events.add('transactionReceived', ({transaction}) => { approve.trigger('click'); $(this).prop('disabled', true) $(this).text(__('Processing...')) - cpHelpers.successPopup(window.CryptoPayLang.transactionSent, ` + helpers.successPopup(window.CryptoPayLang.transactionSent, ` ${window.CryptoPayLang.openInExplorer} `).then(() => { - modal.hide(); + modal.close(); }); - }); + }, 'dokan'); } else if (key == 'dokan_cryptopay_lite') { let order = { amount, @@ -70,23 +65,25 @@ if (!CryptoPayApp) { CryptoPayApp = window.CryptoPayLiteApp.start(order, params); } else { - CryptoPayApp.reStart(order, params); + await CryptoPayApp.reStart(order, params); } + modal.open(); + CryptoPayApp.store.config.set('networks', [details.network]); window.CryptoPayLiteApp.events.add('transactionReceived', ({transaction}) => { approve.trigger('click'); $(this).prop('disabled', true) $(this).text(__('Processing...')) - cplHelpers.successPopup(window.CryptoPayLiteLang.transactionSent, ` + helpers.successPopup(window.CryptoPayLiteLang.transactionSent, ` ${window.CryptoPayLiteLang.openInExplorer} `).then(() => { - modal.hide(); + modal.close(); }); - }); + }, 'dokan'); } }); diff --git a/classes/DokanCryptoPayWithdrawal.php b/classes/DokanCryptoPayWithdrawal.php index ba9cdfb..aa2406a 100644 --- a/classes/DokanCryptoPayWithdrawal.php +++ b/classes/DokanCryptoPayWithdrawal.php @@ -66,6 +66,7 @@ public function __construct(string $title, string $key) if ('dokan_cryptopay' == $this->key) { Helpers::registerIntegration($this->key); + Hook::addFilter('mode_' . $this->key, fn () => 'network'); Hook::addFilter('apply_discount_' . $this->key, '__return_false'); Hook::addFilter('receiver_' . $this->key, function (string $receiver, object $data) { if ($data->getParams()->get('receiver')) { @@ -76,6 +77,7 @@ public function __construct(string $title, string $key) }, 10, 2); } else { LiteHelpers::registerIntegration($this->key); + LiteHook::addFilter('mode_' . $this->key, fn () => 'network'); LiteHook::addFilter('apply_discount_' . $this->key, '__return_false'); LiteHook::addFilter('receiver_' . $this->key, function (string $receiver, object $data) { if ($data->getParams()->get('receiver')) { @@ -410,9 +412,9 @@ function getCustomPaymentDetails(details, method, data) { public function runCryptoPay(): string { if ('dokan_cryptopay' == $this->key) { - return (new Payment($this->key))->setConfirmation(false)->html(); + return (new Payment($this->key))->setConfirmation(false)->modal(); } else { - return (new LitePayment($this->key))->setConfirmation(false)->html(); + return (new LitePayment($this->key))->setConfirmation(false)->modal(); } } } diff --git a/cryptopay-withdrawal-for-dokan.php b/cryptopay-withdrawal-for-dokan.php index 12315f8..0c47e2b 100644 --- a/cryptopay-withdrawal-for-dokan.php +++ b/cryptopay-withdrawal-for-dokan.php @@ -10,7 +10,7 @@ /** * Plugin Name: CryptoPay Withdrawal for Dokan - * Version: 1.0.5 + * Version: 1.0.6 * Plugin URI: https://beycanpress.com/cryptopay/ * Description: Add custom cryptocurrency withdrawal method to Dokan plugin * Author: BeycanPress LLC @@ -20,7 +20,7 @@ * Text Domain: dokan-cryptopay * Tags: Cryptopay, Cryptocurrency, WooCommerce, WordPress, MetaMask, Trust, Binance, Wallet, Ethereum, Bitcoin, Binance smart chain, Payment, Plugin, Gateway, Moralis, Converter, API, coin market cap, CMC * Requires at least: 5.0 - * Tested up to: 6.5.5 + * Tested up to: 6.6 * Requires PHP: 8.1 */ @@ -29,7 +29,7 @@ use BeycanPress\CryptoPayLite\Loader as LiteLoader; define('DOKAN_CRYPTOPAY_FILE', __FILE__); -define('DOKAN_CRYPTOPAY_VERSION', '1.0.3'); +define('DOKAN_CRYPTOPAY_VERSION', '1.0.6'); define('DOKAN_CRYPTOPAY_URL', plugin_dir_url(__FILE__)); define('DOKAN_CRYPTOPAY_PATH', plugin_dir_path(__FILE__)); @@ -70,30 +70,20 @@ 'currency' => get_woocommerce_currency(), 'apiUrl' => home_url('/wp-json/dokan/v1/withdraw/') ]); - - wp_enqueue_style('dokan-cryptopay', plugin_dir_url(__FILE__) . 'assets/css/main.css', [], DOKAN_CRYPTOPAY_VERSION); }); add_action('admin_footer', function () use ($gateway): void { - echo ' -