mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
Add boilerplate for react settings app
This commit is contained in:
parent
53af77897f
commit
9c5d978707
14 changed files with 10671 additions and 2 deletions
|
@ -90,5 +90,12 @@ return function ( string $root_dir ): iterable {
|
|||
$modules[] = ( require "$modules_dir/ppcp-axo-block/module.php" )();
|
||||
}
|
||||
|
||||
if ( apply_filters(
|
||||
'woocommerce.feature-flags.woocommerce_paypal_payments.settings_enabled',
|
||||
getenv( 'PCP_SETTINGS_ENABLED' ) === '1'
|
||||
) ) {
|
||||
$modules[] = ( require "$modules_dir/ppcp-settings/module.php" )();
|
||||
}
|
||||
|
||||
return $modules;
|
||||
};
|
||||
|
|
16
modules/ppcp-settings/composer.json
Normal file
16
modules/ppcp-settings/composer.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "woocommerce/ppcp-settings",
|
||||
"type": "inpsyde-module",
|
||||
"description": "Settings module",
|
||||
"license": "GPL-2.0",
|
||||
"require": {
|
||||
"php": "^7.4 | ^8.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"WooCommerce\\PayPalCommerce\\Settings\\": "src"
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true
|
||||
}
|
14
modules/ppcp-settings/module.php
Normal file
14
modules/ppcp-settings/module.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
/**
|
||||
* The Settings module.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Settings
|
||||
*/
|
||||
|
||||
declare( strict_types = 1 );
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Settings;
|
||||
|
||||
return static function () : SettingsModule {
|
||||
return new SettingsModule();
|
||||
};
|
12
modules/ppcp-settings/package.json
Normal file
12
modules/ppcp-settings/package.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"name": "ppcp-settings",
|
||||
"version": "1.0.0",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"scripts": {
|
||||
"watch": "wp-scripts start --webpack-src-dir=resources/js --output-path=assets",
|
||||
"build": "wp-scripts build --webpack-src-dir=resources/js --output-path=assets"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@wordpress/scripts": "^30.3.0"
|
||||
}
|
||||
}
|
1
modules/ppcp-settings/resources/css/style.scss
Normal file
1
modules/ppcp-settings/resources/css/style.scss
Normal file
|
@ -0,0 +1 @@
|
|||
.red {color:red;}
|
3
modules/ppcp-settings/resources/js/App.js
Normal file
3
modules/ppcp-settings/resources/js/App.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
export function App() {
|
||||
return <div className="red">App</div>;
|
||||
}
|
18
modules/ppcp-settings/resources/js/index.js
Normal file
18
modules/ppcp-settings/resources/js/index.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
import React from 'react';
|
||||
import * as ReactDOM from 'react-dom/client';
|
||||
import { App } from './App';
|
||||
|
||||
ReactDOM.createRoot(
|
||||
document.getElementById( 'ppcp-settings-container' )
|
||||
).render( <App /> );
|
||||
|
||||
/*
|
||||
import React from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import { App } from './App';
|
||||
|
||||
createRoot( document.getElementById( 'ppcp-settings-container' ) ).render(
|
||||
<App />
|
||||
);
|
||||
|
||||
*/
|
26
modules/ppcp-settings/services.php
Normal file
26
modules/ppcp-settings/services.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
/**
|
||||
* The Settings module services.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Settings
|
||||
*/
|
||||
|
||||
declare( strict_types = 1 );
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Settings;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
return array(
|
||||
'settings.url' => static function ( ContainerInterface $container ) : string {
|
||||
/**
|
||||
* The path cannot be false.
|
||||
*
|
||||
* @psalm-suppress PossiblyFalseArgument
|
||||
*/
|
||||
return plugins_url(
|
||||
'/modules/ppcp-settings/',
|
||||
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
|
||||
);
|
||||
},
|
||||
);
|
78
modules/ppcp-settings/src/SettingsModule.php
Normal file
78
modules/ppcp-settings/src/SettingsModule.php
Normal file
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
/**
|
||||
* The Settings module.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\AxoBlock
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace WooCommerce\PayPalCommerce\Settings;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
|
||||
/**
|
||||
* Class SettingsModule
|
||||
*/
|
||||
class SettingsModule implements ServiceModule, ExecutableModule {
|
||||
use ModuleClassNameIdTrait;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function services(): array {
|
||||
return require __DIR__ . '/../services.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function run( ContainerInterface $container ): bool {
|
||||
add_action(
|
||||
'admin_enqueue_scripts',
|
||||
function( $hook_suffix ) use ( $container ) {
|
||||
if ( 'woocommerce_page_wc-settings' !== $hook_suffix ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$script_asset_file = require dirname( realpath( __FILE__ ), 2 ) . '/assets/index.asset.php';
|
||||
$module_url = $container->get( 'settings.url' );
|
||||
|
||||
wp_register_script(
|
||||
'ppcp-admin-settings',
|
||||
$module_url . '/assets/index.js',
|
||||
$script_asset_file['dependencies'],
|
||||
$script_asset_file['version'],
|
||||
true
|
||||
);
|
||||
|
||||
wp_enqueue_script( 'ppcp-admin-settings' );
|
||||
|
||||
$stlye_asset_file = require dirname( realpath( __FILE__ ), 2 ) . '/assets/style.asset.php';
|
||||
wp_register_style(
|
||||
'ppcp-admin-settings',
|
||||
$module_url . '/assets/style-style.css',
|
||||
$stlye_asset_file['dependencies'],
|
||||
$stlye_asset_file['version']
|
||||
);
|
||||
|
||||
wp_enqueue_style( 'ppcp-admin-settings' );
|
||||
}
|
||||
);
|
||||
|
||||
add_action(
|
||||
'woocommerce_paypal_payments_gateway_admin_options_wrapper',
|
||||
function( PayPalGateway $gateway ) {
|
||||
global $hide_save_button;
|
||||
$hide_save_button = true;
|
||||
|
||||
echo '<div id="ppcp-settings-container"></div>';
|
||||
}
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
12
modules/ppcp-settings/webpack.config.js
Normal file
12
modules/ppcp-settings/webpack.config.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
|
||||
const path = require( 'path' );
|
||||
|
||||
module.exports = {
|
||||
...defaultConfig,
|
||||
...{
|
||||
entry: {
|
||||
index: path.resolve( process.cwd(), 'resources/js', 'index.js' ),
|
||||
style: path.resolve( process.cwd(), 'resources/css', 'style.scss' ),
|
||||
},
|
||||
},
|
||||
};
|
10453
modules/ppcp-settings/yarn.lock
Normal file
10453
modules/ppcp-settings/yarn.lock
Normal file
File diff suppressed because it is too large
Load diff
|
@ -118,7 +118,8 @@ return array(
|
|||
$container->get( 'wcgateway.place-order-button-text' ),
|
||||
$container->get( 'api.endpoint.payment-tokens' ),
|
||||
$container->get( 'vaulting.vault-v3-enabled' ),
|
||||
$container->get( 'vaulting.wc-payment-tokens' )
|
||||
$container->get( 'vaulting.wc-payment-tokens' ),
|
||||
$container->get( 'wcgateway.settings.admin-settings-enabled' )
|
||||
);
|
||||
},
|
||||
'wcgateway.credit-card-gateway' => static function ( ContainerInterface $container ): CreditCardGateway {
|
||||
|
@ -1914,4 +1915,8 @@ return array(
|
|||
|
||||
return $simple_redirect_tasks;
|
||||
},
|
||||
|
||||
'wcgateway.settings.admin-settings-enabled' => static function( ContainerInterface $container ): bool {
|
||||
return $container->has( 'settings.url' );
|
||||
},
|
||||
);
|
||||
|
|
|
@ -202,6 +202,13 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
*/
|
||||
private $wc_payment_tokens;
|
||||
|
||||
/**
|
||||
* Whether settings module is enabled.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $admin_settings_enabled;
|
||||
|
||||
/**
|
||||
* PayPalGateway constructor.
|
||||
*
|
||||
|
@ -225,6 +232,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
* @param PaymentTokensEndpoint $payment_tokens_endpoint Payment tokens endpoint.
|
||||
* @param bool $vault_v3_enabled Whether Vault v3 module is enabled.
|
||||
* @param WooCommercePaymentTokens $wc_payment_tokens WooCommerce payment tokens.
|
||||
* @param bool $admin_settings_enabled Whether settings module is enabled.
|
||||
*/
|
||||
public function __construct(
|
||||
SettingsRenderer $settings_renderer,
|
||||
|
@ -246,7 +254,8 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
string $place_order_button_text,
|
||||
PaymentTokensEndpoint $payment_tokens_endpoint,
|
||||
bool $vault_v3_enabled,
|
||||
WooCommercePaymentTokens $wc_payment_tokens
|
||||
WooCommercePaymentTokens $wc_payment_tokens,
|
||||
bool $admin_settings_enabled
|
||||
) {
|
||||
$this->id = self::ID;
|
||||
$this->settings_renderer = $settings_renderer;
|
||||
|
@ -270,6 +279,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
$this->payment_tokens_endpoint = $payment_tokens_endpoint;
|
||||
$this->vault_v3_enabled = $vault_v3_enabled;
|
||||
$this->wc_payment_tokens = $wc_payment_tokens;
|
||||
$this->admin_settings_enabled = $admin_settings_enabled;
|
||||
|
||||
$default_support = array(
|
||||
'products',
|
||||
|
@ -745,6 +755,17 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the parent admin_options method.
|
||||
*/
|
||||
public function admin_options() {
|
||||
if ( ! $this->admin_settings_enabled ) {
|
||||
parent::admin_options();
|
||||
}
|
||||
|
||||
do_action( 'woocommerce_paypal_payments_gateway_admin_options_wrapper', $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the settings renderer.
|
||||
*
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
"install:modules:ppcp-onboarding": "cd modules/ppcp-onboarding && yarn install",
|
||||
"install:modules:ppcp-card-fields": "cd modules/ppcp-card-fields && yarn install",
|
||||
"install:modules:ppcp-compat": "cd modules/ppcp-compat && yarn install",
|
||||
"install:modules:ppcp-settings": "cd modules/ppcp-settings && yarn install",
|
||||
"install:modules:ppcp-uninstall": "cd modules/ppcp-uninstall && yarn install",
|
||||
"build:modules:ppcp-admin-notices": "cd modules/ppcp-admin-notices && yarn run build",
|
||||
"build:modules:ppcp-applepay": "cd modules/ppcp-applepay && yarn run build",
|
||||
|
@ -47,6 +48,7 @@
|
|||
"build:modules:ppcp-card-fields": "cd modules/ppcp-card-fields && yarn run build",
|
||||
"build:modules:ppcp-compat": "cd modules/ppcp-compat && yarn run build",
|
||||
"build:modules:ppcp-uninstall": "cd modules/ppcp-uninstall && yarn run build",
|
||||
"build:modules:ppcp-settings": "cd modules/ppcp-settings && yarn run build",
|
||||
"build:modules": "run-p build:modules:*",
|
||||
"watch:modules:ppcp-admin-notices": "cd modules/ppcp-admin-notices && yarn run watch",
|
||||
"watch:modules:ppcp-applepay": "cd modules/ppcp-applepay && yarn run watch",
|
||||
|
@ -68,6 +70,7 @@
|
|||
"watch:modules:ppcp-card-fields": "cd modules/ppcp-card-fields && yarn run watch",
|
||||
"watch:modules:ppcp-compat": "cd modules/ppcp-compat && yarn run watch",
|
||||
"watch:modules:ppcp-uninstall": "cd modules/ppcp-uninstall && yarn run watch",
|
||||
"watch:modules:ppcp-settings": "cd modules/ppcp-settings && yarn run watch",
|
||||
"watch:modules": "run-p watch:modules:*",
|
||||
"ddev:setup": "ddev start && ddev orchestrate",
|
||||
"ddev:start": "ddev start",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue