Skip to content

Commit

Permalink
v1.8.0: adds logs
Browse files Browse the repository at this point in the history
  • Loading branch information
10xSebastian committed Dec 12, 2022
1 parent d6c5d94 commit 2d438f0
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 7 deletions.
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -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

Expand Down
10 changes: 8 additions & 2 deletions depay-woocommerce-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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';

Expand All @@ -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,
Expand Down
13 changes: 11 additions & 2 deletions includes/class-depay-wc-payments-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, [
Expand Down
5 changes: 5 additions & 0 deletions includes/class-depay-wc-payments-rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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( [] ),
Expand All @@ -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,
Expand All @@ -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 );

Expand Down
5 changes: 5 additions & 0 deletions includes/class-depay-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) ) );
}
}
2 changes: 1 addition & 1 deletion languages/depay-woocommerce-payments.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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: "
"[email protected]\n"
"MIME-Version: 1.0\n"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2d438f0

Please sign in to comment.