Skip to content

Commit 91a7232

Browse files
committed
v5.1.0
* Callback improvements * Minor bugfixes
1 parent c190ca5 commit 91a7232

File tree

5 files changed

+74
-20
lines changed

5 files changed

+74
-20
lines changed

CryptAPI.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: CryptAPI Payment Gateway for WooCommerce
44
Plugin URI: https://github.com/cryptapi/woocommerce-cryptapi
55
Description: Accept cryptocurrency payments on your WooCommerce website
6-
Version: 5.0.2
6+
Version: 5.1.0
77
Requires at least: 5.8
88
Tested up to: 6.7.2
99
WC requires at least: 5.8
@@ -17,7 +17,7 @@
1717
exit; // Exit if accessed directly.
1818
}
1919

20-
define('CRYPTAPI_PLUGIN_VERSION', '5.0.2');
20+
define('CRYPTAPI_PLUGIN_VERSION', '5.1.0');
2121
define('CRYPTAPI_PLUGIN_PATH', plugin_dir_path(__FILE__));
2222
define('CRYPTAPI_PLUGIN_URL', plugin_dir_url(__FILE__));
2323

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,10 @@ The easiest and fastest way is via our live chat on our [website](https://crypta
404404
#### 5.0.2
405405
* Bug fixes.
406406

407+
#### 5.1.0
408+
* Callback improvements
409+
* Minor bugfixes
410+
407411
### Upgrade Notice
408412
#### 4.3
409413
* Please be sure to enable the PHP extension BCMath before upgrading to this version.

controllers/CryptAPI.php

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -552,14 +552,13 @@ function process_payment($order_id)
552552
$addr = $this->{$selected . '_address'};
553553

554554
if (!empty($addr) || !empty($api_key)) {
555-
556555
$nonce = $this->generate_nonce();
557556

558-
$callback_url = str_replace('https:', 'http:', add_query_arg(array(
557+
$callback_url = add_query_arg(array(
559558
'wc-api' => 'WC_Gateway_CryptAPI',
560559
'order_id' => $order_id,
561560
'nonce' => $nonce,
562-
), home_url('/')));
561+
), trailingslashit(home_url('')));
563562

564563
try {
565564
$order = new \WC_Order($order_id);
@@ -658,9 +657,12 @@ function process_payment($order_id)
658657
function validate_payment()
659658
{
660659
$data = \CryptAPI\Utils\Api::process_callback($_GET);
661-
662660
$order = new \WC_Order($data['order_id']);
663661

662+
if (!$this->verify_signature($_SERVER)) {
663+
die('Sig not valid');
664+
}
665+
664666
if ($order->is_paid() || $order->get_status() === 'cancelled' || $data['nonce'] != $order->get_meta('cryptapi_nonce')) {
665667
die("*ok*");
666668
}
@@ -672,6 +674,41 @@ function validate_payment()
672674
$this->process_callback_data($data, $order);
673675
}
674676

677+
static function load_pubkey() {
678+
$transient = get_transient('cryptapi_pubkey');
679+
680+
if (!empty($transient)) {
681+
$pubkey = $transient;
682+
} else {
683+
$pubkey = \CryptAPI\Utils\Api::get_pubkey();
684+
set_transient('cryptapi_pubkey', $pubkey, 86400);
685+
686+
if (empty($pubkey)) {
687+
throw new Exception('Failed fetching the pubkey.');
688+
}
689+
}
690+
691+
return $pubkey;
692+
}
693+
694+
function verify_signature($server) {
695+
$pubkey = $this->load_pubkey();
696+
697+
if (!array_key_exists( 'HTTP_X_CA_SIGNATURE', $server )) {
698+
return false;
699+
}
700+
701+
$signature = base64_decode($server['HTTP_X_CA_SIGNATURE']);
702+
703+
$algo = OPENSSL_ALGO_SHA256;
704+
705+
$home_url = home_url('');
706+
707+
$data = "$home_url$server[REQUEST_URI]";
708+
709+
return (bool) openssl_verify($data, $signature, $pubkey, $algo);
710+
}
711+
675712
function order_status()
676713
{
677714
$order_id = sanitize_text_field($_REQUEST['order_id']);
@@ -1345,18 +1382,6 @@ function scheduled_subscription_mail($amount, $renewal_order)
13451382
}
13461383
}
13471384

1348-
private function generate_nonce($len = 32)
1349-
{
1350-
$data = str_split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');
1351-
1352-
$nonce = [];
1353-
for ($i = 0; $i < $len; $i++) {
1354-
$nonce[] = $data[mt_rand(0, sizeof($data) - 1)];
1355-
}
1356-
1357-
return implode('', $nonce);
1358-
}
1359-
13601385
public function generate_cryptocurrency_html($key, $data)
13611386
{
13621387
$field_key = $this->get_field_key($key);
@@ -1425,6 +1450,18 @@ public function generate_cryptocurrency_html($key, $data)
14251450
return ob_get_clean();
14261451
}
14271452

1453+
private function generate_nonce($len = 32)
1454+
{
1455+
$data = str_split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');
1456+
1457+
$nonce = [];
1458+
for ($i = 0; $i < $len; $i++) {
1459+
$nonce[] = $data[mt_rand(0, sizeof($data) - 1)];
1460+
}
1461+
1462+
return implode('', $nonce);
1463+
}
1464+
14281465
function handling_fee()
14291466
{
14301467
if (is_admin() && !defined('DOING_AJAX')) {

readme.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: cryptapi
33
Tags: crypto payments, woocommerce, payment gateway, crypto, payment, pay with crypto, payment request, bitcoin, bnb, usdt, ethereum, litecoin, bitcoin cash, shib, doge, solana
44
Requires at least: 5.8
55
Tested up to: 6.7.2
6-
Stable tag: 5.0.2
6+
Stable tag: 5.1.0
77
Requires PHP: 7.2
88
WC requires at least: 5.8
99
WC tested up to: 9.6.2
@@ -402,6 +402,10 @@ The easiest and fastest way is via our live chat on our [website](https://crypta
402402
= 5.0.2 =
403403
* Bug fixes.
404404

405+
= 5.1.0 =
406+
* Callback improvements
407+
* Minor bugfixes
408+
405409
== Upgrade Notice ==
406410

407411
= 4.3 =

utils/Api.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ public static function get_conversion($from, $to, $value, $disable_conversion)
204204

205205
public static function get_estimate($coin)
206206
{
207-
208207
$params = [
209208
'addresses' => 1,
210209
'priority' => 'default',
@@ -219,6 +218,16 @@ public static function get_estimate($coin)
219218
return null;
220219
}
221220

221+
public static function get_pubkey() {
222+
$response = self::_request(null, 'pubkey', []);
223+
224+
if ($response->status == 'success') {
225+
return $response->pubkey;
226+
}
227+
228+
return null;
229+
}
230+
222231
public static function process_callback($_get)
223232
{
224233
$params = [

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy