Skip to content

Commit 98dab9b

Browse files
author
Ariano Fonseca Ângelo
committed
v4.5.1
- Minor fixes - Improved algorithm - Added cryptocurrencies logos to the checkout
1 parent 321813c commit 98dab9b

13 files changed

Lines changed: 504 additions & 423 deletions

CryptAPI.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
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: 4.4.3
6+
Version: 4.5.1
77
Requires at least: 5
8-
Tested up to: 5.9.3
8+
Tested up to: 6.0.1
99
WC requires at least: 5.8
10-
WC tested up to: 6.5.1
10+
WC tested up to: 6.8.0
1111
Requires PHP: 7.2
1212
Author: cryptapi
1313
Author URI: https://cryptapi.io/
@@ -168,4 +168,4 @@ function cryptapi_pro_notice_dismissed()
168168
$user_id = get_current_user_id();
169169
if (isset($_GET['cryptapi-dismissed']))
170170
add_user_meta($user_id, 'cryptapi_pro_notice_dismissed', 'true', true);
171-
}
171+
}

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,18 @@ The easiest and fastest way is via our live chat on our [website](https://crypta
252252
#### 4.4.3
253253
* Minor fixes
254254

255+
#### 4.4.3
256+
* Minor fixes
257+
* Improved algorithm
258+
259+
#### 4.5.0
260+
* Minor fixes
261+
* Improved algorithm
262+
* Added cryptocurrencies logos to the checkout
263+
264+
#### 4.5.1
265+
* Minor fixes
266+
255267
### Upgrade Notice
256268
#### 4.3
257269
* Please be sure to enable the PHP extension BCMath before upgrading to this version.

controllers/CryptAPI.php

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ function __construct()
5656
add_action('woocommerce_email_order_details', array($this, 'add_email_link'), 2, 4);
5757

5858
add_filter('woocommerce_my_account_my_orders_actions', array($this, 'add_order_link'), 10, 2);
59-
6059
}
6160

6261
function load_coins()
@@ -358,7 +357,7 @@ function init_form_fields()
358357
$c = 0;
359358
foreach (WC_CryptAPI_Gateway::$COIN_OPTIONS as $ticker => $coin) {
360359
$this->form_fields["{$ticker}_address"] = array(
361-
'title' => $coin,
360+
'title' => is_array($coin) ? $coin['name'] : $coin,
362361
'type' => 'cryptocurrency',
363362
'description' => sprintf($coin_description, $coin),
364363
'desc_tip' => true,
@@ -387,12 +386,19 @@ function needs_setup()
387386
return true;
388387
}
389388

389+
public function get_icon()
390+
{
391+
392+
$icon = $this->show_branding ? '<img style="top: -5px; position:relative" width="120" src="' . plugin_dir_url(dirname(__FILE__)) . 'static/files/200_logo_ca.png' . '" alt="' . esc_attr($this->get_title()) . '" />' : '';
393+
394+
return apply_filters('woocommerce_gateway_icon', $icon, $this->id);
395+
}
396+
390397
function payment_fields()
391398
{ ?>
392399
<div class="form-row form-row-wide">
393400
<p><?php echo $this->description; ?></p>
394-
<div><img src="" </div>
395-
<ul style="list-style: none outside;">
401+
<ul style="margin-top: 7px; list-style: none outside;">
396402
<?php
397403
if (!empty($this->coins) && is_array($this->coins)) {
398404
$selected = WC()->session->get('cryptapi_coin');
@@ -405,11 +411,12 @@ function payment_fields()
405411
$addr = $this->{$val . '_address'};
406412
$apikey = $this->api_key;
407413
if (!empty($addr) || !empty($apikey)) { ?>
408-
<option value="<?php echo $val; ?>" <?php
414+
<option data-image="<?php echo WC_CryptAPI_Gateway::$COIN_OPTIONS[$val]['logo']; ?>" value="<?php echo $val; ?>" <?php
409415
if (!empty($selected) && $selected === $val) {
410416
echo " selected='true'";
411417
}
412-
?>> <?php echo __('Pay with', 'cryptapi') . ' ' . WC_CryptAPI_Gateway::$COIN_OPTIONS[$val] ?></option>
418+
$crypto_name = is_array(WC_CryptAPI_Gateway::$COIN_OPTIONS[$val]) ? WC_CryptAPI_Gateway::$COIN_OPTIONS[$val]['name'] : WC_CryptAPI_Gateway::$COIN_OPTIONS[$val];
419+
?>> <?php echo __('Pay with', 'cryptapi') . ' ' . $crypto_name; ?></option>
413420
<?php
414421
}
415422
}
@@ -420,6 +427,24 @@ function payment_fields()
420427
} ?>
421428
</ul>
422429
</div>
430+
<script>
431+
jQuery('#payment_cryptapi_coin').selectWoo({
432+
minimumResultsForSearch: -1,
433+
templateResult: formatState,
434+
});
435+
436+
function formatState(opt) {
437+
if (!opt.id) {
438+
return opt.text;
439+
}
440+
let optImage = jQuery(opt.element).attr('data-image');
441+
if (!optImage) {
442+
return opt.text;
443+
} else {
444+
return jQuery('<span style="display:flex; align-items:center;"><img style="margin-right: 8px" src="' + optImage + '" width="24px" alt="' + opt.text + '" /> ' + opt.text + '</span>');
445+
}
446+
}
447+
</script>
423448
<?php
424449
}
425450

@@ -545,6 +570,7 @@ function process_payment($order_id)
545570
function validate_payment()
546571
{
547572
$data = CryptAPI\Helper::process_callback($_GET);
573+
548574
$order = new WC_Order($data['order_id']);
549575

550576
if ($order->is_paid() || $order->get_status() === 'cancelled' || $data['nonce'] != $order->get_meta('cryptapi_nonce')) {
@@ -560,12 +586,12 @@ function validate_payment()
560586
$history = json_decode($order->get_meta('cryptapi_history'), true);
561587

562588
if (empty($history[$data['uuid']])) {
563-
$fiat_conversion = CryptAPI\Helper::get_conversion($order->get_meta('cryptapi_currency'), get_woocommerce_currency(), $paid, $this->disable_conversion);
589+
$conversion = json_decode(stripcslashes($data['value_coin_convert']), true);
564590

565591
$history[$data['uuid']] = [
566592
'timestamp' => time(),
567593
'value_paid' => CryptAPI\Helper::sig_fig($paid, 6),
568-
'value_paid_fiat' => $fiat_conversion,
594+
'value_paid_fiat' => $conversion[get_woocommerce_currency()],
569595
'pending' => $data['pending']
570596
];
571597
} else {
@@ -607,6 +633,14 @@ function validate_payment()
607633
die("*ok*");
608634
}
609635

636+
if ($remaining > 0 && (int)$data['pending'] === 0) {
637+
if ($remaining < $min_tx) {
638+
$order->add_order_note(__('Payment detected and confirmed. Customer still need to send', 'cryptapi') . ' ' . $min_tx . $crypto_coin, false);
639+
} else {
640+
$order->add_order_note(__('Payment detected and confirmed. Customer still need to send', 'cryptapi') . ' ' . $remaining . $crypto_coin, false);
641+
}
642+
}
643+
610644
if ($remaining_pending < $min_tx) {
611645
$order->update_meta_data('cryptapi_qr_code_value', CryptAPI\Helper::get_static_qrcode($order->get_meta('cryptapi_address'), $order->get_meta('cryptapi_currency'), $min_tx, $this->qrcode_size)['qr_code']);
612646
} else {
@@ -1167,7 +1201,7 @@ public function generate_cryptocurrency_html($key, $data)
11671201
<td class="forminp forminp-<?php echo esc_attr($data['type']) ?>">
11681202
<p>
11691203
<strong>
1170-
<?php echo __('Addresses', 'cryptapi');?>
1204+
<?php echo __('Addresses', 'cryptapi'); ?>
11711205
</strong><br/>
11721206
<?php echo __("If you are using CryptAPI Pro you can choose if setting the receiving addresses here bellow or in your CryptAPI Pro settings page.<br/>- In order to set the addresses on plugin settings, you need to select “Address Override” while creating the API key.<br/>- In order to set the addresses on CryptAPI Pro settings, you need to NOT select “Address Override” while creating the API key.", 'cryptapi'); ?>
11731207
</p>
@@ -1227,7 +1261,7 @@ function handling_fee()
12271261
return;
12281262
}
12291263

1230-
if (!empty($selected) && $selected !='none' && $this->add_blockchain_fee) {
1264+
if (!empty($selected) && $selected != 'none' && $this->add_blockchain_fee) {
12311265
$est = CryptAPI\Helper::get_estimate($selected);
12321266

12331267
$fee_order += (float)$est->{get_woocommerce_currency()};

define.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
22

3-
define('CRYPTAPI_PLUGIN_VERSION', '4.4.3');
3+
define('CRYPTAPI_PLUGIN_VERSION', '4.5.1');
44
define('CRYPTAPI_PLUGIN_PATH', plugin_dir_path(__FILE__));
55
define('CRYPTAPI_PLUGIN_URL', plugin_dir_url(__FILE__));
141 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)