Skip to content

Commit

Permalink
waiting response from wpmudev team
Browse files Browse the repository at this point in the history
  • Loading branch information
BeycanDeveloper committed Mar 26, 2024
1 parent 435f461 commit 9eef93a
Show file tree
Hide file tree
Showing 31 changed files with 2,131 additions and 7 deletions.
153 changes: 153 additions & 0 deletions app/Field.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?php

declare(strict_types=1);

namespace BeycanPress\CryptoPay\Forminator;

// phpcs:disable PSR1.Methods.CamelCapsMethodName
// phpcs:disable Squiz.NamingConventions.ValidVariableName
// phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
// phpcs:disable SlevomatCodingStandard.TypeHints.PropertyTypeHint
// phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint

class Field extends \Forminator_Field
{
/**
* @var string
*/
public $name = 'CryptoPay';

/**
* @var string
*/
public $slug = 'cryptopay';

/**
* @var string
*/
public $type = 'cryptopay';

/**
* @var int
*/
public $position = 24;

/**
* @var array<mixed>
*/
public $options = [];

/**
* @var string
*/
public $category = 'standard';

/**
* @var string
*/
public $icon = 'sui-icon cryptopay-icon';

/**
* @var array<mixed>
*/
public $field;

/**
* @var array<mixed>
*/
public $form_settings;


/**
* Gateway constructor.
*/
public function __construct()
{
parent::__construct();
add_action('admin_enqueue_scripts', [$this, 'adminScripts']);
}

/**
* @return void
*/
public function adminScripts(): void
{
wp_enqueue_style(
'forminator-cryptopay',
FORMINATOR_CRYPTOPAY_URL . 'assets/css/main.css',
[],
FORMINATOR_CRYPTOPAY_VERSION
);

wp_enqueue_script(
'forminator-cryptopay',
FORMINATOR_CRYPTOPAY_URL . 'assets/js/admin.js',
[],
FORMINATOR_CRYPTOPAY_VERSION,
true
);
}

/**
* @return array<mixed>
*/
public function defaults(): array
{
$currency = 'USD';
try {
// gateway
} catch (\Exception $e) {
forminator_maybe_log(__METHOD__, $e->getMessage());
}

return [
'currency' => $currency,
'amount_type' => 'fixed',
'options' => []
];
}

/**
* Front-end markup
* @param array<mixed> $field
* @param \Forminator_Render_Form $views_obj Forminator_Render_Form object.
* @return string
*/
public function markup($field, $views_obj): string
{

$this->field = $field;
$this->form_settings = $views_obj->model->settings;

$elementName = self::get_property('element_id', $field);
$fieldId = $elementName . '-field';
$amount = self::get_property('amount', $field, '0');
$amountVariable = self::get_property('variable', $field, '');
$amountType = self::get_property('amount_type', $field, 'fixed');
$currency = self::get_property('currency', $field, $this->getDefaultCurrency());

$attr = [
'type' => 'hidden',
'name' => $elementName,
'id' => 'forminator-' . $fieldId,
'class' => 'forminator-cryptopay-input',
'data-is-payment' => 'true',
'data-payment-type' => $this->type,
'data-amount-type' => esc_html($amountType),
'data-currency' => esc_html(strtolower($currency)),
'data-amount' => ('fixed' === $amountType ? esc_html($amount) : $amountVariable),
];

$html = self::create_input($attr);

return apply_filters('forminator_field_cryptopay_markup', $html, $attr, $field);
}

/**
* @return string
*/
public function getDefaultCurrency(): string
{
return 'USD';
}
}
15 changes: 15 additions & 0 deletions app/Gateway.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace BeycanPress\CryptoPay\Forminator;

class Gateway extends \Forminator_Payment_Gateway
{
/**
* Gateway constructor.
*/
public function __construct()
{
}
}
12 changes: 12 additions & 0 deletions app/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,17 @@ class Loader
*/
public function __construct()
{
add_filter('forminator_fields', [$this, 'registerField']);
}

/**
* @param array<mixed> $fields
* @return array<mixed>
*/
public function registerField(array $fields): array
{
return array_merge($fields, [
new Field()
]);
}
}
3 changes: 3 additions & 0 deletions assets/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.cryptopay-icon {
content: url(../images/icon.svg);
}
2 changes: 2 additions & 0 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
;(() => {
})()
Empty file removed assets/js/main.js
Empty file.
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.

16 changes: 9 additions & 7 deletions forminator-cryptopay-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@

load_plugin_textdomain('forminator-cryptopay', false, basename(__DIR__) . '/languages');

if (!defined('GF_MIN_WP_VERSION') /* TODO: check the plugin */) {
Helpers::requirePluginMessage('Forminator', 'https://wordpress.org/plugins/forminator/');
} elseif (Helpers::bothExists()) {
new BeycanPress\CryptoPay\Forminator\Loader();
} else {
Helpers::requireCryptoPayMessage('Forminator');
}
add_action('plugins_loaded', function (): void {
if (!defined('FORMINATOR_PLUGIN_BASENAME')) {
Helpers::requirePluginMessage('Forminator', 'https://wordpress.org/plugins/forminator/');
} elseif (Helpers::bothExists()) {
new BeycanPress\CryptoPay\Forminator\Loader();
} else {
Helpers::requireCryptoPayMessage('Forminator');
}
});
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 ComposerAutoloaderInitb035a5ad621c56f0f4eca9f034b92c9e::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.10",
"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"
}
}
}
38 changes: 38 additions & 0 deletions vendor/beycanpress/cryptopay-integrator/phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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="Squiz.NamingConventions.ValidVariableName"/>
<rule ref="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore">
<severity>0</severity>
</rule>
<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>
Loading

0 comments on commit 9eef93a

Please sign in to comment.