From 93a4ea7cc1832425fe876066fdccc7599cc3ae32 Mon Sep 17 00:00:00 2001 From: Halil Beycan <50718965+BeycanDeveloper@users.noreply.github.com> Date: Wed, 6 Mar 2024 22:44:27 +0800 Subject: [PATCH] updated integrator --- composer.json | 2 +- composer.lock | 14 +-- .../cryptopay-integrator/composer.json | 2 +- .../cryptopay-integrator/phpcs.xml | 3 + .../cryptopay-integrator/src/Helpers.php | 81 +++++++++++++++++ .../cryptopay-integrator/src/Session.php | 91 +++++++++++++++++++ .../cryptopay-integrator/src/Type.php | 11 +++ .../cryptopay-integrator/views/pay.php | 89 ++++++++++++++++++ vendor/composer/installed.json | 14 +-- vendor/composer/installed.php | 10 +- 10 files changed, 296 insertions(+), 21 deletions(-) create mode 100644 vendor/beycanpress/cryptopay-integrator/src/Session.php create mode 100644 vendor/beycanpress/cryptopay-integrator/src/Type.php create mode 100644 vendor/beycanpress/cryptopay-integrator/views/pay.php diff --git a/composer.json b/composer.json index f6e8498..c666576 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,6 @@ } }, "require": { - "beycanpress/cryptopay-integrator": "^0.1.3" + "beycanpress/cryptopay-integrator": "^0.1.5" } } diff --git a/composer.lock b/composer.lock index 119a020..4034c88 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f99ffda5f6e370daee8d691b9e8af453", + "content-hash": "1fe4f2337dedacb4e5c49da7935e6767", "packages": [ { "name": "beycanpress/cryptopay-integrator", - "version": "0.1.3", + "version": "0.1.5", "source": { "type": "git", "url": "https://github.com/BeycanPress/cryptopay-integrator.git", - "reference": "3a22611e6bdc1c5655b4241d300197cdbcd71cb7" + "reference": "3e09b41450580cf9591b52f9e4f73bbce0970637" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/BeycanPress/cryptopay-integrator/zipball/3a22611e6bdc1c5655b4241d300197cdbcd71cb7", - "reference": "3a22611e6bdc1c5655b4241d300197cdbcd71cb7", + "url": "https://api.github.com/repos/BeycanPress/cryptopay-integrator/zipball/3e09b41450580cf9591b52f9e4f73bbce0970637", + "reference": "3e09b41450580cf9591b52f9e4f73bbce0970637", "shasum": "" }, "require": { @@ -37,9 +37,9 @@ "homepage": "https://github.com/BeycanPress/cryptopay-integrator", "support": { "issues": "https://github.com/BeycanPress/cryptopay-integrator/issues", - "source": "https://github.com/BeycanPress/cryptopay-integrator/tree/0.1.3" + "source": "https://github.com/BeycanPress/cryptopay-integrator/tree/0.1.5" }, - "time": "2024-02-29T03:30:28+00:00" + "time": "2024-03-06T14:42:16+00:00" } ], "packages-dev": [], diff --git a/vendor/beycanpress/cryptopay-integrator/composer.json b/vendor/beycanpress/cryptopay-integrator/composer.json index cee4811..d47b670 100644 --- a/vendor/beycanpress/cryptopay-integrator/composer.json +++ b/vendor/beycanpress/cryptopay-integrator/composer.json @@ -1,6 +1,6 @@ { "name": "beycanpress/cryptopay-integrator", - "version": "0.1.3", + "version": "0.1.5", "description": "CryptoPay and CryptoPay Lite integration wrapper", "type": "library", "license": "MIT", diff --git a/vendor/beycanpress/cryptopay-integrator/phpcs.xml b/vendor/beycanpress/cryptopay-integrator/phpcs.xml index 4c6648b..f44524d 100644 --- a/vendor/beycanpress/cryptopay-integrator/phpcs.xml +++ b/vendor/beycanpress/cryptopay-integrator/phpcs.xml @@ -5,15 +5,18 @@ BeycanPressStandard ./**/*.php + */views/* + + diff --git a/vendor/beycanpress/cryptopay-integrator/src/Helpers.php b/vendor/beycanpress/cryptopay-integrator/src/Helpers.php index 9b98793..46137bd 100644 --- a/vendor/beycanpress/cryptopay-integrator/src/Helpers.php +++ b/vendor/beycanpress/cryptopay-integrator/src/Helpers.php @@ -5,14 +5,18 @@ namespace BeycanPress\CryptoPay\Integrator; use BeycanPress\CryptoPay\Loader; +use BeycanPress\CryptoPay\Payment; use BeycanPress\CryptoPay\PluginHero\Hook; use BeycanPress\CryptoPay\Helpers as ProHelpers; use BeycanPress\CryptoPay\Pages\TransactionPage; +use BeycanPress\CryptoPay\Types\Order\OrderType; use BeycanPress\CryptoPay\PluginHero\Http\Response; // Lite use BeycanPress\CryptoPayLite\Loader as LiteLoader; +use BeycanPress\CryptoPayLite\Payment as LitePayment; use BeycanPress\CryptoPayLite\Helpers as LiteHelpers; use BeycanPress\CryptoPayLite\PluginHero\Hook as LiteHook; +use BeycanPress\CryptoPayLite\Types\Order\OrderType as LiteOrderType; use BeycanPress\CryptoPayLite\PluginHero\Http\Response as LiteResponse; use BeycanPress\CryptoPayLite\Pages\TransactionPage as LiteTransactionPage; @@ -136,4 +140,81 @@ public static function response(string $method, ...$args): mixed return LiteResponse::$method(...$args); } } + + /** + * @param array $data + * @return string + * @throws \Exception + */ + public static function createSPP(array $data): string + { + if (!isset($data['addon'])) { + throw new \Exception('Addon is required'); + } + + if (!isset($data['order'])) { + throw new \Exception('Order is required'); + } + + if (!isset($data['order']['amount'])) { + throw new \Exception('Order amount is required'); + } + + if (!isset($data['order']['currency'])) { + throw new \Exception('Order currency is required'); + } + + if (!isset($data['type'])) { + throw new \Exception('CryptoPay type is required'); + } + + if (!($data['type'] instanceof Type)) { + throw new \Exception('Invalid CryptoPay type'); + } + + $token = md5(json_encode($data) . time()); + + Session::set($token, $data); + + return home_url("/?cp_spp={$token}"); + } + + /** + * @return void + */ + public static function listenSPP(): void + { + $token = isset($_GET['cp_spp']) ? sanitize_text_field($_GET['cp_spp']) : null; + + if ($token && Session::has($token)) { + extract(Session::get($token)); + if (Type::PRO === $type) { + $cryptopay = self::createProPayment($addon, (array) $order); + } else { + $cryptopay = self::createLitePayment($addon, (array) $order); + } + require dirname(__DIR__) . '/views/pay.php'; + exit; + } + } + + /** + * @param string $addon + * @param array $order + * @return string + */ + public static function createProPayment(string $addon, array $order): string + { + return (new Payment($addon))->setOrder(OrderType::fromArray($order))->html(loading:true); + } + + /** + * @param string $addon + * @param array $order + * @return string + */ + public static function createLitePayment(string $addon, array $order): string + { + return (new LitePayment($addon))->setOrder(LiteOrderType::fromArray($order))->html(loading:true); + } } diff --git a/vendor/beycanpress/cryptopay-integrator/src/Session.php b/vendor/beycanpress/cryptopay-integrator/src/Session.php new file mode 100644 index 0000000..b2f3db3 --- /dev/null +++ b/vendor/beycanpress/cryptopay-integrator/src/Session.php @@ -0,0 +1,91 @@ + + + + + + + <?php echo esc_html__('CryptoPay Single Page Payment') ?> + + + +
+
+

+ +

:

+ + +

:

+ + +

:

+ +

+ +

+
+
+ +
+
+ + + \ No newline at end of file diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 647a9c9..930c055 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -2,23 +2,23 @@ "packages": [ { "name": "beycanpress/cryptopay-integrator", - "version": "0.1.3", - "version_normalized": "0.1.3.0", + "version": "0.1.5", + "version_normalized": "0.1.5.0", "source": { "type": "git", "url": "https://github.com/BeycanPress/cryptopay-integrator.git", - "reference": "3a22611e6bdc1c5655b4241d300197cdbcd71cb7" + "reference": "3e09b41450580cf9591b52f9e4f73bbce0970637" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/BeycanPress/cryptopay-integrator/zipball/3a22611e6bdc1c5655b4241d300197cdbcd71cb7", - "reference": "3a22611e6bdc1c5655b4241d300197cdbcd71cb7", + "url": "https://api.github.com/repos/BeycanPress/cryptopay-integrator/zipball/3e09b41450580cf9591b52f9e4f73bbce0970637", + "reference": "3e09b41450580cf9591b52f9e4f73bbce0970637", "shasum": "" }, "require": { "php": ">=8.1" }, - "time": "2024-02-29T03:30:28+00:00", + "time": "2024-03-06T14:42:16+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -34,7 +34,7 @@ "homepage": "https://github.com/BeycanPress/cryptopay-integrator", "support": { "issues": "https://github.com/BeycanPress/cryptopay-integrator/issues", - "source": "https://github.com/BeycanPress/cryptopay-integrator/tree/0.1.3" + "source": "https://github.com/BeycanPress/cryptopay-integrator/tree/0.1.5" }, "install-path": "../beycanpress/cryptopay-integrator" } diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 8fb6649..a946e16 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => '__root__', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '46ce28210b987ff83dafb47a621676fd873c6f6f', + 'reference' => 'bda9afa32f7c3a6a8540fe07d79c350489225a75', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -13,16 +13,16 @@ '__root__' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '46ce28210b987ff83dafb47a621676fd873c6f6f', + 'reference' => 'bda9afa32f7c3a6a8540fe07d79c350489225a75', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), 'dev_requirement' => false, ), 'beycanpress/cryptopay-integrator' => array( - 'pretty_version' => '0.1.3', - 'version' => '0.1.3.0', - 'reference' => '3a22611e6bdc1c5655b4241d300197cdbcd71cb7', + 'pretty_version' => '0.1.5', + 'version' => '0.1.5.0', + 'reference' => '3e09b41450580cf9591b52f9e4f73bbce0970637', 'type' => 'library', 'install_path' => __DIR__ . '/../beycanpress/cryptopay-integrator', 'aliases' => array(),