Skip to content

Commit d721268

Browse files
committed
v1.0.0
- Initial release
1 parent c4a588a commit d721268

File tree

3 files changed

+100
-33
lines changed

3 files changed

+100
-33
lines changed

BlockBee.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
Description: Accept cryptocurrency payments on your WooCommerce website
66
Version: 1.0.0
77
Requires at least: 5
8-
Tested up to: 6.0.2
8+
Tested up to: 6.0.3
99
WC requires at least: 5.8
10-
WC tested up to: 6.9.4
10+
WC tested up to: 7.0.0
1111
Requires PHP: 7.2
1212
Author: BlockBee
1313
Author URI: https://blockbee.io/

controllers/BlockBee.php

+96-29
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ function __construct() {
4343
add_action( 'wp_ajax_nopriv_' . $this->id . '_order_status', array( $this, 'order_status' ) );
4444
add_action( 'wp_ajax_' . $this->id . '_order_status', array( $this, 'order_status' ) );
4545

46+
add_action( 'wp_ajax_' . $this->id . '_validate_logs', array( $this, 'validate_logs' ) );
47+
4648
add_action( 'blockbee_cronjob', array( $this, 'cronjob' ), 10, 3 );
4749

4850
add_action( 'woocommerce_cart_calculate_fees', array( $this, 'handling_fee' ) );
@@ -54,6 +56,8 @@ function __construct() {
5456
add_action( 'woocommerce_email_order_details', array( $this, 'add_email_link' ), 2, 4 );
5557

5658
add_filter( 'woocommerce_my_account_my_orders_actions', array( $this, 'add_order_link' ), 10, 2 );
59+
60+
add_action( 'woocommerce_admin_order_data_after_order_details', array( $this, 'order_detail_validate_logs' ) );
5761
}
5862

5963
function load_coins() {
@@ -77,10 +81,10 @@ function admin_options() {
7781
parent::admin_options();
7882
?>
7983
<div style='margin-top: 2rem;'>
80-
<?php echo esc_attr(__( "If you need any help or have any suggestion, contact us via the <b>live chat</b> on our <b><a href='https://blockbee.io' target='_blank'>website</a></b> or join our <b><a href='https://discord.gg/cryptapi' target='_blank'>Discord server</a></b>", "blockbee-cryptocurrency-payment-gateway" )); ?>
84+
<?php echo __( "If you need any help or have any suggestion, contact us via the <b>live chat</b> on our <b><a href='https://blockbee.io' target='_blank'>website</a></b> or join our <b><a href='https://discord.gg/cryptapi' target='_blank'>Discord server</a></b>", "blockbee-cryptocurrency-payment-gateway" ); ?>
8185
</div>
8286
<div style='margin-top: .5rem;'>
83-
<?php echo esc_attr(__( "If you enjoy this plugin please <b><a href='https://wordpress.org/support/plugin/blockbee-cryptocurrency-payment-gateway-for-woocommerce/reviews/#new-post' target='_blank'>rate and review it</a></b>!", "blockbee-cryptocurrency-payment-gateway" )); ?>
87+
<?php echo __( "If you enjoy this plugin please <b><a href='https://wordpress.org/support/plugin/blockbee-cryptocurrency-payment-gateway-for-woocommerce/reviews/#new-post' target='_blank'>rate and review it</a></b>!", "blockbee-cryptocurrency-payment-gateway" ); ?>
8488
</div>
8589
<?php
8690
}
@@ -143,7 +147,7 @@ function init_form_fields() {
143147
'title' => __( 'Show crypto logos in checkout', 'blockbee-cryptocurrency-payment-gateway' ),
144148
'type' => 'checkbox',
145149
'label' => sprintf( __( 'Enable this to show the cryptocurrencies logos in the checkout %1$s %2$s Notice: %3$s It may break in some templates. Use at your own risk.', 'blockbee-cryptocurrency-payment-gateway' ), '<br/>', '<strong>', '</strong>' ),
146-
'default' => 'yes'
150+
'default' => 'false'
147151
),
148152
'add_blockchain_fee' => array(
149153
'title' => __( 'Add the blockchain fee to the order', 'blockbee-cryptocurrency-payment-gateway' ),
@@ -527,10 +531,6 @@ function order_status() {
527531
$showMinFee = 1;
528532
}
529533

530-
if ( ( (int) $order->get_meta( 'blockbee_last_checked' ) + 60 ) < time() && (int) $order->get_meta( 'blockbee_cancelled' ) === 0 && ! $order->is_paid() ) {
531-
$this->validate_logs( $order, $history );
532-
}
533-
534534
$data = [
535535
'is_paid' => $order->is_paid(),
536536
'is_pending' => $blockbee_pending,
@@ -559,21 +559,33 @@ function order_status() {
559559
die();
560560
}
561561

562-
function validate_logs( $order, $history ) {
563-
$callbacks = BlockBee\Helper::check_logs( $order->get_meta( 'blockbee_callback_url' ), $order->get_meta( 'blockbee_currency' ) );
562+
function validate_logs() {
563+
$order_id = sanitize_text_field( $_REQUEST['order_id'] );
564+
$order = new WC_Order($order_id);
564565

565-
$order->update_meta_data( 'blockbee_last_checked', time() );
566-
$order->save_meta_data();
566+
try {
567+
568+
$callbacks = BlockBee\Helper::check_logs( $order->get_meta( 'blockbee_callback_url' ), $order->get_meta( 'blockbee_currency' ) );
569+
570+
$order->update_meta_data( 'cryptapi_last_checked', time() );
571+
$order->save_meta_data();
567572

568-
foreach ( $callbacks as $callback ) {
569-
$logs = $callback->logs;
570-
$request_url = parse_url( $logs[0]->request_url );
571-
parse_str( $request_url['query'], $data );
573+
if($callbacks) {
574+
foreach ( $callbacks as $callback ) {
575+
$logs = $callback->logs;
576+
$request_url = parse_url( $logs[0]->request_url );
577+
parse_str( $request_url['query'], $data );
572578

573-
if ( empty( $history[ $data->uuid ] ) || ( ! empty( $history[ $data->uuid ] ) && (int) $history[ $data->uuid ]['pending'] === 1 && (int) $data['pending'] === 0 ) ) {
574-
$this->process_callback_data( $data, $order, true );
579+
if ( empty( $history[ $data->uuid ] ) || ( ! empty( $history[ $data->uuid ] ) && (int) $history[ $data->uuid ]['pending'] === 1 && (int) $data['pending'] === 0 ) ) {
580+
$this->process_callback_data( $data, $order, true );
581+
}
582+
}
575583
}
584+
die();
585+
} catch ( Exception $e ) {
586+
//
576587
}
588+
die();
577589
}
578590

579591
function process_callback_data( $data, $order, $validation = false ) {
@@ -585,6 +597,14 @@ function process_callback_data( $data, $order, $validation = false ) {
585597

586598
$history = json_decode( $order->get_meta( 'blockbee_history' ), true );
587599

600+
if(!$data['uuid']) {
601+
if ( ! $validation ) {
602+
die( "*ok*" );
603+
} else {
604+
return;
605+
}
606+
}
607+
588608
if ( empty( $history[ $data['uuid'] ] ) ) {
589609
$conversion = json_decode( stripcslashes( $data['value_coin_convert'] ), true );
590610

@@ -764,7 +784,7 @@ function thankyou_page( $order_id ) {
764784
?>
765785
<img class="blockbee_qrcode value" <?php
766786
if ( $qr_code_setting == 'without_amount' ) {
767-
echo esc_attr('style="display:none;"');
787+
echo 'style="display:none;"';
768788
}
769789
?> src="data:image/png;base64,<?php echo $qr_code_img_value; ?>" alt="<?php echo esc_attr(__( 'QR Code with value', 'blockbee-cryptocurrency-payment-gateway' )); ?>"/>
770790
<?php
@@ -780,7 +800,7 @@ function thankyou_page( $order_id ) {
780800
?>
781801
<button class="blockbee_qrcode_btn no_value <?php
782802
if ( $qr_code_setting == 'without_amount' ) {
783-
echo esc_attr('active');
803+
echo 'active';
784804
}
785805
?>" aria-label="<?php echo esc_attr(__( 'Show QR Code without value', 'blockbee-cryptocurrency-payment-gateway' )); ?>">
786806
<?php echo esc_attr(__( 'ADDRESS', 'blockbee-cryptocurrency-payment-gateway' )); ?>
@@ -791,7 +811,7 @@ function thankyou_page( $order_id ) {
791811
?>
792812
<button class="blockbee_qrcode_btn value <?php
793813
if ( $qr_code_setting == 'amount' ) {
794-
echo esc_attr('active');
814+
echo 'active';
795815
}
796816
?>" aria-label="<?php echo esc_attr(__( 'Show QR Code with value', 'blockbee-cryptocurrency-payment-gateway' )); ?>">
797817
<?php echo esc_attr(__( 'WITH AMOUNT', 'blockbee-cryptocurrency-payment-gateway' )); ?>
@@ -830,18 +850,18 @@ function thankyou_page( $order_id ) {
830850
<span class="blockbee_tooltip blockbee_copy_icon_tooltip tip"><?php echo esc_attr(__( 'COPY', 'blockbee-cryptocurrency-payment-gateway' )); ?></span>
831851
<span class="blockbee_tooltip blockbee_copy_icon_tooltip success" style="display: none"><?php echo esc_attr(__( 'COPIED!', 'blockbee-cryptocurrency-payment-gateway' )); ?></span>
832852
</button>
833-
<strong>(<?php echo esc_attr("{$currency_symbol}" . " <span class='blockbee_fiat_total'>" . $total . "</span>"); ?>)</strong>
853+
<strong>(<?php echo esc_attr($currency_symbol) . "<span class='blockbee_fiat_total'>" . esc_attr($total) . "</span>"?>)</strong>
834854
</div>
835855
<div class="blockbee_payment_notification blockbee_notification_payment_received" style="display: none;">
836-
<?php echo esc_attr(sprintf( __( 'So far you sent %1s. Please send a new payment to complete the order, as requested above', 'blockbee-cryptocurrency-payment-gateway' ),
856+
<?php echo sprintf( __( 'So far you sent %1s. Please send a new payment to complete the order, as requested above', 'blockbee-cryptocurrency-payment-gateway' ),
837857
'<strong><span class="blockbee_notification_amount"></span></strong>'
838-
)); ?>
858+
); ?>
839859
</div>
840860
<div class="blockbee_payment_notification blockbee_notification_remaining" style="display: none">
841-
<?php echo esc_attr('<strong>' . __( 'Notice', 'blockbee-cryptocurrency-payment-gateway' ) . '</strong>: ' . sprintf( __( 'For technical reasons, the minimum amount for each transaction is %1s, so we adjusted the value by adding the remaining to it.', 'blockbee-cryptocurrency-payment-gateway' ),
842-
$min_tx . ' ' . strtoupper( $crypto_coin ),
861+
<?php echo '<strong>' . __( 'Notice', 'blockbee-cryptocurrency-payment-gateway' ) . '</strong>: ' . sprintf( __( 'For technical reasons, the minimum amount for each transaction is %1s, so we adjusted the value by adding the remaining to it.', 'blockbee-cryptocurrency-payment-gateway' ),
862+
esc_attr($min_tx) . ' ' . strtoupper( esc_attr($crypto_coin) ),
843863
'<span class="blockbee_notification_remaining"></span>'
844-
)); ?>
864+
); ?>
845865
</div>
846866
<?php
847867
if ( intval( $this->refresh_value_interval ) != 0 ) {
@@ -851,7 +871,7 @@ function thankyou_page( $order_id ) {
851871
strtoupper( $crypto_coin )
852872
)); ?>
853873
<span class="blockbee_time_seconds_count" data-soon="<?php echo esc_attr(__( 'a moment', 'blockbee-cryptocurrency-payment-gateway' )); ?>"
854-
data-seconds="<?php echo esc_attr($conversion_timer); ?>"><?php echo esc_attr(date( 'i:s', $conversion_timer )); ?></span>
874+
data-seconds="<?php echo esc_attr($conversion_timer); ?>"><?php echo date( 'i:s', esc_attr($conversion_timer) ); ?></span>
855875
</div>
856876
<?php
857877
}
@@ -878,12 +898,12 @@ function thankyou_page( $order_id ) {
878898
<a class="blockbee_show_qr" href="#" aria-label="<?php echo esc_attr(__( 'Show the QR code', 'blockbee-cryptocurrency-payment-gateway' )); ?>">
879899
<span class="blockbee_show_qr_open <?php
880900
if ( ! $this->qrcode_default ) {
881-
echo esc_attr('active');
901+
echo ' active';
882902
}
883903
?>"><?php echo __( 'Open QR CODE', 'blockbee-cryptocurrency-payment-gateway' ); ?></span>
884904
<span class="blockbee_show_qr_close<?php
885905
if ( $this->qrcode_default ) {
886-
echo esc_attr('active');
906+
echo ' active';
887907
}
888908
?>"><?php echo esc_attr(__( 'Close QR CODE', 'blockbee-cryptocurrency-payment-gateway' )); ?></span>
889909
</a>
@@ -1235,4 +1255,51 @@ function get_private_order_notes( $order_id ) {
12351255

12361256
return $order_note;
12371257
}
1258+
1259+
function order_detail_validate_logs($order) {
1260+
if ( WC_BlockBee_Gateway::$HAS_TRIGGERED ) {
1261+
return;
1262+
}
1263+
1264+
if($order->is_paid()) {
1265+
return;
1266+
}
1267+
1268+
if($order->get_payment_method() !== 'blockbee') {
1269+
return;
1270+
}
1271+
1272+
$ajax_url = add_query_arg( array(
1273+
'action' => 'blockbee_validate_logs',
1274+
'order_id' => $order->get_ID(),
1275+
), home_url( '/wp-admin/admin-ajax.php' ) );
1276+
?>
1277+
<p class="form-field form-field-wide wc-customer-user">
1278+
<small style="display: block;">
1279+
<?php echo sprintf(esc_attr( __( 'If the order is not being updated, your ISP is probably blocking our IPs (%1$s and %2$s): please try to get them whitelisted and feel free to contact us anytime to get support (link to our contact page). In the meantime you can refresh the status of any payment by clicking this button below:', 'blockbee-cryptocurrency-payment-gateway' ) ), '145.239.119.223', '135.125.112.47'); ?>
1280+
</small>
1281+
</p>
1282+
<a style="margin-top: 1rem;margin-bottom: 1rem;" id="validate_callbacks" class="button action" href="#">
1283+
<?php echo esc_attr( __( 'Check for Callbacks', 'blockbee-cryptocurrency-payment-gateway' ) ); ?>
1284+
</a>
1285+
<script>
1286+
jQuery(function () {
1287+
const validate_button = jQuery('#validate_callbacks');
1288+
1289+
validate_button.on('click', function (e) {
1290+
e.preventDefault();
1291+
validate_callbacks();
1292+
validate_button.html('<?php echo esc_attr( __( 'Checking', 'blockbee-cryptocurrency-payment-gateway' ) );?>');
1293+
})
1294+
1295+
function validate_callbacks() {
1296+
jQuery.getJSON('<?php echo $ajax_url?>').always(function () {
1297+
window.location.reload();
1298+
})
1299+
}
1300+
})
1301+
</script>
1302+
<?php
1303+
WC_BlockBee_Gateway::$HAS_TRIGGERED = true;
1304+
}
12381305
}

readme.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
Contributors: blockbee
33
Tags: crypto payments, woocommerce, payment gateway, crypto, payment, pay with crypto, payment request, bitcoin, bnb, usdt, ethereum, monero, litecoin, bitcoin cash, shib, doge
44
Requires at least: 5
5-
Tested up to: 6.0.2
5+
Tested up to: 6.0.3
66
Stable tag: 1.0.0
77
Requires PHP: 7.2
88
WC requires at least: 5.8
9-
WC tested up to: 6.8.0
9+
WC tested up to: 7.0.0
1010
License: MIT
1111

1212
Accept cryptocurrency payments on your WooCommerce website

0 commit comments

Comments
 (0)