diff --git a/.gitignore b/.gitignore index 5548067..b7ff43a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -wordpress +/.idea + +/vendor diff --git a/README.md b/README.md index 5da2a6a..f5e23a0 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,18 @@ Here you will find files to download and install the official SimPay plugin for * *Safety and continuous technical support* – we guarantee proper security for all payments. And in case of problems with the integration or operation of SimPay systems, we immediately respond with support. Do you have an issue with integration or want to learn more? Write to kontakt@simpay.pl + +## Requirements + +* PHP >= 8.1 +* Wordpress >= 6.0 +* Composer >= 2.1 +* SimPay API credentials + +## Installation + +1. Download the latest release from [here](#) +2. Upload the plugin to your Wordpress installation +3. Activate the plugin +4. Go to the plugin settings page and enter your API credentials +5. You're ready to go! diff --git a/assets/img/sim.png b/assets/img/sim.png deleted file mode 100644 index 9367fb3..0000000 Binary files a/assets/img/sim.png and /dev/null differ diff --git a/assets/js/simpay.js b/assets/js/simpay.js deleted file mode 100644 index cf82860..0000000 --- a/assets/js/simpay.js +++ /dev/null @@ -1,9 +0,0 @@ -jQuery("#usluga2").change(function () { - const selected = jQuery(this).find(':selected').val(); - - jQuery('.selectsms').hide(); - jQuery('#prices_' + selected).show(); - - console.log('test'); - -}); \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..8b20589 --- /dev/null +++ b/composer.json @@ -0,0 +1,24 @@ +{ + "name": "simpay/simpay-wordpress", + "version": "2.0.0", + "type": "library", + "require": { + "simpaypl/simpay": "^2.2", + "ext-yaml": "*" + }, + "autoload": { + "psr-4": { + "SimPay\\SimPayWordpressPlugin\\": "src/", + "SimPay\\SimPayWordpressPlugin\\Migrations\\": "migrations/" + } + }, + "archive": { + "exclude": [ + ".*", + "composer.*", + "output.*", + "DOCKER_ENV", + "docker_tag" + ] + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..4d8ccd5 --- /dev/null +++ b/composer.lock @@ -0,0 +1,1126 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "34b5b5b81edcea10098e780ed955fbf8", + "packages": [ + { + "name": "guzzlehttp/guzzle", + "version": "7.8.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "1110f66a6530a40fe7aea0378fe608ee2b2248f9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/1110f66a6530a40fe7aea0378fe608ee2b2248f9", + "reference": "1110f66a6530a40fe7aea0378fe608ee2b2248f9", + "shasum": "" + }, + "require": { + "ext-json": "*", + "guzzlehttp/promises": "^1.5.3 || ^2.0.1", + "guzzlehttp/psr7": "^1.9.1 || ^2.5.1", + "php": "^7.2.5 || ^8.0", + "psr/http-client": "^1.0", + "symfony/deprecation-contracts": "^2.2 || ^3.0" + }, + "provide": { + "psr/http-client-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.1", + "ext-curl": "*", + "php-http/client-integration-tests": "dev-master#2c025848417c1135031fdf9c728ee53d0a7ceaee as 3.0.999", + "php-http/message-factory": "^1.1", + "phpunit/phpunit": "^8.5.29 || ^9.5.23", + "psr/log": "^1.1 || ^2.0 || ^3.0" + }, + "suggest": { + "ext-curl": "Required for CURL handler support", + "ext-intl": "Required for Internationalized Domain Name (IDN) support", + "psr/log": "Required for using the Log middleware" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Jeremy Lindblom", + "email": "jeremeamia@gmail.com", + "homepage": "https://github.com/jeremeamia" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "psr-18", + "psr-7", + "rest", + "web service" + ], + "support": { + "issues": "https://github.com/guzzle/guzzle/issues", + "source": "https://github.com/guzzle/guzzle/tree/7.8.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle", + "type": "tidelift" + } + ], + "time": "2023-08-27T10:20:53+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "111166291a0f8130081195ac4556a5587d7f1b5d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/111166291a0f8130081195ac4556a5587d7f1b5d", + "reference": "111166291a0f8130081195ac4556a5587d7f1b5d", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.1", + "phpunit/phpunit": "^8.5.29 || ^9.5.23" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "support": { + "issues": "https://github.com/guzzle/promises/issues", + "source": "https://github.com/guzzle/promises/tree/2.0.1" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises", + "type": "tidelift" + } + ], + "time": "2023-08-03T15:11:55+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "2.6.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "be45764272e8873c72dbe3d2edcfdfcc3bc9f727" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/be45764272e8873c72dbe3d2edcfdfcc3bc9f727", + "reference": "be45764272e8873c72dbe3d2edcfdfcc3bc9f727", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.1 || ^2.0", + "ralouphie/getallheaders": "^3.0" + }, + "provide": { + "psr/http-factory-implementation": "1.0", + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.1", + "http-interop/http-factory-tests": "^0.9", + "phpunit/phpunit": "^8.5.29 || ^9.5.23" + }, + "suggest": { + "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "psr-7", + "request", + "response", + "stream", + "uri", + "url" + ], + "support": { + "issues": "https://github.com/guzzle/psr7/issues", + "source": "https://github.com/guzzle/psr7/tree/2.6.1" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7", + "type": "tidelift" + } + ], + "time": "2023-08-27T10:13:57+00:00" + }, + { + "name": "illuminate/collections", + "version": "v10.21.0", + "source": { + "type": "git", + "url": "https://github.com/illuminate/collections.git", + "reference": "f494398dbaaead9e5ff16a18002d11634e8358e6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/collections/zipball/f494398dbaaead9e5ff16a18002d11634e8358e6", + "reference": "f494398dbaaead9e5ff16a18002d11634e8358e6", + "shasum": "" + }, + "require": { + "illuminate/conditionable": "^10.0", + "illuminate/contracts": "^10.0", + "illuminate/macroable": "^10.0", + "php": "^8.1" + }, + "suggest": { + "symfony/var-dumper": "Required to use the dump method (^6.2)." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "10.x-dev" + } + }, + "autoload": { + "files": [ + "helpers.php" + ], + "psr-4": { + "Illuminate\\Support\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Collections package.", + "homepage": "https://laravel.com", + "support": { + "issues": "https://github.com/laravel/framework/issues", + "source": "https://github.com/laravel/framework" + }, + "time": "2023-08-11T14:48:51+00:00" + }, + { + "name": "illuminate/conditionable", + "version": "v10.21.0", + "source": { + "type": "git", + "url": "https://github.com/illuminate/conditionable.git", + "reference": "d0958e4741fc9d6f516a552060fd1b829a85e009" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/conditionable/zipball/d0958e4741fc9d6f516a552060fd1b829a85e009", + "reference": "d0958e4741fc9d6f516a552060fd1b829a85e009", + "shasum": "" + }, + "require": { + "php": "^8.0.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "10.x-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Support\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Conditionable package.", + "homepage": "https://laravel.com", + "support": { + "issues": "https://github.com/laravel/framework/issues", + "source": "https://github.com/laravel/framework" + }, + "time": "2023-02-03T08:06:17+00:00" + }, + { + "name": "illuminate/contracts", + "version": "v10.21.0", + "source": { + "type": "git", + "url": "https://github.com/illuminate/contracts.git", + "reference": "eb1a7e72e159136a832f2c0467de5570bdc208ae" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/contracts/zipball/eb1a7e72e159136a832f2c0467de5570bdc208ae", + "reference": "eb1a7e72e159136a832f2c0467de5570bdc208ae", + "shasum": "" + }, + "require": { + "php": "^8.1", + "psr/container": "^1.1.1|^2.0.1", + "psr/simple-cache": "^1.0|^2.0|^3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "10.x-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Contracts\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Contracts package.", + "homepage": "https://laravel.com", + "support": { + "issues": "https://github.com/laravel/framework/issues", + "source": "https://github.com/laravel/framework" + }, + "time": "2023-07-26T21:27:34+00:00" + }, + { + "name": "illuminate/macroable", + "version": "v10.21.0", + "source": { + "type": "git", + "url": "https://github.com/illuminate/macroable.git", + "reference": "dff667a46ac37b634dcf68909d9d41e94dc97c27" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/macroable/zipball/dff667a46ac37b634dcf68909d9d41e94dc97c27", + "reference": "dff667a46ac37b634dcf68909d9d41e94dc97c27", + "shasum": "" + }, + "require": { + "php": "^8.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "10.x-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Support\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Macroable package.", + "homepage": "https://laravel.com", + "support": { + "issues": "https://github.com/laravel/framework/issues", + "source": "https://github.com/laravel/framework" + }, + "time": "2023-06-05T12:46:42+00:00" + }, + { + "name": "psr/container", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "shasum": "" + }, + "require": { + "php": ">=7.4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "support": { + "issues": "https://github.com/php-fig/container/issues", + "source": "https://github.com/php-fig/container/tree/2.0.2" + }, + "time": "2021-11-05T16:47:00+00:00" + }, + { + "name": "psr/http-client", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-client.git", + "reference": "0955afe48220520692d2d09f7ab7e0f93ffd6a31" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/0955afe48220520692d2d09f7ab7e0f93ffd6a31", + "reference": "0955afe48220520692d2d09f7ab7e0f93ffd6a31", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", + "keywords": [ + "http", + "http-client", + "psr", + "psr-18" + ], + "support": { + "source": "https://github.com/php-fig/http-client/tree/1.0.2" + }, + "time": "2023-04-10T20:12:12+00:00" + }, + { + "name": "psr/http-factory", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "e616d01114759c4c489f93b099585439f795fe35" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/e616d01114759c4c489f93b099585439f795fe35", + "reference": "e616d01114759c4c489f93b099585439f795fe35", + "shasum": "" + }, + "require": { + "php": ">=7.0.0", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-factory/tree/1.0.2" + }, + "time": "2023-04-10T20:10:41+00:00" + }, + { + "name": "psr/http-message", + "version": "2.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/2.0" + }, + "time": "2023-04-04T09:54:51+00:00" + }, + { + "name": "psr/simple-cache", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/simple-cache.git", + "reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/764e0b3939f5ca87cb904f570ef9be2d78a07865", + "reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865", + "shasum": "" + }, + "require": { + "php": ">=8.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\SimpleCache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interfaces for simple caching", + "keywords": [ + "cache", + "caching", + "psr", + "psr-16", + "simple-cache" + ], + "support": { + "source": "https://github.com/php-fig/simple-cache/tree/3.0.0" + }, + "time": "2021-10-29T13:26:27+00:00" + }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "support": { + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" + }, + "time": "2019-03-08T08:55:37+00:00" + }, + { + "name": "simpaypl/simpay", + "version": "2.2.0", + "source": { + "type": "git", + "url": "https://github.com/SimPaypl/SimPay-API-php.git", + "reference": "769e1c19acfc0f0c9f2fa32c0b865bf3751775a3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/SimPaypl/SimPay-API-php/zipball/769e1c19acfc0f0c9f2fa32c0b865bf3751775a3", + "reference": "769e1c19acfc0f0c9f2fa32c0b865bf3751775a3", + "shasum": "" + }, + "require": { + "ext-iconv": "*", + "ext-json": "*", + "guzzlehttp/guzzle": "^7.4", + "illuminate/collections": ">=8.68", + "php": ">=7.4", + "symfony/var-dumper": ">=5.3" + }, + "type": "library", + "autoload": { + "psr-4": { + "SimPay\\API\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Krzysztof Grzelak", + "email": "k.grzelak@simpay.pl" + } + ], + "description": "Official SimPay API", + "support": { + "issues": "https://github.com/SimPaypl/SimPay-API-php/issues", + "source": "https://github.com/SimPaypl/SimPay-API-php/tree/v2.2.0" + }, + "time": "2023-04-26T11:59:35+00:00" + }, + { + "name": "symfony/deprecation-contracts", + "version": "v3.3.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/7c3aff79d10325257a001fcf92d991f24fc967cf", + "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.4-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "files": [ + "function.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A generic function and convention to trigger deprecation notices", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.3.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-05-23T14:45:45+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.28.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "42292d99c55abe617799667f454222c54c60e229" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/42292d99c55abe617799667f454222c54c60e229", + "reference": "42292d99c55abe617799667f454222c54c60e229", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "provide": { + "ext-mbstring": "*" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.28-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.28.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-07-28T09:04:16+00:00" + }, + { + "name": "symfony/var-dumper", + "version": "v6.3.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/var-dumper.git", + "reference": "2027be14f8ae8eae999ceadebcda5b4909b81d45" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/2027be14f8ae8eae999ceadebcda5b4909b81d45", + "reference": "2027be14f8ae8eae999ceadebcda5b4909b81d45", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/deprecation-contracts": "^2.5|^3", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/console": "<5.4" + }, + "require-dev": { + "ext-iconv": "*", + "symfony/console": "^5.4|^6.0", + "symfony/http-kernel": "^5.4|^6.0", + "symfony/process": "^5.4|^6.0", + "symfony/uid": "^5.4|^6.0", + "twig/twig": "^2.13|^3.0.4" + }, + "bin": [ + "Resources/bin/var-dump-server" + ], + "type": "library", + "autoload": { + "files": [ + "Resources/functions/dump.php" + ], + "psr-4": { + "Symfony\\Component\\VarDumper\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides mechanisms for walking through any arbitrary PHP variable", + "homepage": "https://symfony.com", + "keywords": [ + "debug", + "dump" + ], + "support": { + "source": "https://github.com/symfony/var-dumper/tree/v6.3.4" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-08-24T14:51:05+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.3.0" +} diff --git a/config/simpay-wordpress.yaml b/config/simpay-wordpress.yaml new file mode 100644 index 0000000..54e4026 --- /dev/null +++ b/config/simpay-wordpress.yaml @@ -0,0 +1,10 @@ +plugin_config: + modules: + - SimPay\SimPayWordpressPlugin\Modules\AdminManager\SimPayAdminManager + - SimPay\SimPayWordpressPlugin\Modules\RegisterMode\RegisterModeModule + - SimPay\SimPayWordpressPlugin\Modules\PaywallMode\PaywallModeModule + migration: + migration_path: '%plugin_dir/migrations/' + migrations: + - SimPay\SimPayWordpressPlugin\Migrations\Version_100_plugin_initialize + diff --git a/index.php b/index.php deleted file mode 100644 index 067d750..0000000 --- a/index.php +++ /dev/null @@ -1 +0,0 @@ -\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-09-01T13:05:48+00:00\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"X-Generator: WP-CLI 2.8.1\n" +"X-Domain: simpay-wordpress\n" + +#. Plugin Name of the plugin +msgid "Simpay Wordpress" +msgstr "" + +#. Plugin URI of the plugin +#. Author URI of the plugin +msgid "https://simpay.pl" +msgstr "" + +#. Description of the plugin +msgid "Use Simpay SMS service to use during registration or access to the post." +msgstr "" + +#. Author of the plugin +msgid "Simpay" +msgstr "" + +#: src/Modules/RegisterModeHandler/Hooks/SimPayValidateSmsCodeDuringRegistration.php:50 +msgid "Error: Enter SMS code." +msgstr "" + +#: src/Modules/RegisterModeHandler/Hooks/SimPayValidateSmsCodeDuringRegistration.php:55 +msgid "Error: Invalid SMS code." +msgstr "" diff --git a/migrations/Version_100_plugin_initialize.php b/migrations/Version_100_plugin_initialize.php new file mode 100644 index 0000000..db99adc --- /dev/null +++ b/migrations/Version_100_plugin_initialize.php @@ -0,0 +1,34 @@ +auth = array( - "auth" => array( - "key" => $key, - "secret" => $secret, - ) - ); - } - - //private function - public function url($value, $params = array()) - { - $data = json_encode(array('params' => array_merge($this->auth, $params))); - $this->call = $this->request($data, "https://simpay.pl/api/" . $value); - return $this->call; - } - - public function getStatus($params) - { - $this->response = $this->url('status', $params); - return $this->response; - } - - public function getServices() - { - $this->response = $this->url('get_services'); - return $this->response; - } - - public function getServicesDB() - { - $this->response = $this->url('get_services_db'); - return $this->response; - } - - public function getTransactionsSMS() - { - $this->response = $this->url('transactions_sms'); - return $this->response; - } - - public function getTransactionsDB() - { - $this->response = $this->url('transactions_db'); - return $this->response; - } - - public function getIP() - { - $this->response = $this->url('get_ip'); - return $this->response; - } - - public function check() - { - if (isset($this->response) and is_array($this->response)) { - if (isset($this->response['respond']['status']) and $this->response['respond']['status'] == 'OK') { - return true; - } elseif (isset($this->response['error']) and is_array($this->response['error'])) { - return false; - } - } else { - throw new Exception('Brak informacji na temat ostatniego zapytania'); - } - } - - public function getSMSNumberFrom() - { - if (isset($this->response) and is_array($this->response)) { - if (isset($this->response['respond']['from'])) { - return $this->response['respond']['from']; - } elseif (isset($this->response['error']) and is_array($this->response['error'])) { - return ''; - } - } else { - throw new Exception('Brak informacji na temat ostatniego zapytania'); - } - } - - //private function getSMSValue($number) { - public function getSMSValue($number) - { - for ($iPosition = 0; $iPosition < count($this->arrayCodes); $iPosition++) { - if ($this->arrayCodes[$iPosition][0] == $number) { - return $this->arrayCodes[$iPosition][1]; - } - } - for ($iPosition = 0; $iPosition < count($this->arrayCodesAdult); $iPosition++) { - if ($this->arrayCodesAdult[$iPosition][0] == $number) { - return $this->arrayCodesAdult[$iPosition][1]; - } - } - return 0; - } - - public function error() - { - if (isset($this->response['error']) and is_array($this->response['error'])) { - return true; - } else { - return false; - } - } - - public function showError() - { - if (isset($this->response['error']) and is_array($this->response['error'])) { - return $this->response['error']; - } else { - throw new Exception('Brak bledu do pokazania'); - } - } - - public function getRespondValue() - { - if (isset($this->response['respond']['status'], $this->response['respond']['value'])) { - return $this->response['respond']['value']; - } else { - return false; - } - } - - public function getRespondNumber() - { - if (isset($this->response['respond']['status'], $this->response['respond']['number'])) { - return $this->response['respond']['number']; - } else { - return false; - } - } - - private function request($data, $url) - { - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, $url); - curl_setopt($curl, CURLOPT_POST, 1); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($curl, CURLOPT_POSTFIELDS, $data); - curl_setopt($curl, CURLOPT_FAILONERROR, 1); - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // developer only - $call = curl_exec($curl); - $response = json_decode($call, true); - $error = curl_errno($curl); - curl_close($curl); - - if ($error > 0) { - throw new RuntimeException('CURL ERROR Code: ' . $error); - } - - return $response; - } - - public function response() - { - return $this->response; - } - - public function getResponse() - { - return $this->response; - } - - public function pre($array) - { - echo '
';
-        print_r($array);
-        echo '
'; - } -} diff --git a/req/functions.php b/req/functions.php deleted file mode 100644 index 6cf01db..0000000 --- a/req/functions.php +++ /dev/null @@ -1,13 +0,0 @@ -get_charset_collate(); - $simpay_table_name = $wpdb->prefix . 'simpay'; - $query = "CREATE TABLE " . $simpay_table_name . " ( - id mediumint(9) NOT NULL AUTO_INCREMENT, - numer varchar(10) NOT NULL, - usluga varchar(160) NOT NULL, - prefix varchar(160) NOT NULL, - id_uslugi varchar(160) NOT NULL, - UNIQUE KEY id (id) - ) " . $charset_collate . ";"; - $wpdb->query($query); -} - -function simpay_uninstall() -{ - - global $wpdb; - - /* - * Usuwanie wpisów z ustawień WP - */ - - delete_option("simpay_key"); - delete_option("simpay_secret"); - delete_option("simpay-register-sms"); - delete_option("simpay-register-numer"); - delete_option("simpay-register-sekret"); - delete_option("simpay-register-id"); - delete_option("simpay-register-usluga"); - delete_option("simpay-register-cena"); - delete_option("simpay-hidden-sms"); - delete_option("simpay-hidden-numer"); - delete_option("simpay-hidden-sekret"); - delete_option("simpay-hidden-id"); - delete_option("simpay-hidden-usluga"); - delete_option("simpay-hidden-cena"); - - /* - * Usuwanie tabeli z bazy danych - */ - - $prefix = $wpdb->prefix; - $simpay_table_name = $prefix . "simpay"; - $query = 'DROP TABLE '. $simpay_table_name; - $wpdb->query($query); -} - -function simpay_menu_add() -{ - add_menu_page("SimPay", "SimPay", "manage_options", "simpay-ustawienia", "simpay_admin_settings", plugins_url('simpay-wordpress/assets/img/sim.png'), null, 99); -} - -function simpay_load_scripts() -{ - //wp_enqueue_script('simpay', plugins_url('assets/js/simpay.js', dirname(__FILE__)), array('jquery')); -} - -/* - * Formularz płatności przy rejestracji -*/ - -function simpay_register_form() -{ - global $simpay; - - $simpay_local = []; - $simpay_local['content'] = get_option("simpay-register-sms"); - $simpay_local['number'] = get_option("simpay-register-numer"); - - if (!empty(get_option("simpay-register-sms"))) { - echo '

'; - echo ''; - echo '

'; - } -} - -function simpay_register_validate($errors, $sanitized_user_login, $user_email) -{ - global $simpay; - - try { - if (empty($_POST['kod_sms']) || !empty($_POST['kod_sms']) && trim($_POST['kod_sms']) == '') { - $errors->add('first_name_error', __('ERROR: Wprowadz kod SMS.', 'mydomain')); - - return $errors; - } - - $codeSMS = trim($_POST['kod_sms']); - - if (strlen($codeSMS) == 0) { - $errors->add('first_name_error', __('ERROR: Wprowadz kod SMS.', 'mydomain')); - - return $errors; - } - - $simpay->getStatus([ - 'service_id' => get_option("simpay-register-id") , - 'number' => get_option("simpay-register-numer") , - 'code' => $codeSMS - ]); - - if ($simpay->check()) { - // kod poprawny - } elseif ($simpay->error()) { - // niepoprawny kod - - $errors->add('first_name_error', __('ERROR: Podany kod jest niepoprawny.', 'mydomain')); - } - } catch (Exception $e) { - echo 'Error: ' . $e->getMessage(); - } - - return $errors; -} - -/* - * Blokada zawartości posta, który jest płatny. -*/ - -function simpay_content($content) -{ - global $simpay; - global $wpdb; - - /* - * Wyświetlanie na stronie "głównej" - */ - - if (is_front_page()) { - $querystr = "SELECT * FROM " . $wpdb->prefix . "simpay"; - $uslugi = $wpdb->get_results($querystr, OBJECT); - foreach ($uslugi as & $value) { - $content = preg_replace("%\[hidden_content_" . $value->id . "\](.*?)\[/hidden_content_" . $value->id . "\]%s", "Płatność dostępna wewnątrz wpisu", $content); - } - - return $content; - } - - if (!in_the_loop()) { - return $content; - } - - if (!is_singular()) { - return $content; - } - - if (!is_main_query()) { - return $content; - } - - if (strpos($content, '[hidden_content') > 0) { - preg_match('/\[hidden_content_(?\d+)\]/', $content, $matches); - - $query = "SELECT * FROM " . $wpdb->prefix . "simpay WHERE `id` = %s LIMIT 1;"; - if (!$service = $wpdb->get_row($wpdb->prepare($query, (int)$matches['id']), OBJECT)) { - return; - } - - $kod_poprawny = false; - $alert = ""; - - if (!empty($_POST["simpay_sprawdz"]) && !empty($_POST["simpay_kodsms"])) { - try { - $simpay->getStatus(array( - 'service_id' => $service->id_uslugi, - 'number' => $service->numer, - 'code' => $_POST['simpay_kodsms'] - )); - - if ($simpay->check()) { - $kod_poprawny = true; - } elseif ($simpay->error()) { - $alert = '
Wystąpił problem podczas sprawdzania sms

'; - } - } catch (Exception $e) { - echo 'Error: ' . $e->getMessage(); - } - } - - $forma = ' -
' . $alert . ' -
-
-
-

Wyślij SMS o treści ' . $service->prefix . '.' . $service->usluga . ' na numer ' . $service->numer . ' cena za sms wynosi ' . fnc_calculate_brutto($simpay->getSMSValue($service->numer)) . ' (brutto) PLN

-
-
Wpisz kod usługi:
-
-

- Akceptuję regulamin usługi SMS -
-
- -
-
-
- '; - - if (!$kod_poprawny) { - $content = preg_replace("%\[hidden_content_" . $service->id . "\](.*?)\[/hidden_content_" . $service->id . "\]%s", $forma, $content); - } else { - $content = str_replace('[hidden_content_' . $service->id . ']', "", $content); - $content = str_replace('[/hidden_content_' . $service->id . ']', "", $content); - } - } - - remove_filter('the_content', 'se225721_the_content'); - - return $content; -} - -/* - * Formularze i ustawienia w panelu admina -*/ - -function simpay_admin_settings() -{ - global $wpdb; - global $simpay; - - wp_enqueue_script('simpay', plugins_url('assets/js/simpay.js', dirname(__FILE__)), array('jquery')); - - if (!current_user_can('administrator')) { - return; - } - - //$api = new SimPay(get_option('simpay_key'), get_option('simpay_secret')); - - if (!empty($_POST['aktualizuj_key'])) { - if (!check_admin_referer('simpay')) { - return; - } - - $apiKey = trim($_POST['api_key']); - $apiSecret = trim($_POST['secret_key']); - - if (filter_var($apiKey, FILTER_SANITIZE_STRING) !== false && filter_var($apiSecret, FILTER_SANITIZE_STRING) !== false) { - update_option("simpay_key", $apiKey); - update_option("simpay_secret", $apiSecret); - - echo ""; - } - } - - if (!empty($_POST['aktualizuj_2']) && isset($_POST['usluga2'])) { - if (!check_admin_referer('simpay')) { - return; - } - - $serviceId = trim($_POST['usluga1']); - $number = $_POST['prices1_' . $serviceId]; - - if ($serviceId == 0) { - return; - } - - if ($number == 0) { - return; - } - - $services = $simpay->getServices(); - if ($services['respond']['status'] != "OK") { - //Jakiś błąd. - } - $services = $services['respond']['services']; - $service = $services[array_search($serviceId, array_column($services, 'id'))]; - - if (is_null($service)) { - return; - } - - $number = $_POST['prices1_' . $service['id']]; - - update_option("simpay-register-cena", $simpay->getSMSValue($number)); - update_option("simpay-register-numer", trim($number)); - update_option("simpay-register-sms", trim($service['prefix'] . '.' . $service['sufix'])); - update_option("simpay-register-id", trim($serviceId)); - } - - if (!empty($_POST['aktualizuj_3'])) { - if (!check_admin_referer('simpay')) { - return; - } - - $serviceId = trim($_POST['usluga2']); - $number = $_POST['prices2_' . $serviceId]; - - if ($serviceId == 0) { - return; - } - - if ($number == 0) { - return; - } - - $services = $simpay->getServices(); - if ($services['respond']['status'] != "OK") { - //Jakiś błąd. - } - $services = $services['respond']['services']; - $service = $services[array_search($serviceId, array_column($services, 'id'))]; - - if (is_null($service)) { - return; - } - - $number = $_POST['prices2_' . $service['id']]; - - $wpdb->insert($wpdb->prefix . "simpay", array( - 'numer' => $number, - 'usluga' => $service['sufix'], - 'prefix' => $service['prefix'], - 'id_uslugi' => $service['id'] - )); - } - - $t_menu = ''; - - if (!empty($_GET["register"])) { - $t_menu = ''; - } - - echo ' -
-

Klucz API:

-
Tutaj możesz sprawdzić te dane: https://simpay.pl/panel/Client/API

- - '; - - wp_nonce_field('simpay'); - - echo ' -

-' . $t_menu . '

'; - - if (isset($_GET['register']) && $_GET['register'] == 1) { - try { - $json = $simpay->getServices(); - if (!isset($json['respond']['status'])) { - return; - } - if ($json['respond']['status'] != "OK") { - //Błąd podczas pobierania? - } - echo '
'; - echo ''; - - foreach ($json['respond']['services'] as $service) : - if ($service['status'] == "service_active") : - echo ''; - endif; - endforeach; - - wp_nonce_field('simpay'); - - echo ' -
'; - } catch (Exception $e) { - echo 'Error: ' . $e->getMessage(); - } - } else { - echo 'Dodaj usługe'; - - try { - $json = $simpay->getServices(); - if (!isset($json['respond']['status'])) { - return; - } - - if ($json['respond']['status'] != "OK") { - //Błąd podczas pobierania? - } - echo '
'; - echo ''; - - foreach ($json['respond']['services'] as $service) : - if ($service['status'] == "service_active") : - echo ''; - endif; - endforeach; - - wp_nonce_field('simpay'); - - echo ' -
'; - } catch (Exception $e) { - echo 'Error: ' . $e->getMessage(); - } - global $wpdb; - - $querystr = "SELECT * FROM " . $wpdb->prefix . "simpay"; - - $uslugi = $wpdb->get_results($querystr, OBJECT); - - echo ' - - - - - '; - - foreach ($uslugi as & $value) { - echo ' - - - - - - '; - } - - if (isset($_POST['delete'])) { - $table = $wpdb->prefix . "simpay"; - - $postID = intval(trim($_POST['delete'])); - - $wpdb->delete($table, array( - 'id' => $postID - )); - - echo ""; - } - - echo '
UsługaKodAkcja
' . $value->numer . ':' . $value->usluga . '
'; - - wp_nonce_field('simpay'); - - echo '
'; - } - - return ''; -} diff --git a/simico.png b/simico.png deleted file mode 100644 index 9367fb3..0000000 Binary files a/simico.png and /dev/null differ diff --git a/simpay-wordpress.php b/simpay-wordpress.php index 3b201bf..d4b56c2 100644 --- a/simpay-wordpress.php +++ b/simpay-wordpress.php @@ -1,44 +1,46 @@ activatePlugin(); } -require_once(plugin_dir_path(__FILE__) . 'req/class/SimPay.class.php'); -require_once(plugin_dir_path(__FILE__) . 'req/functions.php'); -require_once(plugin_dir_path(__FILE__) . 'req/simpay.php'); +function deactivateSimPayWordpressPlugin(): void { + $pluginManager = PluginManagerFactory::create(); -$simpay = new SimPay(get_option('simpay_key'), get_option('simpay_secret')); + $pluginManager->deactivatePlugin(); +} -register_activation_hook(__FILE__, 'simpay_install'); -register_deactivation_hook(__FILE__, 'simpay_uninstall'); +register_activation_hook( __FILE__, 'activateSimPayWordpressPlugin' ); +register_deactivation_hook( __FILE__, 'deactivateSimPayWordpressPlugin' ); -/* - * Definiowanie formularza odpowiedzialnego za płatność przy rejestracji. -*/ -add_action('register_form', 'simpay_register_form'); -add_filter('registration_errors', 'simpay_register_validate', 10, 3); +function initSimPay(): void { + $pluginManager = PluginManagerFactory::create(); -/* - * Definiowanie nowej zakładki w menu. -*/ -add_action('admin_menu', 'simpay_menu_add'); + $pluginManager->init(); +} -add_filter('the_content', 'simpay_content'); +add_action( 'plugins_loaded', 'initSimPay', 11 ); diff --git a/src/Config/ConfigManagerException.php b/src/Config/ConfigManagerException.php new file mode 100644 index 0000000..ed4d87e --- /dev/null +++ b/src/Config/ConfigManagerException.php @@ -0,0 +1,11 @@ +loadConfig(); + } + + /** + * @throws ConfigManagerException + */ + private function loadConfig(): void + { + $yamlTags = $this->getYamlTags(); + + $ndocs = null; + $this->configTree = yaml_parse_file( + $this->configFilePath, + 0, + $ndocs, + ['' => fn($value) => str_replace(array_keys($yamlTags), array_values($yamlTags), $value)] + ); + + if ($this->configTree === false) { + throw new ConfigManagerException('Invalid or missing yaml config'); + } + } + + private function getYamlTags(): array + { + return [ + '%plugin_dir' => SIMPAY_ABSPATH, + ]; + } + + public function getConfig($configName, $defaultValue = null): mixed + { + $expectedConfigTree = explode('.', $configName); + + $currentConfigNode = 0; + $finalConfig = $this->configTree; + while (true) { + if (!isset($expectedConfigTree[$currentConfigNode])) { + break; + } + $configNode = $expectedConfigTree[$currentConfigNode++]; + if (!isset($finalConfig[$configNode])) { + $finalConfig = null; + break; + } + $finalConfig = $finalConfig[$configNode]; + } + + return $finalConfig ?? $defaultValue; + } +} diff --git a/src/Database/Migration/DatabaseMigrationFactory.php b/src/Database/Migration/DatabaseMigrationFactory.php new file mode 100644 index 0000000..86d8a81 --- /dev/null +++ b/src/Database/Migration/DatabaseMigrationFactory.php @@ -0,0 +1,28 @@ +prefix, + $wpdb->get_charset_collate(), + QueryManagerFactory::create(), + ]; + } +} diff --git a/src/Database/Migration/DatabaseMigrationInterface.php b/src/Database/Migration/DatabaseMigrationInterface.php new file mode 100644 index 0000000..73b9cb8 --- /dev/null +++ b/src/Database/Migration/DatabaseMigrationInterface.php @@ -0,0 +1,15 @@ +currentDbVersion = (int)\get_option(self::CURRENT_DB_VERSION_OPTION_NAME, 0); + } + + /** + * @throws FailedDatabaseMigrationException + */ + public function runMigration(): void + { + $migrationsToRun = $this->getMigrationsToExecute(); + /** @var MigrationInterface $migration */ + foreach ($migrationsToRun as $migration) { + try { + $queries = $migration::up($this->dbPrefix, $this->dbCharsetCollate); + $this->runQueries($queries); + } catch (FailedDatabaseQueryException) { + throw new FailedDatabaseMigrationException($migration::class); + } + + \update_option(self::CURRENT_DB_VERSION_OPTION_NAME, $migration::getVersion()); + } + } + + public function getMigrationsToExecute(): MigrationsBag + { + $allMigrations = $this->configManager->getConfig('plugin_config.migration.migrations'); + $migrationsToExec = new MigrationsBag(); + + foreach ($allMigrations as $migration) { + if ($migration::getVersion() > $this->currentDbVersion) { + $migrationsToExec->add($migration); + } + } + + return $migrationsToExec; + } + + /** + * @throws FailedDatabaseQueryException + */ + private function runQueries(array|string $queries): void + { + if (!is_array($queries)) { + $queries = [$queries]; + } + + foreach ($queries as $query) { + $this->queryManagerService->write($query); + } + } +} diff --git a/src/Database/Migration/FailedDatabaseMigrationException.php b/src/Database/Migration/FailedDatabaseMigrationException.php new file mode 100644 index 0000000..c41516f --- /dev/null +++ b/src/Database/Migration/FailedDatabaseMigrationException.php @@ -0,0 +1,18 @@ +migration}"; + } +} diff --git a/src/Database/Migration/MigrationInterface.php b/src/Database/Migration/MigrationInterface.php new file mode 100644 index 0000000..cc16117 --- /dev/null +++ b/src/Database/Migration/MigrationInterface.php @@ -0,0 +1,14 @@ +migrations[] = $migration; + } + + public function getIterator(): ArrayIterator + { + return new ArrayIterator($this->migrations); + } +} diff --git a/src/Database/QueryManager/FailedDatabaseQueryException.php b/src/Database/QueryManager/FailedDatabaseQueryException.php new file mode 100644 index 0000000..c0a5f82 --- /dev/null +++ b/src/Database/QueryManager/FailedDatabaseQueryException.php @@ -0,0 +1,18 @@ +lastDbError}"; + } +} diff --git a/src/Database/QueryManager/QueryManagerFactory.php b/src/Database/QueryManager/QueryManagerFactory.php new file mode 100644 index 0000000..53fb9b6 --- /dev/null +++ b/src/Database/QueryManager/QueryManagerFactory.php @@ -0,0 +1,22 @@ +wpDb->query($query); + + if ($dbResult === false) { + throw new FailedDatabaseQueryException($this->getLastDbError()); + } + + return $dbResult; + } + + private function getLastDbError(): string + { + ob_start(); + $this->wpDb->print_error(); + + $error = ob_get_contents(); + ob_end_flush(); + + return $error; + } + + public function readOne(string $query): mixed + { + return $this->wpDb->get_row($query); + } + + public function read(string $query): mixed + { + return $this->wpDb->get_results($query); + } + + public function getDbPrefix(): string + { + return $this->wpDb->prefix; + } + + public function getDbCharset(): string + { + return $this->wpDb->get_charset_collate(); + } +} diff --git a/src/HooksManager/ActionInterface.php b/src/HooksManager/ActionInterface.php new file mode 100644 index 0000000..5559b80 --- /dev/null +++ b/src/HooksManager/ActionInterface.php @@ -0,0 +1,8 @@ +actions = $this->add($this->actions, $hookInstance::getHookName(), $hookInstance, $priority, $accepted_args); + } + + private function add( + array $hooks, + string $hookName, + ActionInterface|FilterInterface $callableMethod, + int $priority, + int $acceptedArgs) + { + $hooks[] = [ + 'hook' => $hookName, + 'callableMethod' => $callableMethod, + 'priority' => $priority, + 'acceptedArgs' => $acceptedArgs + ]; + + return $hooks; + } + + public function addFilter( + FilterInterface $hookInstance, + int $priority = 10, + int $accepted_args = 1 + ) + { + $this->filters = $this->add($this->filters, $hookInstance::getHookName(), $hookInstance, $priority, $accepted_args); + } + + public function loadHooks(): void + { + foreach ($this->filters as $hook) { + add_filter($hook['hook'], $hook['callableMethod'], $hook['priority'], $hook['acceptedArgs']); + } + + foreach ($this->actions as $hook) { + add_action($hook['hook'], $hook['callableMethod'], $hook['priority'], $hook['acceptedArgs']); + } + } +} diff --git a/src/I18n/I18nLoader.php b/src/I18n/I18nLoader.php new file mode 100644 index 0000000..b35e8ca --- /dev/null +++ b/src/I18n/I18nLoader.php @@ -0,0 +1,16 @@ +domainName, + false, + SIMPAY_ABSPATH . 'languages/' + ); + } +} diff --git a/src/ModuleManager/ModuleBag.php b/src/ModuleManager/ModuleBag.php new file mode 100644 index 0000000..b1932d3 --- /dev/null +++ b/src/ModuleManager/ModuleBag.php @@ -0,0 +1,22 @@ +modules[$module::class] = $module; + } + + public function getIterator(): ArrayIterator + { + return new ArrayIterator($this->modules); + } +} diff --git a/src/ModuleManager/ModuleInterface.php b/src/ModuleManager/ModuleInterface.php new file mode 100644 index 0000000..bd97185 --- /dev/null +++ b/src/ModuleManager/ModuleInterface.php @@ -0,0 +1,11 @@ +loadModule(); + } + } +} diff --git a/src/ModuleManager/ModuleLoaderInterface.php b/src/ModuleManager/ModuleLoaderInterface.php new file mode 100644 index 0000000..db3601b --- /dev/null +++ b/src/ModuleManager/ModuleLoaderInterface.php @@ -0,0 +1,8 @@ +pageName = $pageName; + $this->settingsGroup = $settingsGroup; + } + + public function addSection(SectionInterface $section) + { + $section->register(); + } + + public function register(): void + { + register_setting($this->getPageName(), $this->getSettingsGroup()); + $this->formOptions = get_option($this->getSettingsGroup()) ?: []; + + $this->registerSections(); + } + + public function getPageName(): string + { + return $this->pageName; + } + + public function getSettingsGroup(): string + { + return $this->settingsGroup; + } + + abstract public function registerSections(); + + public function getFormOptionValue(string $name): string + { + if (!isset($this->getFormOptions()[$name])) { + return ''; + } + + return $this->getFormOptions()[$name]; + } + + public function getFormOptions(): array + { + return $this->formOptions; + } +} diff --git a/src/Modules/AdminManager/Form/FormInterface.php b/src/Modules/AdminManager/Form/FormInterface.php new file mode 100644 index 0000000..2cdf822 --- /dev/null +++ b/src/Modules/AdminManager/Form/FormInterface.php @@ -0,0 +1,22 @@ +addSection( + new ApiCredentialsSection( + $this, + 'simpay_api_credentials', + 'API Credentials' + ) + ); + $this->addSection( + new PluginModeSection( + $this, + 'simpay_plugin_mode', + 'Plugin Mode' + ) + ); + } +} diff --git a/src/Modules/AdminManager/Form/Section/AbstractSection.php b/src/Modules/AdminManager/Form/Section/AbstractSection.php new file mode 100644 index 0000000..7f79b7e --- /dev/null +++ b/src/Modules/AdminManager/Form/Section/AbstractSection.php @@ -0,0 +1,81 @@ +form = $form; + $this->sectionName = $sectionName; + $this->sectionTitle = $sectionTitle; + $this->view = ViewManagerFactory::create(); + } + + public function addField(string $id, string $title, callable $renderer): void + { + add_settings_field( + $id, + $title, + $renderer, + $this->form->getPageName(), + $this->getSectionName(), + ); + } + + public function getSectionName(): string + { + return $this->sectionName; + } + + public function register(): void + { + add_settings_section( + $this->getSectionName(), + $this->getSectionTitle(), + [$this, 'afterRegisterSection'], + $this->form->getPageName(), + ); + + $this->registerFields(); + } + + public function getSectionTitle(): string + { + return $this->sectionTitle; + } + + abstract protected function registerFields(); + + public function afterRegisterSection(): void + { + settings_errors($this->getErrorsId(), true, true); + } + + protected function getFieldNameForForm(string $string): string + { + return $this->form->getSettingsGroup() . "[$string]"; + } + + protected function addErrorAlert(string $message, $type = 'error'): void + { + add_settings_error($this->getErrorsId(), $this->getErrorsId(), $message, $type); + } + + protected function getErrorsId(): string + { + return $this->getSectionName() . '_errors'; + } +} diff --git a/src/Modules/AdminManager/Form/Section/ApiCredentialsSection.php b/src/Modules/AdminManager/Form/Section/ApiCredentialsSection.php new file mode 100644 index 0000000..a77c8a0 --- /dev/null +++ b/src/Modules/AdminManager/Form/Section/ApiCredentialsSection.php @@ -0,0 +1,51 @@ +view->render('admin.settings.partials.field-input', [ + 'args' => [ + 'type' => 'text', + 'placeholder' => 'API Key', + 'name' => $this->getFieldNameForForm('simpay_api_key'), + 'value' => $this->form->getFormOptionValue('simpay_api_key'), + ] + ]); + } + + public function getFieldApiPassword(): void + { + $this->view->render('admin.settings.partials.field-input', [ + 'args' => [ + 'type' => 'password', + 'placeholder' => 'API Password', + 'name' => $this->getFieldNameForForm('simpay_api_password'), + 'value' => $this->form->getFormOptionValue('simpay_api_password'), + ] + ]); + } + + public function getFieldServiceId(): void + { + $this->view->render('admin.settings.partials.field-input', [ + 'args' => [ + 'type' => 'text', + 'placeholder' => 'Service ID', + 'name' => $this->getFieldNameForForm('simpay_service_id'), + 'value' => $this->form->getFormOptionValue('simpay_service_id'), + ] + ]); + } + + protected function registerFields(): void + { + $this->addField('simpay_api_key', 'API Key', [$this, 'getFieldApiKey']); + $this->addField('simpay_api_password', 'API Password', [$this, 'getFieldApiPassword']); + $this->addField('simpay_service_id', 'Service ID', [$this, 'getFieldServiceId']); + } +} diff --git a/src/Modules/AdminManager/Form/Section/PluginModeSection.php b/src/Modules/AdminManager/Form/Section/PluginModeSection.php new file mode 100644 index 0000000..2f6ac13 --- /dev/null +++ b/src/Modules/AdminManager/Form/Section/PluginModeSection.php @@ -0,0 +1,89 @@ +view->render('admin.settings.partials.field-select', [ + 'args' => [ + 'name' => $this->getFieldNameForForm('simpay_plugin_mode'), + 'value' => $this->form->getFormOptionValue('simpay_plugin_mode'), + 'options' => [ + 'register' => "Pay for register", + 'per_post' => "Pay for post view", + ], + 'disabled' => $disabledOptions, + ] + ]); + } + + public function getFieldSmsNumber(): void + { + $options = []; + $smsNumbers = $this->simPayService->getSmsNumbers(); + + /** @var SmsNumberInterface $smsNumber */ + foreach ($smsNumbers as $smsNumber) { + $options[$smsNumber->getNumber()] = $this->makeOptionValueForSmsPrice($smsNumber); + } + + $this->view->render('admin.settings.partials.field-select', [ + 'args' => [ + 'name' => $this->getFieldNameForForm('simpay_sms_number'), + 'value' => $this->form->getFormOptionValue('simpay_sms_number'), + 'options' => $options, + ] + ]); + } + + private function makeOptionValueForSmsPrice(SmsNumberInterface $smsNumber): string + { + return "{$smsNumber->getPriceNet()} PLN ({$smsNumber->getPriceGross()} PLN VAT)"; + } + + protected function registerFields(): void + { + if (!get_option('users_can_register')) { + $this->addErrorAlert('Registrations of users are disabled, so you need to turn it on first to use Pay for register Mode', 'info'); + } + + if ( + $this->form->getFormOptionValue('simpay_api_key') && + $this->form->getFormOptionValue('simpay_api_password') && + $this->form->getFormOptionValue('simpay_service_id') + ) { + try { + $this->simPayService = SimPayServiceFactory::create(); + $this->simPayService->getSmsService(); + } catch (SimPayApiInvalidCredentialsException) { + $this->addErrorAlert('Invalid credentials to SimPay API', 'error'); + return; + } + } else { + return; + } + + $this->addField('simpay_plugin_mode', 'Mode of plugin', [$this, 'getFieldModeOfPlugin']); + + if ( + $this->form->getFormOptionValue('simpay_plugin_mode') === '' || + $this->form->getFormOptionValue('simpay_plugin_mode') === 'register' + ) { + $this->addField('simpay_sms_number', 'Price for registration', [$this, 'getFieldSmsNumber']); + } + } +} diff --git a/src/Modules/AdminManager/Form/Section/SectionInterface.php b/src/Modules/AdminManager/Form/Section/SectionInterface.php new file mode 100644 index 0000000..1fa7413 --- /dev/null +++ b/src/Modules/AdminManager/Form/Section/SectionInterface.php @@ -0,0 +1,16 @@ +render('admin.settings.settings-page'); + } +} diff --git a/src/Modules/AdminManager/Hooks/InitSettingsPageHook.php b/src/Modules/AdminManager/Hooks/InitSettingsPageHook.php new file mode 100644 index 0000000..d56bf1e --- /dev/null +++ b/src/Modules/AdminManager/Hooks/InitSettingsPageHook.php @@ -0,0 +1,24 @@ +register(); + } +} diff --git a/src/Modules/AdminManager/SimPayAdminManager.php b/src/Modules/AdminManager/SimPayAdminManager.php new file mode 100644 index 0000000..6305a76 --- /dev/null +++ b/src/Modules/AdminManager/SimPayAdminManager.php @@ -0,0 +1,31 @@ +initializeAdminSettings(); + } + + private function initializeAdminSettings(): void + { + $this->hooksManager->addAction(new InitSettingsPageHook()); + $this->hooksManager->addAction(new AddAdminPageHook()); + } +} diff --git a/src/Modules/PaywallMode/Hooks/AddPaywallMetaboxesToPostEdit.php b/src/Modules/PaywallMode/Hooks/AddPaywallMetaboxesToPostEdit.php new file mode 100644 index 0000000..ba89bbb --- /dev/null +++ b/src/Modules/PaywallMode/Hooks/AddPaywallMetaboxesToPostEdit.php @@ -0,0 +1,81 @@ +view = ViewManagerFactory::create(); + } + + public static function getHookName(): string + { + return 'add_meta_boxes'; + } + + public function __invoke(): void + { + add_meta_box( + 'simpay-paywall-options', + __('Paywall settings', 'simpay-wordpress'), + [$this, 'renderMetaboxContent'], + ); + } + + public function renderMetaboxContent($post): void + { + $this->post = $post; + $this->view->render('admin.settings.partials.table-form', [ + 'elements' => [ + __('Is Paywall active:') => [$this, 'getIsPaywallActive'], + __('SMS Numbers:') => [$this, 'getSmsNumbers'], + ] + ]); + } + + public function getIsPaywallActive(): void + { + $this->view->render('admin.settings.partials.field-checkbox', [ + 'args' => [ + 'name' => 'paywall_active', + 'value' => get_post_meta($this->post->ID, 'paywall_active', false)[0] ?? false, + ], + ]); + } + + public function getSmsNumbers(): void + { + $options = []; + $smsNumbers = $this->simPayService->getSmsNumbers(); + + /** @var SmsNumberInterface $smsNumber */ + foreach ($smsNumbers as $smsNumber) { + $options[$smsNumber->getNumber()] = $this->makeOptionValueForSmsPrice($smsNumber); + } + + $this->view->render('admin.settings.partials.field-select', [ + 'args' => [ + 'name' => 'paywall_price', + 'value' => get_post_meta($this->post->ID, 'paywall_price', null)[0] ?? false, + 'options' => $options + ] + ]); + } + + private function makeOptionValueForSmsPrice(SmsNumberInterface $smsNumber): string + { + return "{$smsNumber->getPriceNet()} PLN ({$smsNumber->getPriceGross()} PLN VAT)"; + } +} diff --git a/src/Modules/PaywallMode/Hooks/AddPaywallOnPost.php b/src/Modules/PaywallMode/Hooks/AddPaywallOnPost.php new file mode 100644 index 0000000..1b95762 --- /dev/null +++ b/src/Modules/PaywallMode/Hooks/AddPaywallOnPost.php @@ -0,0 +1,145 @@ +view = ViewManagerFactory::create(); + $this->simPayOptions = get_option('simpay_options') ?: []; + } + + public static function getHookName(): string + { + return 'the_content'; + } + + public function __invoke($content): string + { + if ($this->simPayOptions['simpay_plugin_mode'] !== 'per_post') { + return $content; + } + + if ($this->simPayOptions['simpay_plugin_mode'] !== 'per_post') { + return $content; + } + + global $wp_query; + + $paywallActiveOption = get_post_meta(get_the_ID(), 'paywall_active', false)[0] ?? false; + $postSmsNumber = get_post_meta(get_the_ID(), 'paywall_price', false)[0] ?? false; + + $this->paywallActive = (bool) $paywallActiveOption; + $this->postSmsNumber = (int) $postSmsNumber; + + if ($this->paywallActive !== true) { + return $content; + } + + if (current_user_can('editor') || current_user_can('administrator')) { + return $content; + } + + if ($this->paywallModeService->hasUserPaymentForPost(get_current_user_id(), get_the_ID())) { + return $content; + } + + if (!is_user_logged_in()) { + return $this->showNotLoggedInAlert(); + } + return $this->handlePaywallForm($wp_query); + + + return $content; + } + + private function showNotLoggedInAlert(): string + { + $this->view->render('public.paywall.access-denied-alert', [ + 'showNotLoggedInInfo' => true, + 'registerUrl' => wp_login_url(), + ]); + + return ''; + } + + /** + * @throws SimPayApiInvalidCredentialsException + */ + private function handlePaywallForm(mixed $wpQuery): ?string + { + if (isset($_POST['sms_code'])) { + if ($error = $this->validateSmsForm()) { + $this->renderSimPayPaymentForm(get_the_ID(), $error); + return ''; + } + $this->paywallModeService->grantAccessToPost(get_current_user_id(), get_the_ID()); + + $this->renderSuccessfulAlert(); + return ''; + } + $this->renderSimPayPaymentForm(get_the_ID()); + + return ''; + } + + /** + * @throws SimPayApiInvalidCredentialsException + */ + private function validateSmsForm(): ?string + { + if (!isset($_POST['sms_code']) || trim($_POST['sms_code']) === '') { + $errors = __('Error: Enter SMS code.', 'simpay-wordpress'); + return $errors; + } + + if (!$this->simPayService->getSmsCodeValidation($_POST['sms_code'], $this->postSmsNumber)->isValid()) { + $errors = __('Error: Invalid SMS code.', 'simpay-wordpress'); + } + + return $errors ?? null; + } + + public function renderSimPayPaymentForm(int $postId, string $error = null): void + { + $this->view->render('public.paywall.access-denied-alert', ['error' => $error]); + + try { + $smsNumber = $this->simPayService->getSmsNumber($this->postSmsNumber); + } catch (SimPayApiInvalidCredentialsException) { + return; + } + + $view = ViewManagerFactory::create(); + $view->render('public.paywall.payment-form', [ + 'postId' => $postId, + 'smsNumber' => $smsNumber->getNumber(), + 'smsPrice' => $smsNumber->getPriceGross(), + 'smsCode' => $this->simPayService->getSmsCode()->getCode(), + ]); + } + + private function renderSuccessfulAlert(): void + { + $this->view->render('public.paywall.successful-payment', [ + 'permalink' => get_permalink(), + ]); + } +} diff --git a/src/Modules/PaywallMode/Hooks/AddSubmenuToSimPayMenu.php b/src/Modules/PaywallMode/Hooks/AddSubmenuToSimPayMenu.php new file mode 100644 index 0000000..35381fa --- /dev/null +++ b/src/Modules/PaywallMode/Hooks/AddSubmenuToSimPayMenu.php @@ -0,0 +1,46 @@ +paywallModeService); + $table->prepare_items(); + $table->display(); + } +} diff --git a/src/Modules/PaywallMode/Hooks/PopulatePaywallColumnsOnPostsListing.php b/src/Modules/PaywallMode/Hooks/PopulatePaywallColumnsOnPostsListing.php new file mode 100644 index 0000000..8d2c418 --- /dev/null +++ b/src/Modules/PaywallMode/Hooks/PopulatePaywallColumnsOnPostsListing.php @@ -0,0 +1,29 @@ +paywallModeService->getNumberOfPaywallUsersOfPost($postId); + } +} diff --git a/src/Modules/PaywallMode/Hooks/SaveMetaboxPaywallData.php b/src/Modules/PaywallMode/Hooks/SaveMetaboxPaywallData.php new file mode 100644 index 0000000..f95ff73 --- /dev/null +++ b/src/Modules/PaywallMode/Hooks/SaveMetaboxPaywallData.php @@ -0,0 +1,32 @@ +hooksManager->addFilter(new AddPaywallOnPost($simPayService, $paywallModeService)); + + // Admin - Metabox + $this->hooksManager->addAction(new AddPaywallMetaboxesToPostEdit($simPayService)); + $this->hooksManager->addAction(new SaveMetaboxPaywallData()); + + // Admin - Posts listing + $this->hooksManager->addAction(new PopulatePaywallColumnsOnPostsListing($paywallModeService), 10, 2); + $this->hooksManager->addFilter(new ShowPaywallColumnOnPostsListing()); + + // Admin - Options + $this->hooksManager->addAction(new AddSubmenuToSimPayMenu($paywallModeService), 11, 2); + } +} diff --git a/src/Modules/PaywallMode/PaywallModeService.php b/src/Modules/PaywallMode/PaywallModeService.php new file mode 100644 index 0000000..bd9dc92 --- /dev/null +++ b/src/Modules/PaywallMode/PaywallModeService.php @@ -0,0 +1,77 @@ +makeWhereCondition(['post_id', $postId], ['user_id', $users], 'COUNT(*) as count'); + $result = $this->queryManager->readOne($query); + + return (int) $result?->count; + } + + private function makeWhereCondition(array $singleWhere = null, array $arrayWhere = null, string $selector = '*'): string + { + $where = ''; + $clauses = []; + if (isset($singleWhere) && $singleWhere[1] !== null) { + $clauses[] = "{$singleWhere[0]} = {$singleWhere[1]}"; + } + + if (isset($arrayWhere) && !empty($arrayWhere[1])) { + $list = join(', ', $arrayWhere[1]); + $clauses[] = "{$arrayWhere[0]} IN({$list})"; + } + + if (!empty($clauses)) { + $where = " WHERE " . join(' AND ', $clauses); + } + + return "SELECT {$selector} FROM {$this->queryManager->getDbPrefix()}simpay_wp_paywall_payments pp{$where}"; + } + + public function getPostsByUser(int $userId = null): array|null + { + $query = $this->makeWhereCondition( + ['user_id', $userId], + null, + 'pp.*, u.user_nicename, p.post_title' + ); + + return $this->queryManager->read($query . + ' LEFT JOIN wp_users u ON (u.id = pp.user_id) LEFT JOIN wp_posts p ON (p.id = pp.post_id)', + ARRAY_A + ); + } + + public function grantAccessToPost(int $userId, int $postId) + { + $this->queryManager->write( + "INSERT INTO {$this->queryManager->getDbPrefix()}simpay_wp_paywall_payments + (`post_id`, `user_id`) + VALUES ({$postId}, $userId);"); + } + + public function hasUserPaymentForPost(int $userId, int $postId): bool + { + return $this->getNumberOfPaywallPostsOfUser($userId, [$postId]) > 0; + } + + public function getNumberOfPaywallPostsOfUser($userId = null, $posts = []): int + { + $query = $this->makeWhereCondition(['user_id', $userId], ['post_id', $posts], 'COUNT(*) as count'); + $result = $this->queryManager->readOne($query); + + return (int) $result?->count; + } +} diff --git a/src/Modules/PaywallMode/Tables/PaywallPostsTable.php b/src/Modules/PaywallMode/Tables/PaywallPostsTable.php new file mode 100644 index 0000000..68106b7 --- /dev/null +++ b/src/Modules/PaywallMode/Tables/PaywallPostsTable.php @@ -0,0 +1,56 @@ +get_columns(); + $hidden = array(); + $sortable = array(); + $this->_column_headers = [$columns, $hidden, $sortable]; + + $this->items = $this->get_table_data(); + } + + public function get_columns(): array + { + return [ + 'post_title' => 'Post title', + 'user_nicename' => 'User name', + 'payment_date' => 'Date of payment', + ]; + } + + private function get_table_data() + { + return $this->paywallModeService->getPostsByUser(); + } + + public function column_default($item, $column_name) + { + return $item[$column_name]; + } + + public function column_post_title(array $item): string + { + return sprintf('%s', get_edit_post_link($item), $item['post_title']); + } + + public function column_user_nicename(array $item): string + { + return sprintf('%s', get_edit_user_link($item['user_id']), $item['user_nicename']); + } +} diff --git a/src/Modules/RegisterMode/Hooks/RegisterFormRender.php b/src/Modules/RegisterMode/Hooks/RegisterFormRender.php new file mode 100644 index 0000000..4e05bd1 --- /dev/null +++ b/src/Modules/RegisterMode/Hooks/RegisterFormRender.php @@ -0,0 +1,42 @@ +getSmsNumber((int) $simPayOptions['simpay_sms_number']); + } catch (SimPayApiInvalidCredentialsException) { + return; + } + + $view = ViewManagerFactory::create(); + $view->render('public.register.register-form', [ + 'smsNumber' => $smsNumber->getNumber(), + 'smsPrice' => $smsNumber->getPriceGross(), + 'smsCode' => $simPayService->getSmsCode()->getCode(), + ]); + } +} diff --git a/src/Modules/RegisterMode/Hooks/ValidateSmsCodeDuringRegistration.php b/src/Modules/RegisterMode/Hooks/ValidateSmsCodeDuringRegistration.php new file mode 100644 index 0000000..9b27009 --- /dev/null +++ b/src/Modules/RegisterMode/Hooks/ValidateSmsCodeDuringRegistration.php @@ -0,0 +1,62 @@ +smsNumber = (int) $simPayOptions['simpay_sms_number']; + + try { + $this->simPayService = SimPayServiceFactory::create(); + return $this->validateSmsForm($errors); + } catch (SimPayApiInvalidCredentialsException) { + return; + } + } + + /** + * @throws SimPayApiInvalidCredentialsException + */ + private function validateSmsForm(WP_Error $errors): WP_Error + { + if ($errors->has_errors()) { + // Prevent validating SMS Code when the form already has errors to don't set it as used + return $errors; + } + + if (!isset($_POST['sms_code']) || trim($_POST['sms_code']) === '') { + $errors->add('sms_code', __('Error: Enter SMS code.', 'simpay-wordpress')); + return $errors; + } + + if (!$this->simPayService->getSmsCodeValidation($_POST['sms_code'], $this->smsNumber)->isValid()) { + $errors->add('sms_code', __('Error: Invalid SMS code.', 'simpay-wordpress')); + } + + return $errors; + } +} diff --git a/src/Modules/RegisterMode/RegisterModeModule.php b/src/Modules/RegisterMode/RegisterModeModule.php new file mode 100644 index 0000000..c4e1192 --- /dev/null +++ b/src/Modules/RegisterMode/RegisterModeModule.php @@ -0,0 +1,25 @@ +hooksManager->addAction(new RegisterFormRender()); + $this->hooksManager->addFilter(new ValidateSmsCodeDuringRegistration()); + } +} diff --git a/src/PluginManagement/PluginManagerFactory.php b/src/PluginManagement/PluginManagerFactory.php new file mode 100644 index 0000000..ffac7b7 --- /dev/null +++ b/src/PluginManagement/PluginManagerFactory.php @@ -0,0 +1,13 @@ +configManager = ConfigManagerFactory::create(); + } + + public function init(): void + { + $hooksManager = HooksManagerFactory::create(); + + $modulesToLoad = $this->configManager->getConfig('plugin_config.modules'); + + $modules = new ModuleBag(); + foreach ($modulesToLoad as $module) { + $modules->add(new $module($hooksManager, $this->configManager)); + } + + $moduleManager = new ModuleLoader(); + $moduleManager->loadModules($modules); + + $hooksManager->loadHooks(); + } + + public function activatePlugin(): void + { + $databaseMigration = DatabaseMigrationFactory::create($this->configManager); + $databaseMigration->runMigration(); + } + + public function deactivatePlugin(): void + { + // TODO: Implement deactivatePlugin() method. + } +} diff --git a/src/SimPay/Dto/SmsCodeDto.php b/src/SimPay/Dto/SmsCodeDto.php new file mode 100644 index 0000000..be44e99 --- /dev/null +++ b/src/SimPay/Dto/SmsCodeDto.php @@ -0,0 +1,20 @@ +smsService->getPrefix() . "." . $this->smsService->getSuffix(); + } +} diff --git a/src/SimPay/Dto/SmsCodeValidationDto.php b/src/SimPay/Dto/SmsCodeValidationDto.php new file mode 100644 index 0000000..8a46c13 --- /dev/null +++ b/src/SimPay/Dto/SmsCodeValidationDto.php @@ -0,0 +1,84 @@ +smsCodeValidation === false) { + return null; + } + + return $this->smsCodeValidation->used; + } + + public function getCode(): ?string + { + if ($this->smsCodeValidation === false) { + return null; + } + + return $this->smsCodeValidation->code; + } + + public function isTestSms(): ?bool + { + if ($this->smsCodeValidation === false) { + return null; + } + + return $this->smsCodeValidation->test; + } + + public function getFromNumber(): ?int + { + if ($this->smsCodeValidation === false) { + return null; + } + + return $this->smsCodeValidation->from; + } + + public function getPriceNet(): ?string + { + if ($this->smsCodeValidation === false) { + return null; + } + + return $this->smsCodeValidation->value; + } + + public function isValid(): bool + { + if ($this->smsCodeValidation === false || $this->getNumber() === null) { + return false; + } + + if ($this->getNumber() === $this->validSmsNumber && $this->isUsed() === false) { + return true; + } + + return false; + } + + public function getNumber(): ?int + { + if ($this->smsCodeValidation === false) { + return null; + } + + return $this->smsCodeValidation->number; + } +} diff --git a/src/SimPay/Dto/SmsNumberDto.php b/src/SimPay/Dto/SmsNumberDto.php new file mode 100644 index 0000000..1521785 --- /dev/null +++ b/src/SimPay/Dto/SmsNumberDto.php @@ -0,0 +1,50 @@ +smsNumber === null) { + return null; + } + + return (int) $this->smsNumber->number; + } + + public function getPriceNet(): ?float + { + if ($this->smsNumber === null) { + return null; + } + + return (float) $this->smsNumber->value; + } + + public function getPriceGross(): ?float + { + if ($this->smsNumber === null) { + return null; + } + + return (float) $this->smsNumber->value_gross; + } + + public function isAdult(): ?bool + { + if ($this->smsNumber === null) { + return null; + } + + return (bool) $this->smsNumber->adult; + } +} diff --git a/src/SimPay/Dto/SmsNumbersDto.php b/src/SimPay/Dto/SmsNumbersDto.php new file mode 100644 index 0000000..11aed7c --- /dev/null +++ b/src/SimPay/Dto/SmsNumbersDto.php @@ -0,0 +1,23 @@ +phoneNumbers as $phoneNumber) { + yield new SmsNumberDto($phoneNumber); + } + } +} diff --git a/src/SimPay/Dto/SmsServiceDto.php b/src/SimPay/Dto/SmsServiceDto.php new file mode 100644 index 0000000..b3f5dc6 --- /dev/null +++ b/src/SimPay/Dto/SmsServiceDto.php @@ -0,0 +1,66 @@ +response?->id; + } + + public function getType(): ?ServiceType + { + return $this->response?->type; + } + + public function getStatus(): ?ServiceStatus + { + return $this->response?->status; + } + + public function getName(): ?string + { + return $this->response?->name; + } + + public function getPrefix(): ?string + { + return $this->response?->prefix; + } + + public function getSuffix(): ?string + { + return $this->response?->suffix; + } + + public function getDescription(): ?string + { + return $this->response?->description; + } + + public function isAdult(): ?bool + { + return $this->response?->adult; + } + + public function getCreatedAt(): ?DateTimeInterface + { + try { + return new DateTimeImmutable($this->response?->created_at); + } catch (Exception) { + return null; + } + } +} diff --git a/src/SimPay/Exception/SimPayApiInvalidCredentialsException.php b/src/SimPay/Exception/SimPayApiInvalidCredentialsException.php new file mode 100644 index 0000000..6e265df --- /dev/null +++ b/src/SimPay/Exception/SimPayApiInvalidCredentialsException.php @@ -0,0 +1,11 @@ +simPay = new SimPay($apiKey, $apiPassword); + $this->smsService = null; + $this->smsNumbers = null; + } + + /** + * @throws SimPayApiInvalidCredentialsException + */ + public function getSmsNumbers(): SmsNumbersInterface + { + if ($this->smsNumbers !== null) { + return $this->smsNumbers; + } + + $smsNumbers = $this->getApi()->getServiceNumbers($this->getSmsService()->getId()); + $this->smsNumbers = new SmsNumbersDto($smsNumbers); + + return $this->smsNumbers; + } + + private function getApi(): Sms + { + return $this->simPay->sms(); + } + + /** + * @throws SimPayApiInvalidCredentialsException + */ + public function getSmsService(): SmsServiceInterface + { + if ($this->smsService !== null) { + return $this->smsService; + } + + $smsService = $this->getApi()->getService($this->serviceId); + if ($smsService === false) { + throw new SimPayApiInvalidCredentialsException(); + } + + $this->smsService = new SmsServiceDto($smsService); + + return $this->smsService; + } + + /** + * @throws SimPayApiInvalidCredentialsException + */ + public function getSmsNumber(int $smsNumber): SmsNumberInterface + { + $smsNumber = $this->getApi()->getServiceNumber($this->getSmsService()->getId(), $smsNumber); + return new SmsNumberDto($smsNumber); + } + + /** + * @throws SimPayApiInvalidCredentialsException + */ + public function getSmsCodeValidation(string $smsCode, int $smsNumber): SmsCodeValidationInterface + { + $smsCodeValidation = $this->getApi()->getSmsCode($this->getSmsService()->getId(), $smsCode, $smsNumber); + return new SmsCodeValidationDto($smsCodeValidation, $smsNumber); + } + + /** + * @throws SimPayApiInvalidCredentialsException + */ + public function getSmsCode(): SmsCodeInterface + { + return new SmsCodeDto($this->getSmsService()); + } +} diff --git a/src/SimPay/SimPayServiceFactory.php b/src/SimPay/SimPayServiceFactory.php new file mode 100644 index 0000000..f1bd677 --- /dev/null +++ b/src/SimPay/SimPayServiceFactory.php @@ -0,0 +1,26 @@ +getFileNameFromView($viewName), $params); + } + + private function getFileNameFromView($viewName): string + { + $safeName = preg_replace('/[^A-Za-z0-9 \-\.]/', '', $viewName); + $fileNameWithoutExtension = str_replace('.', '/', $safeName); + + return SIMPAY_ABSPATH . 'view/' . $fileNameWithoutExtension . '.php'; + } +} diff --git a/src/View/ViewManagerFactory.php b/src/View/ViewManagerFactory.php new file mode 100644 index 0000000..47180fa --- /dev/null +++ b/src/View/ViewManagerFactory.php @@ -0,0 +1,13 @@ + + + + diff --git a/view/admin/settings/partials/field-checkbox.php b/view/admin/settings/partials/field-checkbox.php new file mode 100644 index 0000000..c632c5d --- /dev/null +++ b/view/admin/settings/partials/field-checkbox.php @@ -0,0 +1,2 @@ +> diff --git a/view/admin/settings/partials/field-input.php b/view/admin/settings/partials/field-input.php new file mode 100644 index 0000000..45c99fb --- /dev/null +++ b/view/admin/settings/partials/field-input.php @@ -0,0 +1,12 @@ + 'text', + 'value' => '', + 'name' => '', + 'placeholder' => '', + ]; + + $args = array_merge($defaultArgs, $args); +?> + + diff --git a/view/admin/settings/partials/field-select.php b/view/admin/settings/partials/field-select.php new file mode 100644 index 0000000..520d0e9 --- /dev/null +++ b/view/admin/settings/partials/field-select.php @@ -0,0 +1,25 @@ + diff --git a/view/admin/settings/partials/section-heading.php b/view/admin/settings/partials/section-heading.php new file mode 100644 index 0000000..70fccc2 --- /dev/null +++ b/view/admin/settings/partials/section-heading.php @@ -0,0 +1 @@ +

diff --git a/view/admin/settings/partials/table-form.php b/view/admin/settings/partials/table-form.php new file mode 100644 index 0000000..b8bee22 --- /dev/null +++ b/view/admin/settings/partials/table-form.php @@ -0,0 +1,12 @@ + + + $element): ?> + + + + + + + diff --git a/view/admin/settings/settings-page.php b/view/admin/settings/settings-page.php new file mode 100644 index 0000000..3b7f7a8 --- /dev/null +++ b/view/admin/settings/settings-page.php @@ -0,0 +1,10 @@ +
+

+
+ +
+
diff --git a/view/public/paywall/access-denied-alert.php b/view/public/paywall/access-denied-alert.php new file mode 100644 index 0000000..b041666 --- /dev/null +++ b/view/public/paywall/access-denied-alert.php @@ -0,0 +1,12 @@ +
+

Dziękujemy za zainteresowanie!

+

Dostęp do treści na tej stronie jest zarezerwowany tylko dla płatnych użytkowników.

+ +

+ +

+ + +

Musisz być zalogowanym użytkownikiem. Kliknij tutaj, aby się zalogować.

+ +
diff --git a/view/public/paywall/payment-form.php b/view/public/paywall/payment-form.php new file mode 100644 index 0000000..48bd061 --- /dev/null +++ b/view/public/paywall/payment-form.php @@ -0,0 +1,10 @@ +
+

+ Aby uzyskać dostęp, wyślij SMS na numer o treści . Koszt SMS to zł (brutto) +

+
+ + + +
+
diff --git a/view/public/paywall/successful-payment.php b/view/public/paywall/successful-payment.php new file mode 100644 index 0000000..2ed0c51 --- /dev/null +++ b/view/public/paywall/successful-payment.php @@ -0,0 +1,4 @@ +
+

Dostęp przyznany!

+

Dziękujemy za płatność. Klinij tutaj, aby uzyskać dostęp do treści.

+
diff --git a/view/public/register/register-form.php b/view/public/register/register-form.php new file mode 100644 index 0000000..a14a437 --- /dev/null +++ b/view/public/register/register-form.php @@ -0,0 +1,10 @@ +

+ Aby się zarejestrować, wyślij SMS
na numer
+ o treści .
+ Koszt SMS to zł (brutto) +

+
+

+ + +