From 150597e005aa4ff4917a68463c5f81fc450be62c Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Tue, 17 Dec 2024 15:40:53 +0100 Subject: [PATCH] Add payment library to repo --- lib/payment-gateway/.distignore | 8 + lib/payment-gateway/CHANGELOG.md | 97 +++ lib/payment-gateway/composer.json | 112 ++++ lib/payment-gateway/index.php | 31 + .../ddev-wordpress-plugin-example.pot | 36 + lib/payment-gateway/package.json | 34 + lib/payment-gateway/psalm.xml.dist | 150 +++++ lib/payment-gateway/release.config.js | 15 + lib/payment-gateway/resources/js/backend.js | 1 + .../resources/js/blocks/index.js | 67 ++ .../src/Fields/ContentField.php | 56 ++ .../src/GatewayIconsRendererInterface.php | 15 + lib/payment-gateway/src/I18n.php | 56 ++ .../src/NoopPaymentProcessor.php | 16 + .../src/NoopPaymentRequestValidator.php | 13 + .../src/NoopRefundProcessor.php | 14 + .../src/PaymentFieldsRendererInterface.php | 18 + lib/payment-gateway/src/PaymentGateway.php | 619 ++++++++++++++++++ .../src/PaymentGatewayBlocks.php | 112 ++++ .../src/PaymentGatewayModule.php | 192 ++++++ .../src/PaymentGatewayValidator.php | 35 + .../src/PaymentProcessorInterface.php | 10 + .../src/PaymentRequestValidatorInterface.php | 15 + .../src/RefundProcessorInterface.php | 20 + .../src/SettingsFieldRendererInterface.php | 10 + .../src/SettingsFieldSanitizerInterface.php | 23 + lib/payment-gateway/webpack.config.js | 47 ++ 27 files changed, 1822 insertions(+) create mode 100644 lib/payment-gateway/.distignore create mode 100644 lib/payment-gateway/CHANGELOG.md create mode 100644 lib/payment-gateway/composer.json create mode 100644 lib/payment-gateway/index.php create mode 100644 lib/payment-gateway/languages/ddev-wordpress-plugin-example.pot create mode 100644 lib/payment-gateway/package.json create mode 100644 lib/payment-gateway/psalm.xml.dist create mode 100644 lib/payment-gateway/release.config.js create mode 100644 lib/payment-gateway/resources/js/backend.js create mode 100644 lib/payment-gateway/resources/js/blocks/index.js create mode 100644 lib/payment-gateway/src/Fields/ContentField.php create mode 100644 lib/payment-gateway/src/GatewayIconsRendererInterface.php create mode 100644 lib/payment-gateway/src/I18n.php create mode 100644 lib/payment-gateway/src/NoopPaymentProcessor.php create mode 100644 lib/payment-gateway/src/NoopPaymentRequestValidator.php create mode 100644 lib/payment-gateway/src/NoopRefundProcessor.php create mode 100644 lib/payment-gateway/src/PaymentFieldsRendererInterface.php create mode 100644 lib/payment-gateway/src/PaymentGateway.php create mode 100644 lib/payment-gateway/src/PaymentGatewayBlocks.php create mode 100644 lib/payment-gateway/src/PaymentGatewayModule.php create mode 100644 lib/payment-gateway/src/PaymentGatewayValidator.php create mode 100644 lib/payment-gateway/src/PaymentProcessorInterface.php create mode 100644 lib/payment-gateway/src/PaymentRequestValidatorInterface.php create mode 100644 lib/payment-gateway/src/RefundProcessorInterface.php create mode 100644 lib/payment-gateway/src/SettingsFieldRendererInterface.php create mode 100644 lib/payment-gateway/src/SettingsFieldSanitizerInterface.php create mode 100644 lib/payment-gateway/webpack.config.js diff --git a/lib/payment-gateway/.distignore b/lib/payment-gateway/.distignore new file mode 100644 index 00000000..185a70f6 --- /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/CHANGELOG.md b/lib/payment-gateway/CHANGELOG.md new file mode 100644 index 00000000..f32ab37a --- /dev/null +++ b/lib/payment-gateway/CHANGELOG.md @@ -0,0 +1,97 @@ +# [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/composer.json b/lib/payment-gateway/composer.json new file mode 100644 index 00000000..b13040dd --- /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": "^1.5" + }, + "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/index.php b/lib/payment-gateway/index.php new file mode 100644 index 00000000..4d2383de --- /dev/null +++ b/lib/payment-gateway/index.php @@ -0,0 +1,31 @@ + 'GET', + 'callback' => function () { + return ['hello' => __('world', 'ddev-wordpress-plugin-example')]; + }, + 'permission_callback' => '__return_true', + ]); +}); + + diff --git a/lib/payment-gateway/languages/ddev-wordpress-plugin-example.pot b/lib/payment-gateway/languages/ddev-wordpress-plugin-example.pot new file mode 100644 index 00000000..2ac5537a --- /dev/null +++ b/lib/payment-gateway/languages/ddev-wordpress-plugin-example.pot @@ -0,0 +1,36 @@ +# Copyright (C) 2023 Inpsyde +# This file is distributed under the GPL-2.0. +msgid "" +msgstr "" +"Project-Id-Version: ddev-wordpress-plugin-example {VERSION}\n" +"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/ddev-wordpress-plugin-example\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"POT-Creation-Date: 2023-02-01T14:03:42+00:00\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"X-Generator: WP-CLI 2.7.1\n" +"X-Domain: ddev-wordpress-plugin-example\n" + +#. Plugin Name of the plugin +msgid "ddev-wordpress-plugin-example" +msgstr "" + +#. Plugin URI of the plugin +#. Author URI of the plugin +msgid "https://inpsyde.com" +msgstr "" + +#. Description of the plugin +msgid "{DESCRIPTION}" +msgstr "" + +#. Author of the plugin +msgid "Inpsyde" +msgstr "" + +#: ddev-wordpress-plugin-example.php:25 +msgid "world" +msgstr "" diff --git a/lib/payment-gateway/package.json b/lib/payment-gateway/package.json new file mode 100644 index 00000000..ba7a3303 --- /dev/null +++ b/lib/payment-gateway/package.json @@ -0,0 +1,34 @@ +{ + "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" + } +} diff --git a/lib/payment-gateway/psalm.xml.dist b/lib/payment-gateway/psalm.xml.dist new file mode 100644 index 00000000..8cf3d706 --- /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 00000000..0ca2a55e --- /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/backend.js b/lib/payment-gateway/resources/js/backend.js new file mode 100644 index 00000000..f5f3a3c6 --- /dev/null +++ b/lib/payment-gateway/resources/js/backend.js @@ -0,0 +1 @@ +alert('hi!'); diff --git a/lib/payment-gateway/resources/js/blocks/index.js b/lib/payment-gateway/resources/js/blocks/index.js new file mode 100644 index 00000000..17c66c7e --- /dev/null +++ b/lib/payment-gateway/resources/js/blocks/index.js @@ -0,0 +1,67 @@ +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'; + + +inpsydeGateways.forEach((name) => { + const settings = getSetting(`${name}_data`, {}); + const hookName = `${name}_checkout_fields`; + const defaultLabel = __( + 'Syde Payment Gateway', + 'syde-payment-gateway' + ); + + const label = decodeEntities(settings.title) || defaultLabel; + + const Content = () => { + const components = defaultHooks.applyFilters(hookName, []) + console.log(hookName) + + /** + * If no external plugins/slot-fills are configured, + * we default to displaying the method description + */ + if (!Array.isArray(components) || !components.length) { + const DefaultPlugin = () => decodeEntities(settings.description || ''); + return + } + + return ( + <>{components.map((Component) => )} + ); + }; + /** + * Label component + * + * @param {*} props Props from payment API. + */ + const Label = (props) => { + const {PaymentMethodLabel} = props.components; + return ; + }; + + /** + * Payment method config object. + */ + const PaymentMethod = { + name: name, + label: