mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
Add module boilerplate
This commit is contained in:
parent
ac7779bc41
commit
1125ca6ad5
14 changed files with 2565 additions and 0 deletions
|
@ -52,5 +52,13 @@ return function ( string $root_dir ): iterable {
|
||||||
$modules[] = ( require "$modules_dir/ppcp-saved-payment-checker/module.php" )();
|
$modules[] = ( require "$modules_dir/ppcp-saved-payment-checker/module.php" )();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( apply_filters(
|
||||||
|
//phpcs:disable WordPress.NamingConventions.ValidHookName.UseUnderscores
|
||||||
|
'woocommerce.feature-flags.woocommerce_paypal_payments.card_fields_enabled',
|
||||||
|
getenv( 'PCP_CARD_FIELDS_ENABLED' ) === '1'
|
||||||
|
) ) {
|
||||||
|
$modules[] = ( require "$modules_dir/ppcp-card-fields/module.php" )();
|
||||||
|
}
|
||||||
|
|
||||||
return $modules;
|
return $modules;
|
||||||
};
|
};
|
||||||
|
|
14
modules/ppcp-card-fields/.babelrc
Normal file
14
modules/ppcp-card-fields/.babelrc
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"presets": [
|
||||||
|
[
|
||||||
|
"@babel/preset-env",
|
||||||
|
{
|
||||||
|
"useBuiltIns": "usage",
|
||||||
|
"corejs": "3.25.0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"@babel/preset-react"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
3
modules/ppcp-card-fields/.gitignore
vendored
Normal file
3
modules/ppcp-card-fields/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
node_modules
|
||||||
|
assets/js
|
||||||
|
assets/css
|
17
modules/ppcp-card-fields/composer.json
Normal file
17
modules/ppcp-card-fields/composer.json
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"name": "woocommerce/ppcp-card-fields",
|
||||||
|
"type": "dhii-mod",
|
||||||
|
"description": "Advanced Checkout Card Fields module",
|
||||||
|
"license": "GPL-2.0",
|
||||||
|
"require": {
|
||||||
|
"php": "^7.2 | ^8.0",
|
||||||
|
"dhii/module-interface": "^0.3.0-alpha1"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"WooCommerce\\PayPalCommerce\\CardFields\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"minimum-stability": "dev",
|
||||||
|
"prefer-stable": true
|
||||||
|
}
|
12
modules/ppcp-card-fields/extensions.php
Normal file
12
modules/ppcp-card-fields/extensions.php
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* The Card Fields module extensions.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\CardFields
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\CardFields;
|
||||||
|
|
||||||
|
return array();
|
16
modules/ppcp-card-fields/module.php
Normal file
16
modules/ppcp-card-fields/module.php
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* The Card Fields module.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\CardFields
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\CardFields;
|
||||||
|
|
||||||
|
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
|
||||||
|
|
||||||
|
return static function (): ModuleInterface {
|
||||||
|
return new CardFieldsModule();
|
||||||
|
};
|
34
modules/ppcp-card-fields/package.json
Normal file
34
modules/ppcp-card-fields/package.json
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
{
|
||||||
|
"name": "ppcp-card-fields",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "GPL-3.0-or-later",
|
||||||
|
"browserslist": [
|
||||||
|
"> 0.5%",
|
||||||
|
"Safari >= 8",
|
||||||
|
"Chrome >= 41",
|
||||||
|
"Firefox >= 43",
|
||||||
|
"Edge >= 14"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"@paypal/paypal-js": "^6.0.0",
|
||||||
|
"core-js": "^3.25.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/core": "^7.19",
|
||||||
|
"@babel/preset-env": "^7.19",
|
||||||
|
"@babel/preset-react": "^7.18.6",
|
||||||
|
"@woocommerce/dependency-extraction-webpack-plugin": "^2.2.0",
|
||||||
|
"babel-loader": "^8.2",
|
||||||
|
"cross-env": "^7.0.3",
|
||||||
|
"file-loader": "^6.2.0",
|
||||||
|
"sass": "^1.42.1",
|
||||||
|
"sass-loader": "^12.1.0",
|
||||||
|
"webpack": "^5.76",
|
||||||
|
"webpack-cli": "^4.10"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "cross-env BABEL_ENV=default NODE_ENV=production webpack",
|
||||||
|
"watch": "cross-env BABEL_ENV=default NODE_ENV=production webpack --watch",
|
||||||
|
"dev": "cross-env BABEL_ENV=default webpack --watch"
|
||||||
|
}
|
||||||
|
}
|
0
modules/ppcp-card-fields/resources/js/boot.js
Normal file
0
modules/ppcp-card-fields/resources/js/boot.js
Normal file
55
modules/ppcp-card-fields/services.php
Normal file
55
modules/ppcp-card-fields/services.php
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* The Card Fields module services.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\CardFields
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\CardFields;
|
||||||
|
|
||||||
|
use WooCommerce\PayPalCommerce\CardFields\Helper\CardFieldsApplies;
|
||||||
|
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'card-fields.eligible' => static function ( ContainerInterface $container ): bool {
|
||||||
|
$save_payment_methods_applies = $container->get( 'card-fields.helpers.save-payment-methods-applies' );
|
||||||
|
assert( $save_payment_methods_applies instanceof CardFieldsApplies);
|
||||||
|
|
||||||
|
return $save_payment_methods_applies->for_country_currency();
|
||||||
|
},
|
||||||
|
'card-fields.helpers.save-payment-methods-applies' => static function ( ContainerInterface $container ) : CardFieldsApplies {
|
||||||
|
return new CardFieldsApplies(
|
||||||
|
$container->get( 'card-fields.supported-country-currency-matrix' ),
|
||||||
|
$container->get( 'api.shop.currency' ),
|
||||||
|
$container->get( 'api.shop.country' )
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'card-fields.supported-country-currency-matrix' => static function ( ContainerInterface $container ) : array {
|
||||||
|
return apply_filters(
|
||||||
|
'woocommerce_paypal_payments_card_fields_supported_country_currency_matrix',
|
||||||
|
array(
|
||||||
|
'US' => array(
|
||||||
|
'AUD',
|
||||||
|
'CAD',
|
||||||
|
'EUR',
|
||||||
|
'GBP',
|
||||||
|
'JPY',
|
||||||
|
'USD',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'card-fields.module.url' => static function ( ContainerInterface $container ): string {
|
||||||
|
/**
|
||||||
|
* The path cannot be false.
|
||||||
|
*
|
||||||
|
* @psalm-suppress PossiblyFalseArgument
|
||||||
|
*/
|
||||||
|
return plugins_url(
|
||||||
|
'/modules/ppcp-card-fields/',
|
||||||
|
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
45
modules/ppcp-card-fields/src/CardFieldsModule.php
Normal file
45
modules/ppcp-card-fields/src/CardFieldsModule.php
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* The Card Fields module.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\CardFields
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\CardFields;
|
||||||
|
|
||||||
|
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
|
||||||
|
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
|
||||||
|
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
|
||||||
|
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
|
class CardFieldsModule implements ModuleInterface {
|
||||||
|
|
||||||
|
public function setup(): ServiceProviderInterface {
|
||||||
|
return new ServiceProvider(
|
||||||
|
require __DIR__ . '/../services.php',
|
||||||
|
require __DIR__ . '/../extensions.php'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run(ContainerInterface $c): void {
|
||||||
|
if ( ! $c->get( 'card-fields.eligible' ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
add_action(
|
||||||
|
'wp_enqueue_scripts',
|
||||||
|
function () use ($c) {
|
||||||
|
$module_url = $c->get( 'card-fields.module.url' );
|
||||||
|
wp_enqueue_script(
|
||||||
|
'ppcp-card-fields-boot',
|
||||||
|
untrailingslashit( $module_url ) . '/assets/js/boot.js',
|
||||||
|
array( 'jquery' ),
|
||||||
|
$c->get( 'ppcp.asset-version' ),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
66
modules/ppcp-card-fields/src/Helper/CardFieldsApplies.php
Normal file
66
modules/ppcp-card-fields/src/Helper/CardFieldsApplies.php
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Service for checking whether Card Fields can be used in the current country and the current currency.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\CardFields\Helper
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\CardFields\Helper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class CardFieldsApplies
|
||||||
|
*/
|
||||||
|
class CardFieldsApplies {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The matrix which countries and currency combinations can be used.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $allowed_country_currency_matrix;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 3-letter currency code of the shop.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $currency;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2-letter country code of the shop.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $country;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CardFieldsApplies constructor.
|
||||||
|
*
|
||||||
|
* @param array $allowed_country_currency_matrix The matrix which countries and currency combinations can be used.
|
||||||
|
* @param string $currency 3-letter currency code of the shop.
|
||||||
|
* @param string $country 2-letter country code of the shop.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
array $allowed_country_currency_matrix,
|
||||||
|
string $currency,
|
||||||
|
string $country
|
||||||
|
) {
|
||||||
|
$this->allowed_country_currency_matrix = $allowed_country_currency_matrix;
|
||||||
|
$this->currency = $currency;
|
||||||
|
$this->country = $country;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether Card Fields can be used in the current country and the current currency.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function for_country_currency(): bool {
|
||||||
|
if ( ! in_array( $this->country, array_keys( $this->allowed_country_currency_matrix ), true ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return in_array( $this->currency, $this->allowed_country_currency_matrix[ $this->country ], true );
|
||||||
|
}
|
||||||
|
}
|
38
modules/ppcp-card-fields/webpack.config.js
Normal file
38
modules/ppcp-card-fields/webpack.config.js
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
const path = require('path');
|
||||||
|
const isProduction = process.env.NODE_ENV === 'production';
|
||||||
|
|
||||||
|
const DependencyExtractionWebpackPlugin = require( '@woocommerce/dependency-extraction-webpack-plugin' );
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
devtool: isProduction ? 'source-map' : 'eval-source-map',
|
||||||
|
mode: isProduction ? 'production' : 'development',
|
||||||
|
target: 'web',
|
||||||
|
plugins: [ new DependencyExtractionWebpackPlugin() ],
|
||||||
|
entry: {
|
||||||
|
'boot': path.resolve('./resources/js/boot.js'),
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
path: path.resolve(__dirname, 'assets/'),
|
||||||
|
filename: 'js/[name].js',
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
rules: [{
|
||||||
|
test: /\.js?$/,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
loader: 'babel-loader',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.scss$/,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
use: [
|
||||||
|
{
|
||||||
|
loader: 'file-loader',
|
||||||
|
options: {
|
||||||
|
name: 'css/[name].css',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{loader:'sass-loader'}
|
||||||
|
]
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
};
|
2254
modules/ppcp-card-fields/yarn.lock
Normal file
2254
modules/ppcp-card-fields/yarn.lock
Normal file
File diff suppressed because it is too large
Load diff
|
@ -10,6 +10,7 @@
|
||||||
"install:modules:ppcp-applepay": "cd modules/ppcp-applepay && yarn install",
|
"install:modules:ppcp-applepay": "cd modules/ppcp-applepay && yarn install",
|
||||||
"install:modules:ppcp-blocks": "cd modules/ppcp-blocks && yarn install",
|
"install:modules:ppcp-blocks": "cd modules/ppcp-blocks && yarn install",
|
||||||
"install:modules:ppcp-button": "cd modules/ppcp-button && yarn install",
|
"install:modules:ppcp-button": "cd modules/ppcp-button && yarn install",
|
||||||
|
"install:modules:ppcp-card-fields": "cd modules/ppcp-card-fields && yarn install",
|
||||||
"install:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn install",
|
"install:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn install",
|
||||||
"install:modules:ppcp-wc-gateway": "cd modules/ppcp-wc-gateway && yarn install",
|
"install:modules:ppcp-wc-gateway": "cd modules/ppcp-wc-gateway && yarn install",
|
||||||
"install:modules:ppcp-webhooks": "cd modules/ppcp-webhooks && yarn install",
|
"install:modules:ppcp-webhooks": "cd modules/ppcp-webhooks && yarn install",
|
||||||
|
@ -21,6 +22,7 @@
|
||||||
"build:modules:ppcp-applepay": "cd modules/ppcp-applepay && yarn run build",
|
"build:modules:ppcp-applepay": "cd modules/ppcp-applepay && yarn run build",
|
||||||
"build:modules:ppcp-blocks": "cd modules/ppcp-blocks && yarn run build",
|
"build:modules:ppcp-blocks": "cd modules/ppcp-blocks && yarn run build",
|
||||||
"build:modules:ppcp-button": "cd modules/ppcp-button && yarn run build",
|
"build:modules:ppcp-button": "cd modules/ppcp-button && yarn run build",
|
||||||
|
"build:modules:ppcp-card-fields": "cd modules/ppcp-card-fields && yarn run build",
|
||||||
"build:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn run build",
|
"build:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn run build",
|
||||||
"build:modules:ppcp-wc-gateway": "cd modules/ppcp-wc-gateway && yarn run build",
|
"build:modules:ppcp-wc-gateway": "cd modules/ppcp-wc-gateway && yarn run build",
|
||||||
"build:modules:ppcp-webhooks": "cd modules/ppcp-webhooks && yarn run build",
|
"build:modules:ppcp-webhooks": "cd modules/ppcp-webhooks && yarn run build",
|
||||||
|
@ -33,6 +35,7 @@
|
||||||
"watch:modules:ppcp-applepay": "cd modules/ppcp-applepay && yarn run watch",
|
"watch:modules:ppcp-applepay": "cd modules/ppcp-applepay && yarn run watch",
|
||||||
"watch:modules:ppcp-blocks": "cd modules/ppcp-blocks && yarn run watch",
|
"watch:modules:ppcp-blocks": "cd modules/ppcp-blocks && yarn run watch",
|
||||||
"watch:modules:ppcp-button": "cd modules/ppcp-button && yarn run watch",
|
"watch:modules:ppcp-button": "cd modules/ppcp-button && yarn run watch",
|
||||||
|
"watch:modules:ppcp-card-fields": "cd modules/ppcp-card-fields && yarn run watch",
|
||||||
"watch:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn run watch",
|
"watch:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn run watch",
|
||||||
"watch:modules:ppcp-wc-gateway": "cd modules/ppcp-wc-gateway && yarn run watch",
|
"watch:modules:ppcp-wc-gateway": "cd modules/ppcp-wc-gateway && yarn run watch",
|
||||||
"watch:modules:ppcp-webhooks": "cd modules/ppcp-webhooks && yarn run watch",
|
"watch:modules:ppcp-webhooks": "cd modules/ppcp-webhooks && yarn run watch",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue