Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #249 from Automattic/add/woocommerce-payments-feat…
Browse files Browse the repository at this point in the history
…ures

Add WooCommerce Payments features
  • Loading branch information
Chris Aprea authored Feb 7, 2022
2 parents 173035b + 73b4a0f commit 1e81ff3
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 0 deletions.
1 change: 1 addition & 0 deletions features/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
125 changes: 125 additions & 0 deletions features/woocommerce-payments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php
/**
* WooCommerce Payments
*
* @package jurassic-ninja
*/

namespace jn;

const WCPAY_DEFAULTS = array(
'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'] ) && $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-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'];
$features['woocommerce'] = true;
}

return $features;
},
10,
2
);
}
);

/**
* 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-ci/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";
}
);
}
1 change: 1 addition & 0 deletions lib/stuff.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,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 );
Expand Down

0 comments on commit 1e81ff3

Please sign in to comment.