Skip to content

Commit 065e3ab

Browse files
author
Arkady Yusupov
committed
added (auto) version checks & updates
added/fixed in update version preview fixed links in plugins list added direct link to settings in plugins list minor lib reorganisation
1 parent ee1b9f1 commit 065e3ab

7 files changed

Lines changed: 296 additions & 141 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# php plugin for woocommerce wordpress
2-
# version 1.0.4
3-
# tested on Wordpress 6.6, 6.8.1, 6.8.2, 6.8.3
4-
# with wooCommerce (8.7.0, 9.3.4, 9.5.1)
2+
3+
version 1.2.0.
4+
tested on Wordpress 6.6, 6.8.1, 6.8.2, 6.8.3, 6.9.1.
5+
with wooCommerce (8.7.0, 9.3.4, 9.5.1).

lib/Api.php

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<?php
2+
/**
3+
* @author Payneteasy
4+
* @copyright 2007-2026 Payneteasy
5+
* @license Property of Payneteasy
6+
*/
7+
8+
namespace Payneteasy\lib;
9+
10+
defined('PAYNETEASY_LIB') or die('Restricted access');
11+
12+
include_once('ApiException.php');
13+
14+
class Api {
15+
private const URL = 'paynet/api/v2/';
16+
private const USERAGENT = 'Payneteasy-Client/1.0';
17+
18+
private string $login;
19+
private string $gate;
20+
private string $control_key;
21+
private string $endpoint;
22+
private bool $is_direct;
23+
24+
public function __construct(string $gate, string $login, string $control_key, string $endpoint, bool $is_direct) {
25+
$this->gate = $gate;
26+
$this->login = $login;
27+
$this->control_key = $control_key;
28+
$this->endpoint = $endpoint;
29+
$this->is_direct = $is_direct;
30+
}
31+
32+
public static function trace(array $a1, array $a2=null): void {
33+
$prefix = isset($a2) ? ' -> ' : ' <- ';
34+
35+
ksort($a1);
36+
foreach ($a1 as $key => $value)
37+
error_log("$prefix'$key' => '$value'");
38+
39+
if (isset($a2)) {
40+
error_log('');
41+
42+
ksort($a2);
43+
foreach ($a2 as $key => $value)
44+
error_log(" <- '$key' => '$value'");
45+
}
46+
}
47+
48+
public static function fetch_github_version(string $repo=''): string {
49+
$Curl = curl_init($url = sprintf('https://api.github.com/repos/%s/releases/latest', $repo));
50+
51+
curl_setopt_array($Curl, [ CURLOPT_USERAGENT => self::USERAGENT, CURLOPT_RETURNTRANSFER => 1 ]);
52+
53+
$response = curl_exec($Curl);
54+
55+
if ($err = curl_errno($Curl))
56+
$errmsg = "Github request error, CURL errno: $err";
57+
elseif (($err = curl_getinfo($Curl, CURLINFO_HTTP_CODE)) != 200)
58+
$errmsg = "Github request error, HTTP code: '{$err}'";
59+
60+
if (!empty($errmsg))
61+
throw new ApiException($errmsg);
62+
elseif (empty($response))
63+
throw new ApiException('Github version response is empty');
64+
65+
curl_close($Curl);
66+
67+
if (!preg_match('/(?:\d+\.)+\d+$/', ($tag = array_reverse(preg_split('/ +/', (json_decode($response, true)['name'])))[0]), $match))
68+
throw new ApiException("Github version tag is malformed: '$tag'");
69+
70+
return $match[0];
71+
}
72+
73+
public function check_config_input(string $gate, string $sandbox, string $login, string $control_key, string $endpoint): array {
74+
return array_reduce([
75+
[ 'Gateway URL', $gate, '|^https?://(?:\\w+(?:-\\w+)*\\.)+(?:\\w+(?:-\\w+)*)/|' ],
76+
[ 'Sandbox URL', $sandbox, '|^https?://(?:\\w+(?:-\\w+)*\\.)+\\w+/|' ],
77+
[ 'Login', $login, '/^[a-z][\\w-]*\\w$/i' ],
78+
[ 'Control key', $control_key, '/^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/i' ],
79+
[ 'End point Id', $endpoint, '/^\d+$/' ]],
80+
function($iter, $entry){ if (!preg_match($entry[2], $entry[1])) $iter[] = "{$entry[0]} is invalid"; return $iter; },
81+
[]);
82+
}
83+
84+
public function is_configured(): bool
85+
{ return $this->login && $this->control_key && $this->endpoint; }
86+
87+
public function is_direct(): bool
88+
{ return $this->is_direct; }
89+
90+
public function sale(array $data): array
91+
{ return $this->execute($this->is_direct ? 'sale' : 'sale-form', $this->signed($data)); }
92+
93+
public function return(array $data): array
94+
{ return $this->execute('return', $this->signed($data, null, true)); }
95+
96+
public function status(array $data): array
97+
{ return $this->execute('status', $this->signed($data, $this->login.$data['client_orderid'].$data['orderid'].$this->control_key)); }
98+
99+
private function signed(array $data, string $str=null, bool $add_login=false): array {
100+
if (isset($str) || $add_login)
101+
$data['login'] = $this->login;
102+
103+
$data['control'] = sha1($str ?? $this->endpoint.$data['client_orderid'].($data['amount'] * 100).$data['email'].$this->control_key);
104+
return $data;
105+
}
106+
107+
private function execute(string $action, array $data): array {
108+
$Curl = curl_init($this->gate . self::URL . "$action/{$this->endpoint}");
109+
110+
curl_setopt_array($Curl, [
111+
CURLOPT_HEADER => 0,
112+
CURLOPT_USERAGENT => self::USERAGENT,
113+
CURLOPT_SSL_VERIFYHOST => 0,
114+
CURLOPT_SSL_VERIFYPEER => 0,
115+
CURLOPT_POST => 1,
116+
CURLOPT_RETURNTRANSFER => 1,
117+
CURLOPT_POSTFIELDS => http_build_query($data) ]);
118+
119+
$response = curl_exec($Curl);
120+
121+
if ($err = curl_errno($Curl))
122+
$errmsg = "Card processing error, CURL errno: '$err'";
123+
elseif (($err = curl_getinfo($Curl, CURLINFO_HTTP_CODE)) != 200)
124+
$errmsg = "Card processing error, HTTP code: '$err'";
125+
126+
curl_close($Curl);
127+
128+
if (!empty($errmsg))
129+
throw new ApiException($errmsg);
130+
elseif (empty($response))
131+
throw new ApiException('Card processing response is empty');
132+
133+
parse_str($response, $result);
134+
array_walk($result, fn(&$v) => $v = rtrim($v));
135+
136+
if ($result['type'] == 'validation-error')
137+
throw new ApiException("Card processing returned error: '{$result['error-message']}'", [ $data, $result ]);
138+
139+
return $result;
140+
}
141+
}
142+
143+
?>

lib/ApiException.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* @author Payneteasy
4+
* @copyright 2007-2026 Payneteasy
5+
* @license Property of Payneteasy
6+
*/
7+
8+
namespace Payneteasy\lib;
9+
10+
defined('PAYNETEASY_LIB') or die('Restricted access');
11+
12+
class ApiException extends \Exception {
13+
private array $context = [];
14+
15+
public function __construct(string $message, array $in_out = [], int $code = 0, \Throwable $previous = null) {
16+
parent::__construct($message, $code, $previous);
17+
18+
error_log($this->message.' in '.$this->file.':'.$this->line);
19+
20+
if ($in = array_shift($in_out)) {
21+
ksort($in);
22+
foreach ($in as $key => $value)
23+
error_log(" -> '$key' => '$value'");
24+
25+
if ($out = array_shift($in_out)) {
26+
error_log('');
27+
28+
ksort($out);
29+
foreach ($out as $key => $value)
30+
error_log(" <- '$key' => '$value'");
31+
}
32+
}
33+
}
34+
}
35+
36+
?>

src/Classes/Api/PaynetApi.php

Lines changed: 0 additions & 81 deletions
This file was deleted.

src/Classes/Exception/PayneteasyException.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

update.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "Payneteasy Payment System",
3+
"slug": "php-plugin-woocommerce",
4+
"author": "<a href='https://payneteasy.com/'>Payneteasy</a>",
5+
"version": "1.2.0",
6+
"requires": "6.6",
7+
"tested": "6.9.1",
8+
"requires_php": "7.4",
9+
"last_updated": "2026-03-03",
10+
"sections" : {
11+
"description" : "Plugin &quot;Payneteasy Payment System&quot; for WooCommerce,<br /> which allows you to integrate online payments."
12+
}
13+
}

0 commit comments

Comments
 (0)