Skip to content

Commit

Permalink
updated integrator
Browse files Browse the repository at this point in the history
  • Loading branch information
0xBeycan committed Mar 6, 2024
1 parent d582f99 commit 1ebb64a
Show file tree
Hide file tree
Showing 23 changed files with 1,801 additions and 0 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"phpcs": "phpcs --standard=phpcs.xml .",
"phpcbf": "phpcbf --standard=phpcs.xml .",
"install-phpcs": "composer config --global --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true && composer global require --dev squizlabs/php_codesniffer=* slevomat/coding-standard"
},
"require": {
"beycanpress/cryptopay-integrator": "^0.1.5"
}
}
54 changes: 54 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

// autoload.php @generated by Composer

if (PHP_VERSION_ID < 50600) {
if (!headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
if (!ini_get('display_errors')) {
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
fwrite(STDERR, $err);
} elseif (!headers_sent()) {
echo $err;
}
}
trigger_error(
$err,
E_USER_ERROR
);
}

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit6be0de7c2c544c6b51cbdeae0bbe23be::getLoader();
1 change: 1 addition & 0 deletions vendor/beycanpress/cryptopay-integrator/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
5 changes: 5 additions & 0 deletions vendor/beycanpress/cryptopay-integrator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# CryptoPay Integrator Wrapper

```bash
composer require beycanpress/cryptopay-integrator
```
25 changes: 25 additions & 0 deletions vendor/beycanpress/cryptopay-integrator/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "beycanpress/cryptopay-integrator",
"version": "0.1.5",
"description": "CryptoPay and CryptoPay Lite integration wrapper",
"type": "library",
"license": "MIT",
"author": "BeycanPress",
"support": {
"issues": "https://github.com/BeycanPress/cryptopay-integrator/issues"
},
"homepage": "https://github.com/BeycanPress/cryptopay-integrator",
"require": {
"php": ">=8.1"
},
"scripts": {
"phpcs": "phpcs --standard=phpcs.xml .",
"phpcbf": "phpcbf --standard=phpcs.xml .",
"install-phpcs": "composer config --global --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true && composer global require --dev squizlabs/php_codesniffer=* slevomat/coding-standard"
},
"autoload": {
"psr-4": {
"BeycanPress\\CryptoPay\\Integrator\\": "src"
}
}
}
34 changes: 34 additions & 0 deletions vendor/beycanpress/cryptopay-integrator/phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<ruleset name="BeycanPressStandard">
<rule ref="PSR12"/>
<description>
BeycanPressStandard
</description>
<file>./**/*.php</file>
<exclude-pattern>*/views/*</exclude-pattern>
<arg name="extensions" value="php"/>
<arg name="standard" value="PSR12"/>
<rule ref="Generic.Files.InlineHTML"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Squiz.Commenting.FunctionComment.Missing"/>
<rule ref="Squiz.Commenting.FunctionComment.MissingParamTag"/>
<rule ref="Squiz.Commenting.FunctionComment.MissingParamName"/>
<rule ref="Squiz.Commenting.FunctionComment.ParamNameNoMatch"/>
<rule ref="Squiz.Commenting.FunctionComment.IncorrectTypeHint"/>
<rule ref="Squiz.Commenting.FunctionComment.MissingReturn"/>
<rule ref="SlevomatCodingStandard.ControlStructures.RequireYodaComparison"/>
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.IncorrectStrictTypesFormat" />
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.UselessAnnotation" />
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.UselessAnnotation" />
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.UselessAnnotation" />
</rule>
<rule ref="SlevomatCodingStandard.Commenting.EmptyComment"/>
<rule ref="SlevomatCodingStandard.Commenting.AnnotationName"/>
</ruleset>
220 changes: 220 additions & 0 deletions vendor/beycanpress/cryptopay-integrator/src/Helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
<?php

declare(strict_types=1);

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;

class Helpers
{
/**
* @return bool
*/
public static function bothExists(): bool
{
return static::exists() || static::liteExists();
}

/**
* @return bool
*/
public static function liteExists(): bool
{
return class_exists(LiteLoader::class);
}

/**
* @return bool
*/
public static function exists(): bool
{
return class_exists(Loader::class);
}

/**
* @param string $addon
* @return void
*/
public static function registerIntegration(string $addon): void
{
if (self::exists()) {
ProHelpers::registerIntegration($addon);
}

if (self::liteExists()) {
LiteHelpers::registerIntegration($addon);
}
}

/**
* @param array<mixed> ...$args
* @return void
*/
// phpcs:ignore
public static function createTransactionPage(...$args): void
{
if (is_admin()) {
if (self::exists()) {
new TransactionPage(...$args);
}

if (self::liteExists()) {
new LiteTransactionPage(...$args);
}
}
}

/**
* @param string $modelClass
* @return void
*/
public static function registerModel(string $modelClass): void
{
if (self::exists() && class_exists($modelClass)) {
$model = new $modelClass();
Hook::addFilter('models', function (array $models) use ($model): array {
return array_merge($models, [
$model->addon => $model
]);
});
}
}

/**
* @param string $modelClass
* @return void
*/
public static function registerLiteModel(string $modelClass): void
{
if (self::liteExists() && class_exists($modelClass)) {
$model = new $modelClass();
LiteHook::addFilter('models', function (array $models) use ($model): array {
return array_merge($models, [
$model->addon => $model
]);
});
}
}

/**
* @param string $method
* @param array<mixed> ...$args
* @return mixed
*/
// phpcs:ignore
public static function run(string $method, ...$args): mixed
{
if (self::exists()) {
return ProHelpers::$method(...$args);
} else {
return LiteHelpers::$method(...$args);
}
}

/**
* @param string $method
* @param array<mixed> ...$args
* @return mixed
*/
// phpcs:ignore
public static function response(string $method, ...$args): mixed
{
if (self::exists()) {
return Response::$method(...$args);
} else {
return LiteResponse::$method(...$args);
}
}

/**
* @param array<mixed> $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<mixed> $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<mixed> $order
* @return string
*/
public static function createLitePayment(string $addon, array $order): string
{
return (new LitePayment($addon))->setOrder(LiteOrderType::fromArray($order))->html(loading:true);
}
}
Loading

0 comments on commit 1ebb64a

Please sign in to comment.