diff --git a/changelog.txt b/changelog.txt index 4d0304c..ebadccd 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,8 @@ *** DePay Web3 Payments for WooCommerce Changelog *** +2022-12-12 - version 1.8.0 +* adds logs + 2022-12-12 - version 1.7.0 * add CURL, POST and GET status to debug diff --git a/depay-woocommerce-payments.php b/depay-woocommerce-payments.php index 475a5df..e51d9b3 100644 --- a/depay-woocommerce-payments.php +++ b/depay-woocommerce-payments.php @@ -12,7 +12,7 @@ * WC tested up to: 7.1.1 * Requires at least: 5.8 * Requires PHP: 7.0 - * Version: 1.7.0 + * Version: 1.8.0 * * @package DePay\Payments */ @@ -22,7 +22,7 @@ define( 'DEPAY_WC_PLUGIN_FILE', __FILE__ ); define( 'DEPAY_WC_ABSPATH', __DIR__ . '/' ); define( 'DEPAY_MIN_WC_ADMIN_VERSION', '0.23.2' ); -define( 'DEPAY_CURRENT_VERSION', '1.7.0' ); +define( 'DEPAY_CURRENT_VERSION', '1.8.0' ); require_once DEPAY_WC_ABSPATH . '/vendor/autoload.php'; @@ -34,6 +34,12 @@ function depay_activated() { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta(" + CREATE TABLE wp_wc_depay_logs ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + log LONGTEXT NOT NULL, + created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + PRIMARY KEY (id) + ); CREATE TABLE wp_wc_depay_checkouts ( id VARCHAR(36) NOT NULL, order_id BIGINT UNSIGNED NOT NULL DEFAULT 0, diff --git a/includes/class-depay-wc-payments-gateway.php b/includes/class-depay-wc-payments-gateway.php index 14b8f2c..92477ab 100644 --- a/includes/class-depay-wc-payments-gateway.php +++ b/includes/class-depay-wc-payments-gateway.php @@ -50,22 +50,31 @@ public function process_payment( $order_id ) { $order->payment_complete(); } } - + public function get_accept( $order ) { $total = $order->get_total(); $currency = $order->get_currency(); if ( 'USD' == $currency ) { $total_in_usd = $total; } else { - $get = wp_remote_get( sprintf( 'https://public.depay.com/currencies/%s', $currency )); + $get = wp_remote_get( sprintf( 'https://public.depay.com/currencies/%s', $currency ) ); + if ( is_wp_error($get) ) { + DePay_WC_Payments::log( $get->get_error_message() ); + } $rate = $get['body']; $total_in_usd = bcdiv( $total, $rate, 3 ); } $accept = []; foreach ( json_decode( get_option( 'depay_wc_accepted_payments' ) ) as $accepted_payment ) { $get = wp_remote_get( sprintf( 'https://public.depay.com/tokens/prices/%s/%s', $accepted_payment->blockchain, $accepted_payment->token ) ); + if ( is_wp_error($get) ) { + DePay_WC_Payments::log( $get->get_error_message() ); + } $rate = $get['body']; $get = wp_remote_get( sprintf( 'https://public.depay.com/tokens/decimals/%s/%s', $accepted_payment->blockchain, $accepted_payment->token ) ); + if ( is_wp_error($get) ) { + DePay_WC_Payments::log( $get->get_error_message() ); + } $decimals = intval( $get['body'] ); if ( !empty( $rate ) && !empty( $decimals ) ) { array_push($accept, [ diff --git a/includes/class-depay-wc-payments-rest.php b/includes/class-depay-wc-payments-rest.php index 9f87956..c09b4a4 100644 --- a/includes/class-depay-wc-payments-rest.php +++ b/includes/class-depay-wc-payments-rest.php @@ -223,6 +223,7 @@ public function track_payment( $request ) { if ( !is_wp_error( $post ) && ( wp_remote_retrieve_response_code( $post ) == 200 || wp_remote_retrieve_response_code( $post ) == 201 ) ) { $response->set_status( 200 ); } else { + DePay_WC_Payments::log( $post->get_error_message() ); $response->set_status( 500 ); } @@ -490,6 +491,8 @@ public function confirm_payment( $request ) { } public function debug( $request ) { + global $wpdb; + $post_response = wp_remote_post( 'https://public.depay.com', array( 'headers' => array( 'Content-Type' => 'application/json; charset=utf-8' ), 'body' => json_encode( [] ), @@ -501,6 +504,7 @@ public function debug( $request ) { $get_response = wp_remote_get( 'https://public.depay.com' ); $get_response_code = $get_response['response']['code']; $get_response_successful = ! is_wp_error( $get_response_code ) && $get_response_code >= 200 && $get_response_code < 300; + $last_logs = $wpdb->get_results( 'SELECT * FROM wp_wc_depay_logs ORDER BY created_at DESC LIMIT 10' ); $response = rest_ensure_response( [ 'wc' => wc()->version, @@ -512,6 +516,7 @@ public function debug( $request ) { 'currency' => get_option( 'woocommerce_currency' ), 'address' => get_option( 'depay_wc_receiving_wallet_address' ), 'accept' => get_option( 'depay_wc_accepted_payments' ), + 'logs' => $last_logs ] ); $response->set_status( 200 ); diff --git a/includes/class-depay-wc-payments.php b/includes/class-depay-wc-payments.php index 11bddaf..a01fcf6 100644 --- a/includes/class-depay-wc-payments.php +++ b/includes/class-depay-wc-payments.php @@ -117,4 +117,9 @@ public static function init_rest_api() { $controller = new DePay_WC_Payments_Rest(); $controller->register_routes(); } + + public static function log( $text ) { + global $wpdb; + $wpdb->insert( 'wp_wc_depay_logs', array( 'log' => $text, 'created_at' => current_time( 'mysql' ) ) ); + } } diff --git a/languages/depay-woocommerce-payments.pot b/languages/depay-woocommerce-payments.pot index 2161b59..e3e0632 100644 --- a/languages/depay-woocommerce-payments.pot +++ b/languages/depay-woocommerce-payments.pot @@ -2,7 +2,7 @@ # This file is distributed under the same license as the package. msgid "" msgstr "" -"Project-Id-Version: DePay WooCommerce Payments 1.7.0\n" +"Project-Id-Version: DePay WooCommerce Payments 1.8.0\n" "Report-Msgid-Bugs-To: " "support@depay.com\n" "MIME-Version: 1.0\n" diff --git a/package.json b/package.json index aa61c47..85b7c4d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-woocommerce-depay-payments", "moduleName": "WooCommerceDePayPayments", - "version": "1.7.0", + "version": "1.8.0", "description": "WooCommerce DePay plugin to accept Web3 payments directly into your wallet with on-the-fly conversion.", "main": "./dist/umd/index.js", "module": "./dist/esm/index.js", diff --git a/readme.txt b/readme.txt index 08b2974..c1779f4 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: web3, payments, woocommerce, depay, cryptocurrency Requires at least: 5.8 Tested up to: 6.0 Requires PHP: 7.0 -Stable tag: 1.7.0 +Stable tag: 1.8.0 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html