-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
2,213 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BeycanPress\CryptoPay\MyCred; | ||
|
||
// 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 | ||
|
||
use BeycanPress\CryptoPay\Payment; | ||
use BeycanPress\CryptoPay\Integrator\Helpers; | ||
use BeycanPress\CryptoPayLite\Payment as PaymentLite; | ||
use BeycanPress\CryptoPay\Types\Order\OrderType; | ||
use BeycanPress\CryptoPay\Types\Transaction\ParamsType; | ||
use BeycanPress\CryptoPayLite\Types\Order\OrderType as LiteOrderType; | ||
use BeycanPress\CryptoPayLite\Types\Transaction\ParamsType as LiteParamsType; | ||
|
||
class Gateway extends \myCRED_Payment_Gateway | ||
{ | ||
/** | ||
* @var mixed | ||
*/ | ||
public $prefs; | ||
|
||
/** | ||
* @var int|float | ||
*/ | ||
public $cost; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $post_id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $transaction_id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $currency; | ||
|
||
/** | ||
* @param mixed $prefs | ||
* Gateway constructor. | ||
*/ | ||
public function __construct($prefs) | ||
{ | ||
$types = mycred_get_types(); | ||
$defaultExchange = []; | ||
|
||
foreach ($types as $type => $label) { | ||
$defaultExchange[$type] = 1; | ||
} | ||
|
||
parent::__construct([ | ||
'id' => 'cryptopay', | ||
'label' => Helpers::exists() ? 'CryptoPay' : 'CryptoPay Lite', | ||
'gateway_logo_url' => MYCRED_CRYPTOPAY_URL . 'assets/images/icon.png', | ||
'defaults' => [ | ||
'theme' => 'light', | ||
'currency' => 'USD', | ||
'exchange' => $defaultExchange | ||
] | ||
], $prefs); | ||
} | ||
|
||
/** | ||
* Preferences (settings) | ||
* @return void | ||
*/ | ||
public function preferences(): void | ||
{ | ||
include MYCRED_CRYPTOPAY_DIR . 'views/preferences.php'; | ||
} | ||
|
||
/** | ||
* Sanitise preferences | ||
* @param array<mixed> $data | ||
* @return array<mixed> | ||
*/ | ||
public function sanitise_preferences($data): array | ||
{ | ||
$newData = []; | ||
|
||
$newData['theme'] = sanitize_text_field($data['theme']); | ||
$newData['currency'] = sanitize_text_field($data['currency']); | ||
|
||
// If exchange is less then 1 we must start with a zero | ||
if (isset($data['exchange'])) { | ||
foreach ((array) $data['exchange'] as $type => $rate) { | ||
if (1 != $rate && in_array(substr($rate, 0, 1), ['.', ','])) { | ||
$data['exchange'][$type] = (float) '0' . $rate; | ||
} | ||
} | ||
} | ||
|
||
$newData['exchange'] = $data['exchange']; | ||
|
||
return $newData; | ||
} | ||
|
||
/** | ||
* Payment form frontend side | ||
* @return void | ||
*/ | ||
public function checkout_page_body(): void | ||
{ | ||
echo wp_kses_post($this->checkout_header()); | ||
echo wp_kses_post($this->checkout_order()); | ||
|
||
$order = [ | ||
'id' => $this->post_id, | ||
'amount' => floatval($this->cost), | ||
'currency' => ($this->prefs['currency'] ?? $this->currency) ?? 'USD', | ||
]; | ||
|
||
$params = [ | ||
'transactionId' => $this->transaction_id | ||
]; | ||
|
||
if (Helpers::exists()) { | ||
$cp = (new Payment('mycred')) | ||
->setOrder(OrderType::fromArray($order)) | ||
->setParams(ParamsType::fromArray($params)); | ||
} else { | ||
$cp = (new PaymentLite('mycred')) | ||
->setOrder(LiteOrderType::fromArray($order)) | ||
->setParams(LiteParamsType::fromArray($params)); | ||
} | ||
|
||
echo Helpers::run('ksesEcho', $cp->html(loading: true)); | ||
|
||
echo wp_kses_post($this->checkout_cancel()); | ||
} | ||
|
||
/** | ||
* Ajax buy process | ||
* @return void | ||
*/ | ||
public function ajax_buy(): void | ||
{ | ||
$this->send_json(esc_html__('This gateway does not support AJAX payments.', 'mycred-cryptopay')); | ||
} | ||
|
||
/** | ||
* Payment request process | ||
* @return void | ||
*/ | ||
public function buy(): void | ||
{ | ||
// Buy | ||
} | ||
|
||
/** | ||
* Payment return process | ||
* @return void | ||
*/ | ||
public function process(): void | ||
{ | ||
// Process payment | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ComposerAutoloaderInit623994210b0626aad6edc565f7c7bab2::getLoader(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# CryptoPay Integrator Wrapper | ||
|
||
```bash | ||
composer require beycanpress/cryptopay-integrator | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
Oops, something went wrong.