diff --git a/.babelrc b/.babelrc deleted file mode 100644 index 5634ac07c..000000000 --- a/.babelrc +++ /dev/null @@ -1,28 +0,0 @@ -{ - "presets": [ - [ - "@babel/preset-env", - { - "useBuiltIns": "entry", - "targets": { - "browsers": [ - "last 2 versions", - "ie 10" - ] - } - } - ], - [ - "@babel/preset-react", - { - "useBuiltIns": "entry", - "targets": { - "browsers": [ - "last 2 versions", - "ie 10" - ] - } - } - ] - ] -} diff --git a/.ddev/config.yaml b/.ddev/config.yaml index 333c2e392..979996e9e 100644 --- a/.ddev/config.yaml +++ b/.ddev/config.yaml @@ -28,7 +28,7 @@ web_environment: - ADMIN_EMAIL=admin@example.com - WC_VERSION=dev - WP_ENVIRONMENT_TYPE=local -nodejs_version: "22" +nodejs_version: "23" # Key features of ddev's config.yaml: diff --git a/.distignore b/.distignore index 2f0170b94..941068c86 100644 --- a/.distignore +++ b/.distignore @@ -17,7 +17,6 @@ patchwork.json *.sh *.config.* *.md -gulpfile.js webpack.config.js readme.md changelog.txt diff --git a/.idea/WooCommerce.iml b/.idea/WooCommerce.iml index e7b783819..692525fb1 100644 --- a/.idea/WooCommerce.iml +++ b/.idea/WooCommerce.iml @@ -4,12 +4,6 @@ - - - - - - diff --git a/.idea/php.xml b/.idea/php.xml index 539444f7e..d08da0064 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -245,7 +245,7 @@ - + diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index 174c4878d..000000000 --- a/gulpfile.js +++ /dev/null @@ -1,352 +0,0 @@ -const gulp = require('gulp') -const { series, parallel, src, dest } = gulp -const del = require('del') -const pump = require('pump') -const minimist = require('minimist') -const { spawn } = require('child_process') -const usage = require('gulp-help-doc') -const zip = require('gulp-zip') -const rename = require('gulp-rename') -const date = require('date-and-time') -const wpPot = require('wp-pot') - -const options = { - ...minimist( - process.argv, - { - string: [ - 'packageVersion', - 'packageName', - 'baseDir', - 'buildDir', - 'distDir', - 'depsVersionPhp' - ], - bools: [ - 'q', - ], - default: { - packageVersion: 'dev', - packageName: 'mollie-payments-for-woocommerce', - baseDir: __dirname, - buildDir: `${__dirname}/build`, - distDir: `${__dirname}/dist`, - q: false, - depsVersionPhp: '7.2.9', - }, - } - ) -} - - -// -------------------------------------------------------------------- -// CONSTANTS -// -------------------------------------------------------------------- - - -// -------------------------------------------------------------------- -// FUNCTIONS -// -------------------------------------------------------------------- -let log = (function (options) { - - /** - * Logs text. - * - * @param text The text to lot. - */ - let out = function (text) { - if (!options.q) { - console.log(text); - } - }; - - let err = function (text) { - console.error(text); - } - - /** - * @alias out() - */ - let log = function (text) { - return out(text); - }; - - log.out = out; - log.err = err; - - return log; -})(options); - -let exec = (function (options) { - /** - * @param {string} cmd The command to run. - * @param {Array} args A list of arguments to run the command with - * @param {Object} settings Any settings for the child process. - * @param {Function[]} tasks The tasks to chain. - */ - return function (cmd, args, settings, cb) { - args = args || [] - settings = settings || {} - cb = cb || function () {} - - let fullCmd = cmd + (args ? ' ' + args.join(' ') : ''); - log(`exec: ${fullCmd}`); - let stdout = '' - let stderr = '' - let error = null; - let ps = spawn(cmd, args, settings); - - if (!options.q) { - ps.stdout.pipe(process.stdout) - } - - ps.stderr.on('data', (data) => { - stderr += data.toString() - }) - - ps.stdout.on('data', (data) => { - stdout += data.toString() - }) - - ps.on('error', (err) => { - err = err.toString() - error = new Error(err); - cb(error, stdout, stderr); - }); - - ps.on('exit', (code) => { - if (code) { - error = new Error(`Subprocess exited with code ${code}\n${stderr}`); - } - - cb(error, stdout, stderr); - }); - - return ps - } -})(options) - -/** - * @param {Function[]} tasks The tasks to chain. - * @param {Function} callback The callback that should run at the end of the chain. - */ -let chain = function (tasks, callback) { - let task = tasks.shift() - - return task((error) => { - if (error || !tasks.length) { - return callback(error) - } - - return chain(tasks, callback) - }) -} - -// -------------------------------------------------------------------- -// TASKS -// -------------------------------------------------------------------- - -function _help() { - return function help(done) { - return usage(gulp) - } -} - -function _clean({baseDir, buildDir}) { - return function clean(done) { - del.sync([buildDir], {force: true, cwd: baseDir}) - done() - } -} - -function _copy({baseDir, buildDir, distDir}) { - return function copy(done) { - pump( - src([`**/*.*`, `!${buildDir}/**/*.*`, `!${distDir}/**/*.*`, '!.git/**/*.*', '!vendor/**/*.*', '!node_modules/**/*.*', '!.ddev/**/*.*', '!.github/**/*.*', '!.psalm/**/*.*'], {base: baseDir, cwd: baseDir, dot: true}), - dest(buildDir), - done - ) - } -} - -function _installPhp({buildDir, depsVersionPhp}) { - return function installPhp(done) { - chain([ - (done) => { return exec('composer', ['config', 'platform.php', depsVersionPhp], {cwd: buildDir}, done)}, - (done) => { return exec(`composer`, ['install', '--prefer-dist', '--optimize-autoloader', '--no-dev'], {cwd: buildDir}, done) }, - ], done); - } -} - -function _installJs({buildDir}) { - return function installJs(done) { - chain([ - (done) => { return exec('npm', ['install', '--production'], {cwd: buildDir}, done) }, - ], done); - } -} - -function _processAssets({baseDir, buildDir}) { - return function processAssets(done) { - exec( - `node_modules/.bin/encore`, - ['production', `--env.basePath="${buildDir}"`], - {cwd: baseDir}, - done, - ) - } -} - -function _archive({baseDir, buildDir, distDir, packageVersion, packageName}) { - return function archive(done) { - return new Promise(() => - { - exec( - `git log -n 1 | head -n 1 | sed -e 's/^commit //' | head -c 8`, - [], - {'shell': true}, - (error, stdout) => - { - if (error) { - done(new Error(error)); - } - - let commit = stdout; - let timestamp = date.format(new Date(), 'YYYY-MM-DD.HH-mm-ss', true) - - pump( - gulp.src([ - 'inc/**/*.*', - 'languages/**/*.mo', - 'languages/**/*.pot', - 'pluginEnvironmentChecker/**/*.*', - 'public/**/*.*', - 'src/**/*.*', - 'vendor/**/*.*', - 'node_modules/**/*.*', - '!node_modules/.package.lock.json', - 'license.txt', - 'mollie-payments-for-woocommerce.php', - 'uninstall.php', - - // Cleanup - '!**/README', - '!**/readme', - '!**/README.md', - '!**/readme.md', - '!**/readme.txt', - '!**/readme.txt', - '!**/CONTRIBUTING', - '!**/contributing', - '!**/CONTRIBUTING.md', - '!**/contributing.md', - '!**/CONTRIBUTING.txt', - '!**/contributing.txt', - '!**/composer.json', - '!**/composer.lock', - '!**/package.json', - '!**/package-lock.json', - '!**/yarn.lock', - '!**/phpunit.xml.dist', - '!**/webpack.config.js', - '!**/.github', - '!**/.git', - '!**/.ddev', - '!**/.gitignore', - '!**/.gitattributes', - '!**/Makefile', - '!**/bitbucket-pipelines.yml', - '!**/bin.yml', - '!**/test.yml', - '!**/tests.yml', - ], { - base: buildDir, - cwd: buildDir, - dot: true, - }), - rename((path) => { path.dirname = `${packageName}/` + path.dirname }), - zip(`${packageName}_${packageVersion}+${commit}.${timestamp}.zip`), - gulp.dest(distDir), - done, - ) - } - ) - }) - } -} - -function _generatePotFile ({buildDir, langDir}) { - return async function generatePotFile (done) { - wpPot({ - destFile: `languages/mollie-payments-for-woocommerce.pot`, - includePOTCreationDate: false, - src: [ - `mollie-payments-for-woocommerce.php`, - `src/**/*.php`, - `inc/**/*.php`, - ] - }); - - done() - } -} - -// -------------------------------------------------------------------- -// TARGETS -// -------------------------------------------------------------------- -exports.help = series( - _help(options), -) - -exports.clean = series( - _clean(options), -) - -exports.copy = series( - _copy(options) -) - -exports.installPhp = series( - _installPhp(options) -) - -exports.installJs = series( - _installJs(options) -) - -exports.processAssets = series( - _processAssets(options) -) - -exports.archive = series( - _archive(options) -) - -exports.install = parallel( - exports.installJs, - exports.installPhp -) - -exports.process = series( - exports.processAssets, -) - -exports.build = series( - exports.clean, - exports.copy, - exports.install, - exports.process, -) - -exports.dist = series( - exports.build, - exports.archive, -) - -exports.default = series( - exports.build -) - -exports.generatePotFile = series( - _generatePotFile(options) -) diff --git a/inc/modules.php b/inc/modules.php index 0924257c0..268dc2f12 100644 --- a/inc/modules.php +++ b/inc/modules.php @@ -6,6 +6,7 @@ use Inpsyde\PaymentGateway\PaymentGatewayModule; use Mollie\WooCommerce\Activation\ActivationModule; use Mollie\WooCommerce\Assets\AssetsModule; +use Mollie\WooCommerce\Components\ComponentsModule; use Mollie\WooCommerce\Gateway\GatewayModule; use Mollie\WooCommerce\Gateway\Voucher\VoucherModule; use Mollie\WooCommerce\Log\LogModule; @@ -36,6 +37,7 @@ static function (): iterable { new PaymentModule(), new SubscriptionModule(), new MerchantCaptureModule(), + new ComponentsModule(), new UninstallModule(), ]; }; diff --git a/lib/payment-gateway/.distignore b/lib/payment-gateway/.distignore new file mode 100644 index 000000000..185a70f64 --- /dev/null +++ b/lib/payment-gateway/.distignore @@ -0,0 +1,8 @@ +.distignore +.ddev +.git* +tests/ +vendor/**/test* +*.lock +package-lock.json +*.xml.* diff --git a/lib/payment-gateway/.gitignore b/lib/payment-gateway/.gitignore new file mode 100644 index 000000000..c2658d7d1 --- /dev/null +++ b/lib/payment-gateway/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/lib/payment-gateway/.nvmrc b/lib/payment-gateway/.nvmrc new file mode 100644 index 000000000..9a2a0e219 --- /dev/null +++ b/lib/payment-gateway/.nvmrc @@ -0,0 +1 @@ +v20 diff --git a/lib/payment-gateway/CHANGELOG.md b/lib/payment-gateway/CHANGELOG.md new file mode 100644 index 000000000..20e71ce08 --- /dev/null +++ b/lib/payment-gateway/CHANGELOG.md @@ -0,0 +1,237 @@ +# [2.8.0](https://github.com/inpsyde/payment-gateway/compare/2.7.1...2.8.0) (2025-07-02) + + +### Bug Fixes + +* 🚀 Update payment gateway active check to use direct property access ([94268ce](https://github.com/inpsyde/payment-gateway/commit/94268cee859aa859bfc0be0bf4e6f43ff41f6f02)) +* Update `orderButtonText` to return empty string instead of null. ([bf9648c](https://github.com/inpsyde/payment-gateway/commit/bf9648c64b205cdd23ea090a1f03ea9f667b12b2)) + + +### Features + +* 🚀 Add method to check if payment method is enabled ([fc98a88](https://github.com/inpsyde/payment-gateway/commit/fc98a881a3b34fa9efa62ed885e41ebf1cfe35e4)) + +## [2.7.1](https://github.com/inpsyde/payment-gateway/compare/2.7.0...2.7.1) (2025-06-20) + + +### Bug Fixes + +* 🔧 Change WooCommerce hook from `woocommerce_blocks_loaded` to `woocommerce_init` ([#50](https://github.com/inpsyde/payment-gateway/issues/50)) ([b9919e8](https://github.com/inpsyde/payment-gateway/commit/b9919e8f98dcf8cee99b2dfe0cdbdc89f47c641b)) + +# [2.7.0](https://github.com/inpsyde/payment-gateway/compare/2.6.0...2.7.0) (2025-04-02) + + +### Bug Fixes + +* Add id in ContentField ([a3747d9](https://github.com/inpsyde/payment-gateway/commit/a3747d90f9b804598158289434f41a2f8b32ef1b)) + + +### Features + +* Add render_directly option in ContentField ([6becaaf](https://github.com/inpsyde/payment-gateway/commit/6becaaf304cbe676f648f40b769ceccdfb8b36a6)) + +# [2.6.0](https://github.com/inpsyde/payment-gateway/compare/2.5.0...2.6.0) (2025-03-14) + + +### Features + +* Allow to override savedTokenComponent in blocks ([#48](https://github.com/inpsyde/payment-gateway/issues/48)) ([11d99eb](https://github.com/inpsyde/payment-gateway/commit/11d99ebf4fff9272884c87bac89055148d3b09a8)) + +# [2.5.0](https://github.com/inpsyde/payment-gateway/compare/2.4.1...2.5.0) (2025-03-14) + + +### Bug Fixes + +* 📝 Remove redundant `get_form_fields` method and streamline form fields handling ([#47](https://github.com/inpsyde/payment-gateway/issues/47)) ([0b17b89](https://github.com/inpsyde/payment-gateway/commit/0b17b89e26460ba0e02e10fe559e61823f1e5051)), closes [#123](https://github.com/inpsyde/payment-gateway/issues/123) + + +### Features + +* Add support for plugin_slug property ([#45](https://github.com/inpsyde/payment-gateway/issues/45)) ([d7fd64c](https://github.com/inpsyde/payment-gateway/commit/d7fd64c96b649d14796368b76ca86fb4b7ece525)) + +## [2.4.1](https://github.com/inpsyde/payment-gateway/compare/2.4.0...2.4.1) (2025-02-26) + + +### Bug Fixes + +* ✨ Fix disabled payment methods appearing in block editor ([#44](https://github.com/inpsyde/payment-gateway/issues/44)) ([d225863](https://github.com/inpsyde/payment-gateway/commit/d225863654c6efbd1e1dad95fe0c877f9191bf8d)) +* 🛠️ Normalize file paths before comparison in `getPluginFileUrlFromAbsolutePath` ([#43](https://github.com/inpsyde/payment-gateway/issues/43)) ([3de5321](https://github.com/inpsyde/payment-gateway/commit/3de5321fb6dac121ec20940758e7d4edb4e64e6f)) + +# [2.4.0](https://github.com/inpsyde/payment-gateway/compare/2.3.1...2.4.0) (2025-02-13) + + +### Features + +* Add a filter for Label icons ([8030e3f](https://github.com/inpsyde/payment-gateway/commit/8030e3f1977fc552d77dfe3cab5f8e871ccb7bf9)) + +## [2.3.1](https://github.com/inpsyde/payment-gateway/compare/2.3.0...2.3.1) (2025-02-05) + + +### Bug Fixes + +* Make icon service optional, provide default icon value as fallback ([#41](https://github.com/inpsyde/payment-gateway/issues/41)) ([9d1a9b7](https://github.com/inpsyde/payment-gateway/commit/9d1a9b70e495250e19445e10be732f4d699fa945)) + +# [2.3.0](https://github.com/inpsyde/payment-gateway/compare/2.2.2...2.3.0) (2025-01-31) + + +### Features + +* Add service definition for icon property ([#40](https://github.com/inpsyde/payment-gateway/issues/40)) ([ef92746](https://github.com/inpsyde/payment-gateway/commit/ef927461518f027836c3f9a9230dd126b88c3ddb)) + +## [2.2.2](https://github.com/inpsyde/payment-gateway/compare/2.2.1...2.2.2) (2025-01-22) + + +### Bug Fixes + +* Avoid excessive re-rendering by leveraging useEffect ([0500255](https://github.com/inpsyde/payment-gateway/commit/050025532c80da0c4bab13fb6d71913cc68f27fc)) + +## [2.2.1](https://github.com/inpsyde/payment-gateway/compare/2.2.0...2.2.1) (2024-12-20) + + +### Bug Fixes + +* Use different base for fallback keys ([b0857e0](https://github.com/inpsyde/payment-gateway/commit/b0857e096147219d49255706b76f3efc39014be7)) + +# [2.2.0](https://github.com/inpsyde/payment-gateway/compare/2.1.1...2.2.0) (2024-12-19) + + +### Features + +* Introduce IconProviderInterface and icon rendering ([#39](https://github.com/inpsyde/payment-gateway/issues/39)) ([a3f8085](https://github.com/inpsyde/payment-gateway/commit/a3f8085935a3be15d17567db8db8aa6de2e4db81)) + +## [2.1.1](https://github.com/inpsyde/payment-gateway/compare/2.1.0...2.1.1) (2024-12-13) + + +### Bug Fixes + +* Pass props when creating components instead of filter ([#38](https://github.com/inpsyde/payment-gateway/issues/38)) ([2aa1ab1](https://github.com/inpsyde/payment-gateway/commit/2aa1ab1f685d18a9ff86c57b456a7f6a410115d0)) + +# [2.1.0](https://github.com/inpsyde/payment-gateway/compare/2.0.0...2.1.0) (2024-12-11) + + +### Features + +* Pass WooCommerce props to filter. Fix block registration ([9584b97](https://github.com/inpsyde/payment-gateway/commit/9584b97445455593bfaca092ff84469eeac2d6d8)) + +# [2.0.0](https://github.com/inpsyde/payment-gateway/compare/1.6.0...2.0.0) (2024-12-10) + + +### Features + +* Introduce high-level API ([#36](https://github.com/inpsyde/payment-gateway/issues/36)) ([a84a200](https://github.com/inpsyde/payment-gateway/commit/a84a20094fdd2670c04c8f1a4005fa1a3452c698)) + + +### BREAKING CHANGES + +* Default/Fallback behaviour is moved into `DefaultPaymentMethodDefinitionTrait`, so existing integrations may see differences in behaviour when upgrading. + +* Refactor README to clarify design considerations and architecture for WooCommerce payment gateways. + +* Improve README with emojis for better visual appeal. + +Adds a unit test +Moves some of the defaults/fallbacks from PaymentGateway into DefaultPaymentMethodDefinitionTrait + +* Refactor and clean up code in PaymentMethodDefinition, NoopGatewayIconsRenderer, and PaymentGateway classes. + +* Introduce high-level API for settings customization + +* Update README.md + +# [1.6.0](https://github.com/inpsyde/payment-gateway/compare/1.5.2...1.6.0) (2024-11-19) + + +### Features + +* Filterable checkout components ([#34](https://github.com/inpsyde/payment-gateway/issues/34)) ([76f8c16](https://github.com/inpsyde/payment-gateway/commit/76f8c1626f3360b9763c6210393a6f7a40a0ccd7)), closes [#35](https://github.com/inpsyde/payment-gateway/issues/35) + +## [1.5.2](https://github.com/inpsyde/payment-gateway/compare/1.5.1...1.5.2) (2024-11-13) + + +### Bug Fixes + +* allow node 22 ([1a28fdd](https://github.com/inpsyde/payment-gateway/commit/1a28fdd38be46459d1c63cd99192d9f2bc22e25d)) +* allow node 22 ([93a85e6](https://github.com/inpsyde/payment-gateway/commit/93a85e69eb329620dc636180298253ac18742a66)) + +## [1.5.1](https://github.com/inpsyde/payment-gateway/compare/1.5.0...1.5.1) (2024-09-23) + + +### Bug Fixes + +* Fix PaymentGatewayBlocks::$gateway type. ([#31](https://github.com/inpsyde/payment-gateway/issues/31)) ([58cd64c](https://github.com/inpsyde/payment-gateway/commit/58cd64cb64bc11fcd1a89d9aa0690d90738162a4)) + +# [1.5.0](https://github.com/inpsyde/payment-gateway/compare/1.4.1...1.5.0) (2024-09-20) + + +### Bug Fixes + +* code style, remove PaymentGatewayBlocks::$name type ([32ed490](https://github.com/inpsyde/payment-gateway/commit/32ed490e73414383c6f6eb34529a483468afb56c)) + + +### Features + +* Allow to interrupt refund with a message ([e5c6e10](https://github.com/inpsyde/payment-gateway/commit/e5c6e10d06b228483b8725cfbd41686fb0c5b776)) + +## [1.4.1](https://github.com/inpsyde/payment-gateway/compare/1.4.0...1.4.1) (2024-09-18) + + +### Bug Fixes + +* use variable in process_refund() ([afabd5c](https://github.com/inpsyde/payment-gateway/commit/afabd5cc6e08a830238af5067500df3fb462644f)) + +# [1.4.0](https://github.com/inpsyde/payment-gateway/compare/1.3.2...1.4.0) (2024-09-13) + + +### Features + +* [PROD-169] Implement l10n for errors & order notes ([#26](https://github.com/inpsyde/payment-gateway/issues/26)) ([7806c79](https://github.com/inpsyde/payment-gateway/commit/7806c798bc1a6e450f91d703fc94f7c07e8aea96)), closes [#1](https://github.com/inpsyde/payment-gateway/issues/1) [#2](https://github.com/inpsyde/payment-gateway/issues/2) + +## [1.3.2](https://github.com/inpsyde/payment-gateway/compare/1.3.1...1.3.2) (2024-07-12) + + +### Bug Fixes + +* Keep frontend source and composer.json in releases ([ee1f8a3](https://github.com/inpsyde/payment-gateway/commit/ee1f8a3642d9240927b8df39b70e8022b000ad4f)) + +## [1.3.1](https://github.com/inpsyde/payment-gateway/compare/1.3.0...1.3.1) (2024-07-01) + + +### Bug Fixes + +* Do not use PHP_INT_MIN for hooks ([8e5e15d](https://github.com/inpsyde/payment-gateway/commit/8e5e15d4f09364333b5937a2d09b44210fe0c2f4)) +* Move comment outside of expression ([c80b6cd](https://github.com/inpsyde/payment-gateway/commit/c80b6cde33661b53fe0ac73824f5eaae3fda9db7)) + +# [1.3.0](https://github.com/inpsyde/payment-gateway/compare/1.2.0...1.3.0) (2024-06-05) + + +### Features + +* Add locators for method title & description ([#24](https://github.com/inpsyde/payment-gateway/issues/24)) ([27a73a9](https://github.com/inpsyde/payment-gateway/commit/27a73a90965af918da92185526315a97ab8b8c48)) + +# [1.2.0](https://github.com/inpsyde/payment-gateway/compare/1.1.1...1.2.0) (2024-06-05) + + +### Features + +* Check required services during init ([79ae2b9](https://github.com/inpsyde/payment-gateway/commit/79ae2b9bb178376419c91b418bdfa2b593b99346)), closes [#15](https://github.com/inpsyde/payment-gateway/issues/15) + +## [1.1.1](https://github.com/inpsyde/payment-gateway/compare/1.1.0...1.1.1) (2024-06-04) + + +### Bug Fixes + +* don't register gateway for blocks if disabled ([e577b52](https://github.com/inpsyde/payment-gateway/commit/e577b522ef0452104a2e54c499f39e9953876a38)) + +# [1.1.0](https://github.com/inpsyde/payment-gateway/compare/1.0.1...1.1.0) (2024-06-04) + + +### Features + +* Add a new service to allow skipping blocks registration ([#21](https://github.com/inpsyde/payment-gateway/issues/21)) ([e1978d1](https://github.com/inpsyde/payment-gateway/commit/e1978d19654a2c685265a9d32fa12ff49c7b6249)) + +# 1.0.0 (2024-05-21) + + +### Bug Fixes + +* specify playwright dependency ([1060e5c](https://github.com/inpsyde/payment-gateway/commit/1060e5cafece37c465e6e78077d2c7378f723b46)) diff --git a/lib/payment-gateway/assets/js/backend.asset.php b/lib/payment-gateway/assets/js/backend.asset.php new file mode 100644 index 000000000..c21294c34 --- /dev/null +++ b/lib/payment-gateway/assets/js/backend.asset.php @@ -0,0 +1 @@ + array(), 'version' => '357a676e1704cd630c8f'); diff --git a/lib/payment-gateway/assets/js/backend.js b/lib/payment-gateway/assets/js/backend.js new file mode 100644 index 000000000..76e5813ef --- /dev/null +++ b/lib/payment-gateway/assets/js/backend.js @@ -0,0 +1 @@ +alert("hi!"); \ No newline at end of file diff --git a/lib/payment-gateway/assets/js/frontend/blocks.asset.php b/lib/payment-gateway/assets/js/frontend/blocks.asset.php new file mode 100644 index 000000000..81b2ed46f --- /dev/null +++ b/lib/payment-gateway/assets/js/frontend/blocks.asset.php @@ -0,0 +1 @@ + array('react', 'wc-blocks-registry', 'wc-settings', 'wp-data', 'wp-hooks', 'wp-html-entities', 'wp-i18n'), 'version' => '0979f440305a0a9ee153'); diff --git a/lib/payment-gateway/assets/js/frontend/blocks.js b/lib/payment-gateway/assets/js/frontend/blocks.js new file mode 100644 index 000000000..eaec67246 --- /dev/null +++ b/lib/payment-gateway/assets/js/frontend/blocks.js @@ -0,0 +1 @@ +(()=>{"use strict";const e=window.React,t=window.wp.i18n,n=window.wc.wcBlocksRegistry,a=window.wp.htmlEntities,l=window.wc.wcSettings,s=window.wp.hooks;window.wp.data,inpsydeGateways&&inpsydeGateways.forEach(o=>{const r=(0,l.getSetting)(`${o}_data`,{}),c=`${o}_checkout_fields`,i=`${o}_saved_token_fields`,d=`${o}_payment_method_icons`,m=(0,t.__)("Syde Payment Gateway","syde-payment-gateway"),u=(0,a.decodeEntities)(r.title)||m,p=t=>{const[n,l]=(0,e.useState)([]);if((0,e.useEffect)(()=>{l(s.defaultHooks.applyFilters(c,[]))},[]),!Array.isArray(n)||!n.length){const t=()=>(0,a.decodeEntities)(r.description||"");return(0,e.createElement)(t,null)}return(0,e.createElement)(e.Fragment,null,n.map(n=>(0,e.createElement)(n,{...t})))},w={name:o,label:(0,e.createElement)(t=>{const{PaymentMethodLabel:n,PaymentMethodIcons:a}=t.components;return(0,e.createElement)(e.Fragment,null,(0,e.createElement)(n,{text:u}),(0,e.createElement)(a,{icons:s.defaultHooks.applyFilters(d,r.icons)}))},null),content:(0,e.createElement)(p,null),edit:(0,e.createElement)(p,null),savedTokenComponent:(0,e.createElement)(t=>{const[n,a]=(0,e.useState)([]);return(0,e.useEffect)(()=>{a(s.defaultHooks.applyFilters(i,[]))},[]),Array.isArray(n)&&n.length?(0,e.createElement)(e.Fragment,null,n.map(n=>(0,e.createElement)(n,{...t}))):null},null),icons:r.icons,canMakePayment:()=>!0,ariaLabel:u,supports:{features:r.supports}};r.placeOrderButtonLabel&&(w.placeOrderButtonLabel=r.placeOrderButtonLabel),s.defaultHooks.applyFilters(`${o}_should_register_payment_method`,!0,w,r)&&(0,n.registerPaymentMethod)(w)})})(); \ No newline at end of file diff --git a/lib/payment-gateway/composer.json b/lib/payment-gateway/composer.json new file mode 100644 index 000000000..daf0844c0 --- /dev/null +++ b/lib/payment-gateway/composer.json @@ -0,0 +1,112 @@ +{ + "name": "inpsyde/payment-gateway", + "type": "inpsyde-module", + "description": "", + "license": "GPL-2.0", + "authors": [ + { + "name": "Inpsyde GmbH", + "homepage": "https://inpsyde.com/", + "email": "hello@inpsyde.com", + "role": "Company" + } + ], + "repositories": [ + { + "type": "composer", + "url": "https://repo.packagist.com/inpsyde/" + } + ], + "require": { + "php": "^7.4 | ^8.0", + "inpsyde/modularity": "@stable" + }, + "require-dev": { + "brain/monkey": "^2.0", + "brainmaestro/composer-git-hooks": "^2.8", + "inpsyde/composer-assets-compiler": "^2.5", + "inpsyde/ddev-tools": "dev-main", + "inpsyde/php-coding-standards": "^2.0", + "inpsyde/wp-translation-downloader": "^2.4", + "mockery/mockery": "^1.3", + "phpunit/phpunit": "^8.0 | ^9.0", + "php-stubs/wordpress-stubs": "^5.0@stable", + "php-stubs/woocommerce-stubs": "^5.0@stable", + "vimeo/psalm": "^4.3" + }, + "autoload": { + "psr-4": { + "Inpsyde\\PaymentGateway\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Inpsyde\\PaymentGateway\\Test\\": "tests/PHPUnit/Helper" + } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "scripts": { + "phpcs": "@php ./vendor/bin/phpcs -n -s --parallel=24", + "phpcs:phpcbf": "@php ./vendor/bin/phpcbf --parallel=24;exit 0", + "phpcs:interactive": "@php ./vendor/bin/phpcs -a", + "phpcs:dev": [ + "@cs:phpcbf", + "@cs:interactive" + ], + "phpunit": "vendor/bin/phpunit", + "test": [ + "@phpunit" + ], + "cghooks": "vendor/bin/cghooks", + "post-install-cmd": [ + "@cghooks add --ignore-lock" + ], + "post-update-cmd": [ + "@cghooks update" + ] + }, + "config": { + "sort-packages": true, + "optimize-autoloader": true, + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true, + "inpsyde/composer-assets-compiler": true, + "composer/installers": true, + "inpsyde/wp-translation-downloader": true + } + }, + "extra": { + "hooks": { + "pre-commit": [ + "vendor/bin/phpcbf -q --parallel=24; exit 0" + ] + }, + "wp-translation-downloader": { + "auto-run": false, + "languageRootDir": "./", + "languages": [ + "de_DE", + "en_US" + ], + "api": { + "names": { + "inpsyde/*": "https://translate.inpsyde.com/products/api/translations/%projectName%" + } + }, + "directories": { + "names": { + "inpsyde/*": "languages/" + } + } + }, + "composer-asset-compiler": { + "auto-run": false, + "dependencies": "install", + "script": "build", + "default-env": { + "WEBPACK_ENV": "production" + } + } + } +} diff --git a/lib/payment-gateway/package.json b/lib/payment-gateway/package.json new file mode 100644 index 000000000..2e4a51c50 --- /dev/null +++ b/lib/payment-gateway/package.json @@ -0,0 +1,37 @@ +{ + "name": "@inpsyde/generic-payment-gateway", + "version": "0.1.0", + "engines": { + "node": "^16 || ^18 || ^20 || ^22" + }, + "devDependencies": { + "@semantic-release/changelog": "^6.0.3", + "@semantic-release/commit-analyzer": "^12.0.0", + "@semantic-release/exec": "^6.0.3", + "@semantic-release/git": "^10.0.1", + "@semantic-release/github": "^10.0.3", + "@semantic-release/npm": "^12.0.0", + "@semantic-release/release-notes-generator": "^13.0.0", + "@woocommerce/dependency-extraction-webpack-plugin": "3.0.0", + "@woocommerce/settings": "^1.0.0", + "@wordpress/hooks": "^4.11.0", + "@wordpress/html-entities": "^3.39.0", + "@wordpress/i18n": "^4.39.0", + "@wordpress/scripts": "^26.10.0", + "semantic-release": "^23.0.8", + "ts-loader": "^9.0.0", + "typescript": "^5.1.6" + }, + "scripts": { + "build": "wp-scripts build", + "build:dev": "wp-scripts build --mode development", + "dev": "wp-scripts build --mode development --watch", + "start": "wp-scripts start", + "lint:md": "wp-scripts lint-md-docs docs/**/*.md", + "lint:js": "wp-scripts lint-js resources/js/**/*", + "lint:style": "wp-scripts lint-style resources/scss/**/*.scss" + }, + "dependencies": { + "react": "^18.3.1" + } +} diff --git a/lib/payment-gateway/psalm.xml.dist b/lib/payment-gateway/psalm.xml.dist new file mode 100644 index 000000000..8cf3d7066 --- /dev/null +++ b/lib/payment-gateway/psalm.xml.dist @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/payment-gateway/release.config.js b/lib/payment-gateway/release.config.js new file mode 100644 index 000000000..0ca2a55e9 --- /dev/null +++ b/lib/payment-gateway/release.config.js @@ -0,0 +1,15 @@ +module.exports = { + "branches": ["main"], + "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + "@semantic-release/changelog", + "@semantic-release/github", + ["@semantic-release/git", { + "assets": ["CHANGELOG.md"], + "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" + }] + ], + "preset": "angular", + "tagFormat": "${version}" +} \ No newline at end of file diff --git a/lib/payment-gateway/resources/js/blocks/index.js b/lib/payment-gateway/resources/js/blocks/index.js index 0b58ddb89..4e516a0f3 100644 --- a/lib/payment-gateway/resources/js/blocks/index.js +++ b/lib/payment-gateway/resources/js/blocks/index.js @@ -2,12 +2,14 @@ import {__} from '@wordpress/i18n'; import {registerPaymentMethod} from '@woocommerce/blocks-registry'; import {decodeEntities} from '@wordpress/html-entities'; import {getSetting} from '@woocommerce/settings'; -import {defaultHooks} from '@wordpress/hooks'; +import {addFilter, defaultHooks} from '@wordpress/hooks'; import { useEffect, useState } from 'react'; +import {ApplePayUtils} from "../../../../../resources/js/src/shared/utils/applePayUtils"; -inpsydeGateways.forEach((name) => { +inpsydeGateways && inpsydeGateways.forEach((name) => { const settings = getSetting(`${name}_data`, {}); const checkoutFieldsHookName = `${name}_checkout_fields`; + const savedTokenFieldsHookName = `${name}_saved_token_fields`; const iconsHookName = `${name}_payment_method_icons`; const defaultLabel = __( 'Syde Payment Gateway', @@ -47,6 +49,25 @@ inpsydeGateways.forEach((name) => { ; }; + + const SavedTokenContent = (props) => { + const [components, setComponents] = useState([]) + useEffect(() => { + setComponents(defaultHooks.applyFilters(savedTokenFieldsHookName, [])) + }, []); + /** + * If no external plugins/slot-fills are configured, + * we default to not displaying anything + */ + if (!Array.isArray(components) || !components.length) { + return null; + } + + return ( + <>{components.map((Component) => )} + ); + }; + /** * Payment method config object. */ @@ -55,6 +76,7 @@ inpsydeGateways.forEach((name) => { label: