mirror of
https://git.wownero.com/wownero/wownerowp.git
synced 2024-08-15 01:03:16 +00:00
Rewrite plugin to v3.0
This commit is contained in:
parent
4c091a13f7
commit
4def1b771e
37 changed files with 4613 additions and 1685 deletions
133
include/admin/class-monero-admin-interface.php
Normal file
133
include/admin/class-monero-admin-interface.php
Normal file
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright (c) 2018, Ryo Currency Project
|
||||
* Admin interface for Monero gateway
|
||||
* Authors: mosu-forge
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
require_once('class-monero-admin-payments-list.php');
|
||||
|
||||
if (class_exists('Monero_Admin_Interface', false)) {
|
||||
return new Monero_Admin_Interface();
|
||||
}
|
||||
|
||||
class Monero_Admin_Interface {
|
||||
|
||||
public function __construct() {
|
||||
add_action('add_meta_boxes', array($this, 'meta_boxes'));
|
||||
add_action('admin_menu', array($this, 'admin_menu'));
|
||||
add_action('admin_head', array( $this, 'admin_menu_update'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add meta boxes.
|
||||
*/
|
||||
public function meta_boxes() {
|
||||
add_meta_box(
|
||||
'monero_admin_order_details',
|
||||
__('Monero Gateway','monero_gateway'),
|
||||
array($this, 'meta_box_order_details'),
|
||||
'shop_order',
|
||||
'normal',
|
||||
'high'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Meta box for order page
|
||||
*/
|
||||
public function meta_box_order_details($order) {
|
||||
Monero_Gateway::admin_order_page($order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add menu items.
|
||||
*/
|
||||
public function admin_menu() {
|
||||
add_menu_page(
|
||||
__('Monero', 'monero_gateway'),
|
||||
__('Monero', 'monero_gateway'),
|
||||
'manage_woocommerce',
|
||||
'monero_gateway',
|
||||
array($this, 'orders_page'),
|
||||
MONERO_GATEWAY_PLUGIN_URL.'/assets/images/monero-icon-admin.png',
|
||||
56 // Position on menu, woocommerce has 55.5, products has 55.6
|
||||
);
|
||||
|
||||
add_submenu_page(
|
||||
'monero_gateway',
|
||||
__('Payments', 'monero_gateway'),
|
||||
__('Payments', 'monero_gateway'),
|
||||
'manage_woocommerce',
|
||||
'monero_gateway_payments',
|
||||
array($this, 'payments_page')
|
||||
);
|
||||
|
||||
$settings_page = add_submenu_page(
|
||||
'monero_gateway',
|
||||
__('Settings', 'monero_gateway'),
|
||||
__('Settings', 'monero_gateway'),
|
||||
'manage_options',
|
||||
'monero_gateway_settings',
|
||||
array($this, 'settings_page')
|
||||
);
|
||||
add_action('load-'.$settings_page, array($this, 'settings_page_init'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove duplicate sub-menu item
|
||||
*/
|
||||
public function admin_menu_update() {
|
||||
global $submenu;
|
||||
if (isset($submenu['monero_gateway'])) {
|
||||
unset($submenu['monero_gateway'][0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Monero payments page
|
||||
*/
|
||||
public function payments_page() {
|
||||
$payments_list = new Monero_Admin_Payments_List();
|
||||
$payments_list->prepare_items();
|
||||
$payments_list->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Monero settings page
|
||||
*/
|
||||
public function settings_page() {
|
||||
WC_Admin_Settings::output();
|
||||
}
|
||||
|
||||
public function settings_page_init() {
|
||||
global $current_tab, $current_section;
|
||||
|
||||
$current_section = 'monero_gateway';
|
||||
$current_tab = 'checkout';
|
||||
|
||||
// Include settings pages.
|
||||
WC_Admin_Settings::get_settings_pages();
|
||||
|
||||
// Save settings if data has been posted.
|
||||
if (apply_filters("woocommerce_save_settings_{$current_tab}_{$current_section}", !empty($_POST))) {
|
||||
WC_Admin_Settings::save();
|
||||
}
|
||||
|
||||
// Add any posted messages.
|
||||
if (!empty($_GET['wc_error'])) {
|
||||
WC_Admin_Settings::add_error(wp_kses_post(wp_unslash($_GET['wc_error'])));
|
||||
}
|
||||
|
||||
if (!empty($_GET['wc_message'])) {
|
||||
WC_Admin_Settings::add_message(wp_kses_post(wp_unslash($_GET['wc_message'])));
|
||||
}
|
||||
|
||||
do_action('woocommerce_settings_page_init');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return new Monero_Admin_Interface();
|
276
include/admin/class-monero-admin-payments-list.php
Normal file
276
include/admin/class-monero-admin-payments-list.php
Normal file
|
@ -0,0 +1,276 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright (c) 2018, Ryo Currency Project
|
||||
* Admin interface for Monero gateway
|
||||
* Authors: mosu-forge
|
||||
*/
|
||||
|
||||
if(!class_exists('WP_List_Table')) {
|
||||
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
|
||||
}
|
||||
|
||||
class Monero_Admin_Payments_List extends WP_List_Table {
|
||||
|
||||
function __construct() {
|
||||
parent::__construct(array(
|
||||
'singular'=> 'payment',
|
||||
'plural' => 'payments',
|
||||
'ajax' => false
|
||||
));
|
||||
}
|
||||
|
||||
function extra_tablenav($which) {
|
||||
if ($which == "top") {
|
||||
$hidden_fields = wp_nonce_field() . wp_referer_field();
|
||||
$tab_info = array(
|
||||
'all' => array(),
|
||||
'pending' => array(),
|
||||
'paid' => array(),
|
||||
'confirmed' => array(),
|
||||
'expired' => array(),
|
||||
);
|
||||
foreach($tab_info as $type=>&$info) {
|
||||
$info['active'] = '';
|
||||
$info['count'] = $this->get_item_count($type);
|
||||
}
|
||||
if(isset($_GET['type'])) {
|
||||
switch($_GET['type']) {
|
||||
case 'all':
|
||||
$tab_info['all']['active'] = 'class="current" aria-current="page"';
|
||||
break;
|
||||
case 'pending':
|
||||
$tab_info['pending']['active'] = 'class="current" aria-current="page"';
|
||||
break;
|
||||
case 'paid':
|
||||
$tab_info['paid']['active'] = 'class="current" aria-current="page"';
|
||||
break;
|
||||
case 'confirmed':
|
||||
$tab_info['confirmed']['active'] = 'class="current" aria-current="page"';
|
||||
break;
|
||||
case 'expired':
|
||||
$tab_info['expired']['active'] = 'class="current" aria-current="page"';
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$tab_info['all']['active'] = 'class="current" aria-current="page"';
|
||||
}
|
||||
if(Monero_Gateway::get_confirm_type() == 'monero-wallet-rpc') {
|
||||
$balance = Monero_Gateway::admin_balance_info();
|
||||
$balance_info = <<<HTML
|
||||
<div style="border:1px solid #ddd;padding:5px 10px;">
|
||||
Wallet height: {$balance['height']}</br>
|
||||
Your balance is: {$balance['balance']}</br>
|
||||
Unlocked balance: {$balance['unlocked_balance']}</br>
|
||||
</div>
|
||||
|
||||
HTML;
|
||||
} else {
|
||||
$balance_info = '';
|
||||
}
|
||||
echo <<<HTML
|
||||
<div class="wrap">
|
||||
<h1 class="wp-heading-inline">Monero Payments</h1>
|
||||
$balance_info
|
||||
<hr class="wp-header-end">
|
||||
<ul class="subsubsub">
|
||||
<li>
|
||||
<a href="?page=monero_gateway_payments&type=all" {$tab_info['all']['active']}>
|
||||
All <span class="count">({$tab_info['all']['count']})</span>
|
||||
</a> |
|
||||
</li>
|
||||
<li style="display:none">
|
||||
<a href="?page=monero_gateway_payments&type=pending" {$tab_info['pending']['active']}>
|
||||
Pending <span class="count">({$tab_info['pending']['count']})</span>
|
||||
</a> |
|
||||
</li>
|
||||
<li>
|
||||
<a href="?page=monero_gateway_payments&type=paid" {$tab_info['paid']['active']}>
|
||||
Received <span class="count">({$tab_info['paid']['count']})</span>
|
||||
</a> |
|
||||
</li>
|
||||
<li>
|
||||
<a href="?page=monero_gateway_payments&type=confirmed" {$tab_info['confirmed']['active']}>
|
||||
Confirmed <span class="count">({$tab_info['confirmed']['count']})</span>
|
||||
</a> |
|
||||
</li>
|
||||
<li>
|
||||
<a href="?page=monero_gateway_payments&type=expired" {$tab_info['expired']['active']}>
|
||||
Expired <span class="count">({$tab_info['expired']['count']})</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<form id="monero-payments-filter" method="get" style="display:none">
|
||||
<p class="search-box">
|
||||
<label class="screen-reader-text" for="post-search-input">Search payments:</label>
|
||||
<input type="search" id="post-search-input" name="s" value="">
|
||||
<input type="submit" id="search-submit" class="button" value="Search payments">
|
||||
</p>
|
||||
$hidden_fields
|
||||
</form>
|
||||
<h2 class="screen-reader-text">Monero Payments List</h2>
|
||||
<style>
|
||||
#col_order_id { width: 150px; }
|
||||
#col_payment_id { width: 150px; }
|
||||
#col_height { width: 100px; }
|
||||
#col_amount { width: 150px; }
|
||||
</style>
|
||||
<table class="wp-list-table widefat fixed striped posts">
|
||||
|
||||
HTML;
|
||||
} else if ($which == "bottom") {
|
||||
echo '<br class="clear"></div>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get column value.
|
||||
*
|
||||
* @param mixed $item Item being displayed.
|
||||
* @param string $column_name Column name.
|
||||
*/
|
||||
public function column_default($item, $column_name) {
|
||||
|
||||
switch($column_name) {
|
||||
case 'col_order_id':
|
||||
echo $this->get_order_link($item->order_id);
|
||||
break;
|
||||
case 'col_payment_id':
|
||||
echo $item->payment_id;
|
||||
break;
|
||||
case 'col_txid':
|
||||
$url = MONERO_GATEWAY_EXPLORER_URL.'/tx/'.$item->txid;
|
||||
echo '<a href="'.$url.'" target="_blank">'.$item->txid.'</a>';
|
||||
break;
|
||||
case 'col_height':
|
||||
echo $item->height;
|
||||
break;
|
||||
case 'col_amount':
|
||||
echo Monero_Gateway::format_monero($item->amount).' Monero';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected function get_order_link($order_id) {
|
||||
$order = new WC_Order($order_id);
|
||||
$buyer = '';
|
||||
|
||||
if($order->get_billing_first_name() || $order->get_billing_last_name()) {
|
||||
$buyer = trim(sprintf(_x('%1$s %2$s', 'full name', 'woocommerce'), $order->get_billing_first_name(), $order->get_billing_last_name()));
|
||||
} else if ($order->get_billing_company()) {
|
||||
$buyer = trim($order->get_billing_company());
|
||||
} else if ($order->get_customer_id()) {
|
||||
$user = get_user_by('id', $order->get_customer_id());
|
||||
$buyer = ucwords($user->display_name);
|
||||
}
|
||||
|
||||
return '<a href="' . esc_url( admin_url( 'post.php?post=' . absint( $order->get_id() ) ) . '&action=edit' ) . '" class="order-view"><strong>#' . esc_attr( $order->get_order_number() ) . ' ' . esc_html( $buyer ) . '</strong></a>';
|
||||
|
||||
}
|
||||
|
||||
function get_columns() {
|
||||
return $columns= array(
|
||||
'col_order_id' => __('Order'),
|
||||
'col_payment_id' => __('Payment ID'),
|
||||
'col_txid' => __('Txid'),
|
||||
'col_height' => __('Height'),
|
||||
'col_amount' => __('Amount'),
|
||||
);
|
||||
}
|
||||
|
||||
public function get_sortable_columns() {
|
||||
return array();
|
||||
return $sortable = array(
|
||||
'col_order_id' => 'col_order_id',
|
||||
'col_payment_id' => 'payment_id',
|
||||
'col_txid' => 'txid',
|
||||
'col_height' => 'height',
|
||||
'col_amount' => 'amount',
|
||||
);
|
||||
}
|
||||
|
||||
function prepare_items() {
|
||||
|
||||
$this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
|
||||
$current_page = absint($this->get_pagenum());
|
||||
|
||||
$per_page = 25;
|
||||
|
||||
$this->get_items($current_page, $per_page);
|
||||
|
||||
}
|
||||
|
||||
public function no_items() {
|
||||
esc_html_e('No Monero payments found', 'monero_gateway');
|
||||
}
|
||||
|
||||
protected function get_filter_vars() {
|
||||
$type = isset($_GET['type']) ? $_GET['type'] : null;
|
||||
return (object) array(
|
||||
'type' => $type,
|
||||
);
|
||||
}
|
||||
|
||||
protected function get_item_count($type) {
|
||||
global $wpdb;
|
||||
$table_name_1 = $wpdb->prefix.'monero_gateway_quotes';
|
||||
$table_name_2 = $wpdb->prefix.'monero_gateway_quotes_txids';
|
||||
$query_where = ' WHERE 1=1 '.$this->get_clause_type($type);
|
||||
$query = "SELECT COUNT(*) AS count FROM {$table_name_2} t2 LEFT JOIN $table_name_1 t1 ON t2.payment_id = t1.payment_id {$query_where}";
|
||||
$item_count = $wpdb->get_var($query);
|
||||
if(is_null($item_count)) $item_count = 0;
|
||||
return $item_count;
|
||||
}
|
||||
|
||||
protected function get_clause_type($type) {
|
||||
global $wpdb;
|
||||
switch($type) {
|
||||
case 'pending':
|
||||
$query_where = $wpdb->prepare(' AND pending = 1 AND paid = 0 ', array());
|
||||
break;
|
||||
case 'paid':
|
||||
$query_where = $wpdb->prepare(' AND paid = 1 AND confirmed = 0 ', array());
|
||||
break;
|
||||
case 'confirmed':
|
||||
$query_where = $wpdb->prepare(' AND confirmed = 1 ', array());
|
||||
break;
|
||||
case 'expired':
|
||||
$query_where = $wpdb->prepare(' AND paid = 0 AND pending = 0 ', array());
|
||||
break;
|
||||
case 'all':
|
||||
default:
|
||||
$query_where = ' ';
|
||||
}
|
||||
return $query_where;
|
||||
}
|
||||
|
||||
public function get_items($current_page, $per_page) {
|
||||
global $wpdb;
|
||||
|
||||
$this->items = array();
|
||||
$filters = $this->get_filter_vars();
|
||||
|
||||
$table_name_1 = $wpdb->prefix.'monero_gateway_quotes';
|
||||
$table_name_2 = $wpdb->prefix.'monero_gateway_quotes_txids';
|
||||
|
||||
$query_where = ' WHERE 1=1 ';
|
||||
|
||||
$query_where .= $this->get_clause_type($filters->type);
|
||||
|
||||
$query_order = $wpdb->prepare('ORDER BY id DESC LIMIT %d, %d;', ($current_page-1)*$per_page, $per_page);
|
||||
|
||||
$query = "SELECT t1.order_id, t1.confirmed, t1.paid, t1.pending, t2.* FROM {$table_name_2} t2 LEFT JOIN $table_name_1 t1 ON t2.payment_id = t1.payment_id {$query_where} {$query_order}";
|
||||
|
||||
$this->items = $wpdb->get_results($query);
|
||||
|
||||
$max_items = $this->get_item_count($filters->type);
|
||||
|
||||
$this->set_pagination_args(
|
||||
array(
|
||||
'total_items' => $max_items,
|
||||
'per_page' => $per_page,
|
||||
'total_pages' => ceil($max_items/$per_page),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
114
include/admin/monero-gateway-admin-settings.php
Normal file
114
include/admin/monero-gateway-admin-settings.php
Normal file
|
@ -0,0 +1,114 @@
|
|||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
return array(
|
||||
'enabled' => array(
|
||||
'title' => __('Enable / Disable', 'monero_gateway'),
|
||||
'label' => __('Enable this payment gateway', 'monero_gateway'),
|
||||
'type' => 'checkbox',
|
||||
'default' => 'no'
|
||||
),
|
||||
'title' => array(
|
||||
'title' => __('Title', 'monero_gateway'),
|
||||
'type' => 'text',
|
||||
'desc_tip' => __('Payment title the customer will see during the checkout process.', 'monero_gateway'),
|
||||
'default' => __('Monero Gateway', 'monero_gateway')
|
||||
),
|
||||
'description' => array(
|
||||
'title' => __('Description', 'monero_gateway'),
|
||||
'type' => 'textarea',
|
||||
'desc_tip' => __('Payment description the customer will see during the checkout process.', 'monero_gateway'),
|
||||
'default' => __('Pay securely using Monero. You will be provided payment details after checkout.', 'monero_gateway')
|
||||
),
|
||||
'discount' => array(
|
||||
'title' => __('Discount for using Monero', 'monero_gateway'),
|
||||
'desc_tip' => __('Provide a discount to your customers for making a private payment with Monero', 'monero_gateway'),
|
||||
'description' => __('Enter a percentage discount (i.e. 5 for 5%) or leave this empty if you do not wish to provide a discount', 'monero_gateway'),
|
||||
'type' => __('number'),
|
||||
'default' => '0'
|
||||
),
|
||||
'valid_time' => array(
|
||||
'title' => __('Order valid time', 'monero_gateway'),
|
||||
'desc_tip' => __('Amount of time order is valid before expiring', 'monero_gateway'),
|
||||
'description' => __('Enter the number of seconds that the funds must be received in after order is placed. 3600 seconds = 1 hour', 'monero_gateway'),
|
||||
'type' => __('number'),
|
||||
'default' => '3600'
|
||||
),
|
||||
'confirms' => array(
|
||||
'title' => __('Number of confirmations', 'monero_gateway'),
|
||||
'desc_tip' => __('Number of confirms a transaction must have to be valid', 'monero_gateway'),
|
||||
'description' => __('Enter the number of confirms that transactions must have. Enter 0 to zero-confim. Each confirm will take approximately four minutes', 'monero_gateway'),
|
||||
'type' => __('number'),
|
||||
'default' => '5'
|
||||
),
|
||||
'confirm_type' => array(
|
||||
'title' => __('Confirmation Type', 'monero_gateway'),
|
||||
'desc_tip' => __('Select the method for confirming transactions', 'monero_gateway'),
|
||||
'description' => __('Select the method for confirming transactions', 'monero_gateway'),
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'viewkey' => __('viewkey', 'monero_gateway'),
|
||||
'monero-wallet-rpc' => __('monero-wallet-rpc', 'monero_gateway')
|
||||
),
|
||||
'default' => 'viewkey'
|
||||
),
|
||||
'monero_address' => array(
|
||||
'title' => __('Monero Address', 'monero_gateway'),
|
||||
'label' => __('Useful for people that have not a daemon online'),
|
||||
'type' => 'text',
|
||||
'desc_tip' => __('Monero Wallet Address (MoneroL)', 'monero_gateway')
|
||||
),
|
||||
'viewkey' => array(
|
||||
'title' => __('Secret Viewkey', 'monero_gateway'),
|
||||
'label' => __('Secret Viewkey'),
|
||||
'type' => 'text',
|
||||
'desc_tip' => __('Your secret Viewkey', 'monero_gateway')
|
||||
),
|
||||
'daemon_host' => array(
|
||||
'title' => __('Monero wallet RPC Host/IP', 'monero_gateway'),
|
||||
'type' => 'text',
|
||||
'desc_tip' => __('This is the Daemon Host/IP to authorize the payment with', 'monero_gateway'),
|
||||
'default' => '127.0.0.1',
|
||||
),
|
||||
'daemon_port' => array(
|
||||
'title' => __('Monero wallet RPC port', 'monero_gateway'),
|
||||
'type' => __('number'),
|
||||
'desc_tip' => __('This is the Wallet RPC port to authorize the payment with', 'monero_gateway'),
|
||||
'default' => '18080',
|
||||
),
|
||||
'testnet' => array(
|
||||
'title' => __(' Testnet', 'monero_gateway'),
|
||||
'label' => __(' Check this if you are using testnet ', 'monero_gateway'),
|
||||
'type' => 'checkbox',
|
||||
'description' => __('Advanced usage only', 'monero_gateway'),
|
||||
'default' => 'no'
|
||||
),
|
||||
'onion_service' => array(
|
||||
'title' => __(' SSL warnings ', 'monero_gateway'),
|
||||
'label' => __(' Check to Silence SSL warnings', 'monero_gateway'),
|
||||
'type' => 'checkbox',
|
||||
'description' => __('Check this box if you are running on an Onion Service (Suppress SSL errors)', 'monero_gateway'),
|
||||
'default' => 'no'
|
||||
),
|
||||
'show_qr' => array(
|
||||
'title' => __('Show QR Code', 'monero_gateway'),
|
||||
'label' => __('Show QR Code', 'monero_gateway'),
|
||||
'type' => 'checkbox',
|
||||
'description' => __('Enable this to show a QR code after checkout with payment details.'),
|
||||
'default' => 'no'
|
||||
),
|
||||
'use_monero_price' => array(
|
||||
'title' => __('Show Prices in Monero', 'monero_gateway'),
|
||||
'label' => __('Show Prices in Monero', 'monero_gateway'),
|
||||
'type' => 'checkbox',
|
||||
'description' => __('Enable this to convert ALL prices on the frontend to Monero (experimental)'),
|
||||
'default' => 'no'
|
||||
),
|
||||
'use_monero_price_decimals' => array(
|
||||
'title' => __('Display Decimals', 'monero_gateway'),
|
||||
'type' => __('number'),
|
||||
'description' => __('Number of decimal places to display on frontend. Upon checkout exact price will be displayed.'),
|
||||
'default' => 12,
|
||||
),
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue