Skip to content

Commit

Permalink
phpcs configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
0xBeycan committed Jan 24, 2024
1 parent dcd268b commit 59837dc
Show file tree
Hide file tree
Showing 13 changed files with 441 additions and 279 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
34 changes: 34 additions & 0 deletions .github/workflows/phpcs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: PHPCS Check

on:
push:
branches:
- master

jobs:
phpcs:
name: PHPCS Check
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'

- name: Install PHPCS
run: |
composer config --global --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer require --dev squizlabs/php_codesniffer=* slevomat/coding-standard
- name: Run PHPCS
run: |
composer phpcs --standard=phpcs.xml .
exit_status=$?
if [ $exit_status -ne 0 ]; then
echo "PHPCS check failed. Please fix the issues before merging."
exit 1
fi
37 changes: 26 additions & 11 deletions classes/class.pmpro_ajax_api.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
<?php

use \BeycanPress\Http\Request;
use \BeycanPress\Http\Response;
declare(strict_types=1);

// @phpcs:disable PSR1.Files.SideEffects
// @phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps

use BeycanPress\Http\Request;
use BeycanPress\Http\Response;

// @phpcs:ignore
class PMPro_Ajax_Api
{
/**
* @return void
*/
public function __construct()
{
add_action('wp_ajax_pmpro_cryptopay_use_discount' , [$this, 'pmpro_cryptopay_use_discount']);
add_action('wp_ajax_nopriv_pmpro_cryptopay_use_discount' , [$this, 'pmpro_cryptopay_use_discount']);
add_action('wp_ajax_pmpro_cryptopay_use_discount', [$this, 'pmpro_cryptopay_use_discount']);
add_action('wp_ajax_nopriv_pmpro_cryptopay_use_discount', [$this, 'pmpro_cryptopay_use_discount']);
}

/**
* @return void
*/
public function pmpro_cryptopay_use_discount() : void
public function pmpro_cryptopay_use_discount(): void
{
global $pmpro_levels;
global $pmpro_levels;

check_ajax_referer('pmpro_cryptopay_use_discount', 'nonce');

$request = new Request();
Expand All @@ -26,22 +35,28 @@ public function pmpro_cryptopay_use_discount() : void

if (!isset($pmpro_levels[$levelId])) {
Response::error(esc_html__('Invalid level id!', 'pmpro-cryptopay'));
}
}

$codeCheck = pmpro_checkDiscountCode($discountCode, $levelId, true);
if ($codeCheck[0] == false) {
Response::error(esc_html__('Invalid discount code!', 'pmpro-cryptopay'));
}

global $wpdb;
$discountId = $wpdb->get_var("SELECT id FROM $wpdb->pmpro_discount_codes WHERE code = '" . esc_sql($discountCode) . "' LIMIT 1");
$discountId = $wpdb->get_var(
"SELECT id FROM $wpdb->pmpro_discount_codes WHERE code = '" . esc_sql($discountCode) . "' LIMIT 1"
);

$discountPrice = $wpdb->get_var("SELECT initial_payment FROM $wpdb->pmpro_discount_codes_levels WHERE code_id = '" . esc_sql($discountId) . "' LIMIT 1");
$discountPrice = $wpdb->get_var(
"SELECT initial_payment
FROM $wpdb->pmpro_discount_codes_levels
WHERE code_id = '" . esc_sql($discountId) . "' LIMIT 1"
);

Response::success(null, [
'amount' => floatval($discountPrice),
]);
}
}

new PMPro_Ajax_Api();
new PMPro_Ajax_Api();
77 changes: 46 additions & 31 deletions classes/lite/class.pmpro_register_hooks.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@
<?php

use \BeycanPress\CryptoPayLite\Loader;
use \BeycanPress\CryptoPayLite\Services;
use \BeycanPress\CryptoPayLite\PluginHero\Hook;
use \BeycanPress\CryptoPayLite\Pages\TransactionPage;
declare(strict_types=1);

// @phpcs:disable PSR1.Files.SideEffects
// @phpcs:disable Generic.Files.LineLength
// @phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps

use BeycanPress\CryptoPayLite\Loader;
use BeycanPress\CryptoPayLite\Services;
use BeycanPress\CryptoPayLite\PluginHero\Hook;
use BeycanPress\CryptoPayLite\Pages\TransactionPage;

// @phpcs:ignore
class PMPro_Register_Hooks_Lite
{
/**
* @return void
*/
public function __construct()
{
if (class_exists(Loader::class)) {

Services::registerAddon('pmpro_lite');

if (is_admin()) {
new TransactionPage(
esc_html__('PMPro transactions', 'cryptopay'),
'pmpro_lite',
9,
[
'orderId' => function($tx) {
'orderId' => function ($tx) {
return '<a href="' . admin_url('admin.php?page=pmpro-orders&order=' . $tx->orderId) . '">' . $tx->orderId . '</a>';
}
],
true,
['updatedAt']
);
}
Hook::addFilter('init_pmpro_lite', function(object $data) {

Hook::addFilter('init_pmpro_lite', function (object $data) {
global $pmpro_levels;

if (!isset($pmpro_levels[$data->params->pmpro->levelId])) {
Expand All @@ -38,7 +47,13 @@ public function __construct()
return $data;
});

function pmpro_check_discount_code_lite(object $order, object &$level) {
/**
* @param object $order
* @param object $level
* @return void
*/
function pmpro_check_discount_code_lite(object $order, object &$level): void
{
global $wpdb;
if (isset($order->discountCode)) {
$codeCheck = pmpro_checkDiscountCode($order->discountCode, $level->id, true);
Expand All @@ -56,18 +71,18 @@ function pmpro_check_discount_code_lite(object $order, object &$level) {
}
}

Hook::addAction('payment_started_pmpro_lite', function(object $data) {
Hook::addAction('payment_started_pmpro_lite', function (object $data): void {
global $pmpro_levels;
$currentUser = wp_get_current_user();

$order = new \MemberOrder();
$level = $pmpro_levels[$data->params->pmpro->levelId];
pmpro_check_discount_code_lite($data->order, $level);

if(empty($order->code)) {
if (empty($order->code)) {
$order->code = $order->getRandomCode();
}

// Set order values.
$order->membership_id = $level->id;
$order->membership_name = $level->name;
Expand Down Expand Up @@ -122,14 +137,14 @@ function pmpro_check_discount_code_lite(object $order, object &$level) {
$data->model->update(['orderId' => $order->id], ['hash' => $data->hash]);
});

Hook::addAction('payment_finished_pmpro_lite', function(object $data) {
Hook::addAction('payment_finished_pmpro_lite', function (object $data): void {
global $pmpro_levels, $wpdb;

$orderId = ($data->model->findOneBy(['hash' => $data->hash]))->orderId;
$order = new \MemberOrder($orderId);
if (!$order->id) {
return;
}
if (!$order->id) {
return;
}

if (!$data->status) {
$order->status = "error";
Expand All @@ -140,12 +155,12 @@ function pmpro_check_discount_code_lite(object $order, object &$level) {
$level = $pmpro_levels[$data->params->pmpro->levelId];
pmpro_check_discount_code_lite($data->order, $level);

$startdate = current_time( "mysql" );
$startdate = current_time("mysql");
if (!empty($level->expiration_number)) {
if( $level->expiration_period == 'Hour' ){
$enddate = date( "Y-m-d H:i:s", strtotime( "+ " . $level->expiration_number . " " . $level->expiration_period, current_time( "timestamp" ) ) );
if ($level->expiration_period == 'Hour') {
$enddate = date("Y-m-d H:i:s", strtotime("+ " . $level->expiration_number . " " . $level->expiration_period, current_time("timestamp")));
} else {
$enddate = date( "Y-m-d 23:59:59", strtotime( "+ " . $level->expiration_number . " " . $level->expiration_period, current_time( "timestamp" ) ) );
$enddate = date("Y-m-d 23:59:59", strtotime("+ " . $level->expiration_number . " " . $level->expiration_period, current_time("timestamp")));
}
} else {
$enddate = "NULL";
Expand All @@ -154,21 +169,21 @@ function pmpro_check_discount_code_lite(object $order, object &$level) {
$discountCodeId = "";
if (isset($data->order->discountCode)) {
$codeCheck = pmpro_checkDiscountCode($data->order->discountCode, $level->id, true);

if ($codeCheck[0] == false) {
$useDiscountCode = false;
} else {
$useDiscountCode = true;
}
//update membership_user table.

// update membership_user table.
if (!empty($data->order->discountCode) && !empty($useDiscountCode)) {
$discountCodeId = $wpdb->get_var("SELECT id FROM $wpdb->pmpro_discount_codes WHERE code = '" . esc_sql($data->order->discountCode) . "' LIMIT 1");
$wpdb->query("INSERT INTO $wpdb->pmpro_discount_codes_uses (code_id, user_id, order_id, timestamp) VALUES('" . $discountCodeId . "', '" . $data->userId . "', '" . intval($orderId) . "', '" . current_time( "mysql" ) . "')");

$wpdb->query("INSERT INTO $wpdb->pmpro_discount_codes_uses (code_id, user_id, order_id, timestamp) VALUES('" . $discountCodeId . "', '" . $data->userId . "', '" . intval($orderId) . "', '" . current_time("mysql") . "')");
}
}

$userLevel = array(
'user_id' => $data->userId,
'membership_id' => $level->id,
Expand All @@ -189,8 +204,8 @@ function pmpro_check_discount_code_lite(object $order, object &$level) {
$order->status = "success";
$order->saveOrder();
});
Hook::addFilter('payment_redirect_urls_pmpro_lite', function(object $data) {

Hook::addFilter('payment_redirect_urls_pmpro_lite', function (object $data) {
return [
'success' => pmpro_url("confirmation", "?level=" . $data->params->pmpro->levelId),
'failed' => pmpro_url("account")
Expand All @@ -200,4 +215,4 @@ function pmpro_check_discount_code_lite(object $order, object &$level) {
}
}

new PMPro_Register_Hooks_Lite();
new PMPro_Register_Hooks_Lite();
14 changes: 11 additions & 3 deletions classes/lite/class.pmpro_transaction_model.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
<?php

declare(strict_types=1);

// @phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps

use BeycanPress\CryptoPayLite\Models\AbstractTransaction;

class PMPro_Transaction_Model_Lite extends AbstractTransaction
// @phpcs:ignore
class PMPro_Transaction_Model_Lite extends AbstractTransaction
{
public $addon = 'pmpro';

public string $addon = 'pmpro';

/**
* @return void
*/
public function __construct()
{
parent::__construct('pmpro_transaction');
Expand Down
Loading

0 comments on commit 59837dc

Please sign in to comment.