diff --git a/.wp-env.json b/.wp-env.json index ea1e6ac..6175181 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -1,16 +1,16 @@ { "core": null, "plugins": [ - "./tests/wp-env-helper.php", + "pronamic/wp-env-quick-login", "pronamic/wp-pronamic-pay-test-helper", "https://downloads.wordpress.org/plugin/woocommerce.zip", "https://downloads.wordpress.org/plugin/pronamic-client.zip", + "https://downloads.wordpress.org/plugin/pronamic-ideal.zip", "https://downloads.wordpress.org/plugin/query-monitor.zip", "https://downloads.wordpress.org/plugin/one-time-login.zip", "https://downloads.wordpress.org/plugin/wp-plugin-dependencies.zip" ], "mappings": { - "wp-content/plugins/pronamic-ideal": "../../../", "wp-content/plugins/pronamic-pay-woocommerce": ".", "wp-content/plugins/woocommerce-subscriptions": "https://github.com/pronamic/woocommerce-subscriptions/releases/download/v5.4.0/woocommerce-subscriptions-5.4.0.zip" }, diff --git a/composer.json b/composer.json index 7cd4f84..a462ef0 100644 --- a/composer.json +++ b/composer.json @@ -33,32 +33,6 @@ { "type": "composer", "url": "https://wpackagist.org/" - }, - { - "type": "package", - "package": { - "name": "wp-premium/woocommerce-subscriptions", - "version": "3.0.9", - "type": "wordpress-plugin", - "dist": { - "url": "https://github.com/wp-premium/woocommerce-subscriptions/archive/3.0.9.zip", - "type": "zip" - }, - "source": { - "url": "https://github.com/wp-premium/woocommerce-subscriptions", - "type": "github", - "reference": "tags/3.0.9" - }, - "autoload": { - "classmap": [ - "includes/" - ], - "exclude-from-classmap": [ - "includes/api/legacy/", - "includes/libraries/" - ] - } - } } ], "config": { @@ -73,8 +47,9 @@ }, "require": { "php": ">=7.4", + "automattic/jetpack-autoloader": "^3.0", "pronamic/wp-html": "^2.2", - "wp-pay/core": "^4.9" + "wp-pay/core": "^4.15" }, "require-dev": { "bamarni/composer-bin-plugin": "^1.4", @@ -88,7 +63,6 @@ "roots/wordpress": "^6.0", "wp-cli/wp-cli": "^2.6", "wp-phpunit/wp-phpunit": "^6.1", - "wp-premium/woocommerce-subscriptions": "^3.0", "wpackagist-plugin/woocommerce": "^7.5", "yoast/phpunit-polyfills": "^1.0", "yoast/wordpress-seo": "^19.6" diff --git a/js/dist/admin.asset.php b/js/dist/admin.asset.php new file mode 100644 index 0000000..2718c96 --- /dev/null +++ b/js/dist/admin.asset.php @@ -0,0 +1 @@ + array(), 'version' => '588af650ccb9df87238c'); diff --git a/js/dist/admin.js b/js/dist/admin.js new file mode 100644 index 0000000..b3c0cd0 --- /dev/null +++ b/js/dist/admin.js @@ -0,0 +1 @@ +var PronamicPayWooCommerce;!function(){const o=document.getElementById("woocommerce_pronamic_pay_ideal_icon_display"),e=document.getElementById("woocommerce_pronamic_pay_ideal_icon");if(!o)return;if(!e)return;const n=e.closest("tr");function c(){n.style.display="custom"===o.value?"":"none",console.log(n.display)}n&&(o.addEventListener("change",(function(o){c()})),c())}(),PronamicPayWooCommerce={}; \ No newline at end of file diff --git a/js/src/admin.js b/js/src/admin.js new file mode 100644 index 0000000..423cce1 --- /dev/null +++ b/js/src/admin.js @@ -0,0 +1,32 @@ +function test() { + const displayElement = document.getElementById( 'woocommerce_pronamic_pay_ideal_icon_display' ); + const iconElement = document.getElementById( 'woocommerce_pronamic_pay_ideal_icon' ); + + if ( ! displayElement ) { + return; + } + + if ( ! iconElement ) { + return; + } + + const iconElementRow = iconElement.closest( 'tr' ); + + if ( ! iconElementRow ) { + return; + } + + function update() { + iconElementRow.style.display = ( 'custom' === displayElement.value ) ? '' : 'none'; + + console.log( iconElementRow.display ); + } + + displayElement.addEventListener( 'change', function ( event ) { + update(); + } ); + + update(); +} + +test(); diff --git a/package.json b/package.json index bf8a8c6..1ad2033 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "eslint-plugin-json": "^3.1.0" }, "scripts": { - "build": "wp-scripts build ./js/src/index.js --output-path=./js/dist/", + "build": "wp-scripts build ./js/src/index.js ./js/src/admin.js --output-path=./js/dist/", "lint:js": "wp-scripts lint-js ./js/src", "start": "wp-scripts start ./js/src/index.js --output-path=./js/dist" } diff --git a/pronamic-pay-woocommerce.php b/pronamic-pay-woocommerce.php index 26cc5d8..5266bb1 100644 --- a/pronamic-pay-woocommerce.php +++ b/pronamic-pay-woocommerce.php @@ -30,7 +30,15 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } - + +/** + * Autoload. + */ +require_once __DIR__ . '/vendor/autoload_packages.php'; + +/** + * Bootstrap. + */ add_filter( 'pronamic_pay_plugin_integrations', function ( $integrations ) { diff --git a/src/Extension.php b/src/Extension.php index 56c4f64..10e8a17 100644 --- a/src/Extension.php +++ b/src/Extension.php @@ -113,6 +113,8 @@ public function setup() { * @link https://github.com/pronamic/wp-pronamic-pay-mollie/issues/18#issuecomment-1373362874 */ \add_action( 'woocommerce_order_status_completed', [ $this, 'trigger_payment_fulfilled_action' ], 10, 2 ); + + \add_action( 'admin_enqueue_scripts', [ $this, 'register_scripts' ] ); } /** @@ -1437,4 +1439,21 @@ function () use ( $order ) { 'default' ); } + + /** + * Register scripts. + * + * @return void + */ + public function register_scripts() { + $asset_file = include __DIR__ . '/../js/dist/admin.asset.php'; + + \wp_register_script( + 'pronamic-pay-woocommerce-admin', + \plugins_url( '../js/dist/admin.js', __FILE__ ), + $asset_file['dependencies'], + $asset_file['version'], + true + ); + } } diff --git a/src/Gateway.php b/src/Gateway.php index c514cea..1561022 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -269,6 +269,21 @@ public function init_form_fields() { ), 'default' => '', ], + 'icon_display' => [ + 'title' => __( 'Icon display', 'pronamic_ideal' ), + 'type' => 'select', + 'options' => [ + 'default' => 'default', + 'none' => 'none', + 'custom' => 'custom', + ], + 'description' => sprintf( + '%s%s', + $description_prefix, + __( 'This controls the icon which the user sees during checkout.', 'pronamic_ideal' ) + ), + 'default' => '', + ], 'icon' => [ 'title' => __( 'Icon', 'pronamic_ideal' ), 'type' => 'text', @@ -332,6 +347,17 @@ public function init_form_fields() { } } + /** + * Admin options. + * + * @return void + */ + public function admin_options() { + parent::admin_options(); + + \wp_enqueue_script( 'pronamic-pay-woocommerce-admin' ); + } + /** * Process the payment and return the result. * diff --git a/tests/wp-env-helper.php b/tests/wp-env-helper.php deleted file mode 100644 index 6935a36..0000000 --- a/tests/wp-env-helper.php +++ /dev/null @@ -1,19 +0,0 @@ - - * @copyright 2005-2023 Pronamic - * @license GPL-3.0-or-later - * @package Pronamic\WordPress\Pay\Extensions\WooCommerce - */ - -add_action( - 'plugins_loaded', - function () { - activate_plugin( 'pronamic-ideal/pronamic-ideal.php' ); - activate_plugin( 'pronamic-pay-woocommerce/pronamic-pay-woocommerce.php' ); - activate_plugin( 'woocommerce-subscriptions/woocommerce-subscriptions.php' ); - } -);