From 3e05b9187c2ce001f0a271683ab1b315bf0fead0 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 9 Dec 2021 14:28:08 +1100 Subject: [PATCH 1/4] Add WooCommerce Payments features --- features/plugins.php | 1 + features/woocommerce-payments.php | 153 ++++++++++++++++++++++++++++++ lib/stuff.php | 1 + 3 files changed, 155 insertions(+) create mode 100644 features/woocommerce-payments.php diff --git a/features/plugins.php b/features/plugins.php index 70c29d6..957a3b2 100644 --- a/features/plugins.php +++ b/features/plugins.php @@ -27,6 +27,7 @@ function () { 'jetpack' => 'Jetpack', 'mailpoet' => 'Mailpoet', 'vaultpress' => 'VaultPress', + 'woocommerce-payments' => 'WooCommerce Payments', 'woocommerce' => 'WooCommerce', 'wordpress-beta-tester' => 'WordPress Beta Tester Plugin', 'wp-downgrade' => 'WP Downgrade', diff --git a/features/woocommerce-payments.php b/features/woocommerce-payments.php new file mode 100644 index 0000000..a86e249 --- /dev/null +++ b/features/woocommerce-payments.php @@ -0,0 +1,153 @@ + false, + 'woocommerce-payments-dev-tools' => false, + 'woocommerce-payments-jn-options' => false, + 'woocommerce-payments-release' => false, +); + +add_action( + 'jurassic_ninja_init', + function () { + add_action( + 'jurassic_ninja_add_features_before_auto_login', + function ( &$app = null, $features, $domain ) { + $features = array_merge( WCPAY_DEFAULTS, $features ); + if ( ! isset( $features['woocommerce-payments'] ) ) { + if ( $features['woocommerce-payments-branch'] ) { + debug( '%s: Adding WooCommerce Payments (on the %s branch)', $domain, $features['woocommerce-payments-branch'] ); + add_woocommerce_payments_branch_plugin( $features['woocommerce-payments-branch'] ); + } elseif ( $features['woocommerce-payments-release'] ) { + debug( '%s: Adding WooCommerce Payments (version %s)', $domain, $features['woocommerce-payments-release'] ); + add_woocommerce_payments_release_plugin( $features['woocommerce-payments-release'] ); + } + } + + if ( $features['woocommerce-payments-dev-tools'] ) { + debug( '%s: Adding WooCommerce Payments Dev Tools', $domain ); + add_woocommerce_payments_dev_tools(); + } + + if ( $features['woocommerce-payments-jn-options'] ) { + debug( '%s: Adding WooCommerce Payments Jurassic Ninja Options', $domain ); + add_woocommerce_payments_jurassic_ninja_options(); + } + }, + 10, + 3 + ); + + add_filter( + 'jurassic_ninja_rest_feature_defaults', + function ( $defaults ) { + return array_merge( $defaults, WCPAY_DEFAULTS ); + } + ); + + add_filter( + 'jurassic_ninja_rest_create_request_features', + function ( $features, $json_params ) { + if ( isset( $json_params['woocommerce-payments-branch'] ) ) { + $features['woocommerce-payments-branch'] = $json_params['woocommerce-payments-branch']; + } + + if ( isset( $json_params['woocommerce-payments-dev-tools'] ) ) { + $features['woocommerce-payments-dev-tools'] = true; + } + + if ( isset( $json_params['woocommerce-payments-jn-options'] ) ) { + $features['woocommerce-payments-jn-options'] = true; + } + + if ( isset( $json_params['woocommerce-payments-release'] ) ) { + $features['woocommerce-payments-release'] = $json_params['woocommerce-payments-release']; + } + + return $features; + }, + 10, + 2 + ); + } +); + +/** + * Builds, installs and activates the WooCommerce Payments plugin on the site + * for a given branch. + * + * @param string $branch The WooCommerce Payments branch to install. + */ +function add_woocommerce_payments_branch_plugin( $branch ) { + $cmd = 'curl https://gist.githubusercontent.com/aprea/45a7f3b3583ff65a658d303c2e5a6207/raw --output build-woocommerce-payments.sh' + . " && source build-woocommerce-payments.sh $branch" + . ' && wp plugin activate woocommerce-payments'; + + add_filter( + 'jurassic_ninja_feature_command', + function ( $s ) use ( $cmd ) { + return "$s && $cmd"; + } + ); +} + +/** + * Installs and activates the WooCommerce Payments plugin on the site + * for a given release tag. + * + * @param string $release_tag The WooCommerce Payments release tag to install. + */ +function add_woocommerce_payments_release_plugin( $release_tag ) { + $woocommerce_payments_release_tag_url = "https://github.com/Automattic/woocommerce-payments/releases/download/$release_tag/woocommerce-payments.zip"; + $cmd = "wp plugin install $woocommerce_payments_release_tag_url --activate"; + + add_filter( + 'jurassic_ninja_feature_command', + function ( $s ) use ( $cmd ) { + return "$s && $cmd"; + } + ); +} + +/** + * Installs and activates the WooCommerce Payments Dev Tools plugin on the site. + */ +function add_woocommerce_payments_dev_tools() { + $woocommerce_payments_dev_tools_plugin_url = 'https://github.com/Automattic/woocommerce-payments-dev-tools/archive/trunk.zip'; + // We install the trunk version of the plugin. + $cmd = "wp plugin install $woocommerce_payments_dev_tools_plugin_url --activate"; + + add_filter( + 'jurassic_ninja_feature_command', + function ( $s ) use ( $cmd ) { + return "$s && $cmd"; + } + ); +} + +/** + * Adds a set of WordPress options to the site to make it + * easier to work with WooCommerce Payments on + * Jurassic Ninja sites. + */ +function add_woocommerce_payments_jurassic_ninja_options() { + // Disable the WPCOM request proxy and enable UPE and subscriptions features. + $cmd = 'wp option update wcpaydev_proxy 0' + . ' && wp option update _wcpay_feature_upe 1' + . ' && wp option update _wcpay_feature_upe_additional_payment_methods 1' + . ' && wp option update _wcpay_feature_subscriptions 1'; + + add_filter( + 'jurassic_ninja_feature_command', + function ( $s ) use ( $cmd ) { + return "$s && $cmd"; + } + ); +} diff --git a/lib/stuff.php b/lib/stuff.php index 49dfc14..cb3ee7a 100644 --- a/lib/stuff.php +++ b/lib/stuff.php @@ -126,6 +126,7 @@ function require_feature_files() { '/features/gutenberg-nightly.php', '/features/wordpress-4.php', '/features/themes.php', + '/features/woocommerce-payments.php', ); $available_features = apply_filters( 'jurassic_ninja_available_features', $available_features ); From 3b902c0e0c01fa8ae7a519713ef6367117441cfa Mon Sep 17 00:00:00 2001 From: Chris Aprea Date: Thu, 16 Dec 2021 16:10:39 +1100 Subject: [PATCH 2/4] Use the CI version of dev tools plugin repo --- features/woocommerce-payments.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/woocommerce-payments.php b/features/woocommerce-payments.php index a86e249..9a2f1e7 100644 --- a/features/woocommerce-payments.php +++ b/features/woocommerce-payments.php @@ -120,7 +120,7 @@ function ( $s ) use ( $cmd ) { * Installs and activates the WooCommerce Payments Dev Tools plugin on the site. */ function add_woocommerce_payments_dev_tools() { - $woocommerce_payments_dev_tools_plugin_url = 'https://github.com/Automattic/woocommerce-payments-dev-tools/archive/trunk.zip'; + $woocommerce_payments_dev_tools_plugin_url = 'https://github.com/Automattic/woocommerce-payments-dev-tools-ci/archive/trunk.zip'; // We install the trunk version of the plugin. $cmd = "wp plugin install $woocommerce_payments_dev_tools_plugin_url --activate"; From 5794eb4285ce98c02efc577957a9991a5edc0b88 Mon Sep 17 00:00:00 2001 From: Chris Aprea Date: Thu, 16 Dec 2021 18:33:26 +1100 Subject: [PATCH 3/4] Remove the branch feature --- features/woocommerce-payments.php | 35 +++---------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/features/woocommerce-payments.php b/features/woocommerce-payments.php index 9a2f1e7..7832abb 100644 --- a/features/woocommerce-payments.php +++ b/features/woocommerce-payments.php @@ -8,7 +8,6 @@ namespace jn; const WCPAY_DEFAULTS = array( - 'woocommerce-payments-branch' => false, 'woocommerce-payments-dev-tools' => false, 'woocommerce-payments-jn-options' => false, 'woocommerce-payments-release' => false, @@ -21,14 +20,9 @@ function () { 'jurassic_ninja_add_features_before_auto_login', function ( &$app = null, $features, $domain ) { $features = array_merge( WCPAY_DEFAULTS, $features ); - if ( ! isset( $features['woocommerce-payments'] ) ) { - if ( $features['woocommerce-payments-branch'] ) { - debug( '%s: Adding WooCommerce Payments (on the %s branch)', $domain, $features['woocommerce-payments-branch'] ); - add_woocommerce_payments_branch_plugin( $features['woocommerce-payments-branch'] ); - } elseif ( $features['woocommerce-payments-release'] ) { - debug( '%s: Adding WooCommerce Payments (version %s)', $domain, $features['woocommerce-payments-release'] ); - add_woocommerce_payments_release_plugin( $features['woocommerce-payments-release'] ); - } + if ( ! isset( $features['woocommerce-payments'] ) && $features['woocommerce-payments-release'] ) { + debug( '%s: Adding WooCommerce Payments (version %s)', $domain, $features['woocommerce-payments-release'] ); + add_woocommerce_payments_release_plugin( $features['woocommerce-payments-release'] ); } if ( $features['woocommerce-payments-dev-tools'] ) { @@ -55,10 +49,6 @@ function ( $defaults ) { add_filter( 'jurassic_ninja_rest_create_request_features', function ( $features, $json_params ) { - if ( isset( $json_params['woocommerce-payments-branch'] ) ) { - $features['woocommerce-payments-branch'] = $json_params['woocommerce-payments-branch']; - } - if ( isset( $json_params['woocommerce-payments-dev-tools'] ) ) { $features['woocommerce-payments-dev-tools'] = true; } @@ -79,25 +69,6 @@ function ( $features, $json_params ) { } ); -/** - * Builds, installs and activates the WooCommerce Payments plugin on the site - * for a given branch. - * - * @param string $branch The WooCommerce Payments branch to install. - */ -function add_woocommerce_payments_branch_plugin( $branch ) { - $cmd = 'curl https://gist.githubusercontent.com/aprea/45a7f3b3583ff65a658d303c2e5a6207/raw --output build-woocommerce-payments.sh' - . " && source build-woocommerce-payments.sh $branch" - . ' && wp plugin activate woocommerce-payments'; - - add_filter( - 'jurassic_ninja_feature_command', - function ( $s ) use ( $cmd ) { - return "$s && $cmd"; - } - ); -} - /** * Installs and activates the WooCommerce Payments plugin on the site * for a given release tag. From 73b4a0f15b3933bf8448ec5eba8eb180e8499c6c Mon Sep 17 00:00:00 2001 From: Chris Aprea Date: Tue, 4 Jan 2022 09:58:43 +1100 Subject: [PATCH 4/4] Install WooCommerce if installing WooCommerce Payments Co-authored-by: bruce aldridge --- features/woocommerce-payments.php | 1 + 1 file changed, 1 insertion(+) diff --git a/features/woocommerce-payments.php b/features/woocommerce-payments.php index 7832abb..c38472f 100644 --- a/features/woocommerce-payments.php +++ b/features/woocommerce-payments.php @@ -59,6 +59,7 @@ function ( $features, $json_params ) { if ( isset( $json_params['woocommerce-payments-release'] ) ) { $features['woocommerce-payments-release'] = $json_params['woocommerce-payments-release']; + $features['woocommerce'] = true; } return $features;