This repository has been archived by the owner on Sep 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #249 from Automattic/add/woocommerce-payments-feat…
…ures Add WooCommerce Payments features
- Loading branch information
Showing
3 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters