This commit is contained in:
Lenny Ovo 2018-11-21 19:44:02 +00:00
parent ad6fe196a6
commit 76318e09e4
32 changed files with 825 additions and 797 deletions

View file

@ -1,8 +1,8 @@
# Monero Gateway for WooCommerce
# Wownero Gateway for WooCommerce
## Features
* Payment validation done through either `monero-wallet-rpc` or the [xmrchain.net blockchain explorer](https://xmrchain.net/).
* Payment validation done through either `wownero-wallet-rpc` or the [explore.wownero.com blockchain explorer](https://explore.wownero.com/).
* Validates payments with `cron`, so does not require users to stay on the order confirmation page for their order to validate.
* Order status updates are done through AJAX instead of Javascript page reloads.
* Customers can pay with multiple transactions and are notified as soon as transactions hit the mempool.
@ -10,60 +10,60 @@
* Live price updates every minute; total amount due is locked in after the order is placed for a configurable amount of time (default 60 minutes) so the price does not change after order has been made.
* Hooks into emails, order confirmation page, customer order history page, and admin order details page.
* View all payments received to your wallet with links to the blockchain explorer and associated orders.
* Optionally display all prices on your store in terms of Monero.
* Optionally display all prices on your store in terms of Wownero.
* Shortcodes! Display exchange rates in numerous currencies.
## Requirements
* Monero wallet to receive payments - [GUI](https://github.com/monero-project/monero-gui/releases) - [CLI](https://github.com/monero-project/monero/releases) - [Paper](https://moneroaddress.org/)
* Wownero wallet to receive payments - [GUI](https://github.com/wownero/wownero/releases)
* [BCMath](http://php.net/manual/en/book.bc.php) - A PHP extension used for arbitrary precision maths
## Installing the plugin
* Download the plugin from the [releases page](https://github.com/monero-integrations/monerowp) or clone with `git clone https://github.com/monero-integrations/monerowp`
* Unzip or place the `monero-woocommerce-gateway` folder in the `wp-content/plugins` directory.
* Activate "Monero Woocommerce Gateway" in your WordPress admin dashboard.
* Download the plugin from the [releases page](https://github.com/itssteven/monerowp) or clone with `git clone https://github.com/itssteven/monerowp`
* Unzip or place the `wownero-woocommerce-gateway` folder in the `wp-content/plugins` directory.
* Activate "Wownero Woocommerce Gateway" in your WordPress admin dashboard.
* It is highly recommended that you use native cronjobs instead of WordPress's "Poor Man's Cron" by adding `define('DISABLE_WP_CRON', true);` into your `wp-config.php` file and adding `* * * * * wget -q -O - https://yourstore.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1` to your crontab.
## Option 1: Use your wallet address and viewkey
This is the easiest way to start accepting Monero on your website. You'll need:
This is the easiest way to start accepting Wownero on your website. You'll need:
* Your Monero wallet address starting with `4`
* Your Wownero wallet address starting with `W`
* Your wallet's secret viewkey
Then simply select the `viewkey` option in the settings page and paste your address and viewkey. You're all set!
Note on privacy: when you validate transactions with your private viewkey, your viewkey is sent to (but not stored on) xmrchain.net over HTTPS. This could potentially allow an attacker to see your incoming, but not outgoing, transactions if they were to get his hands on your viewkey. Even if this were to happen, your funds would still be safe and it would be impossible for somebody to steal your money. For maximum privacy use your own `monero-wallet-rpc` instance.
Note on privacy: when you validate transactions with your private viewkey, your viewkey is sent to (but not stored on) xmrchain.net over HTTPS. This could potentially allow an attacker to see your incoming, but not outgoing, transactions if they were to get his hands on your viewkey. Even if this were to happen, your funds would still be safe and it would be impossible for somebody to steal your money. For maximum privacy use your own `wownero-wallet-rpc` instance.
## Option 2: Using `monero-wallet-rpc`
## Option 2: Using `wownero-wallet-rpc`
The most secure way to accept Monero on your website. You'll need:
The most secure way to accept Wownero on your website. You'll need:
* Root access to your webserver
* Latest [Monero-currency binaries](https://github.com/monero-project/monero/releases)
* Latest [Wownero-currency binaries](https://github.com/wownero/wownero/releases)
After downloading (or compiling) the Monero binaries on your server, install the [systemd unit files](https://github.com/monero-integrations/monerowp/tree/master/assets/systemd-unit-files) or run `monerod` and `monero-wallet-rpc` with `screen` or `tmux`. You can skip running `monerod` by using a remote node with `monero-wallet-rpc` by adding `--daemon-address node.moneroworld.com:18089` to the `monero-wallet-rpc.service` file.
After downloading (or compiling) the Wownero binaries on your server, install the [systemd unit files](https://github.com/monero-integrations/monerowp/tree/master/assets/systemd-unit-files) or run `wownerod` and `wownero-wallet-rpc` with `screen` or `tmux`. You can skip running `wownerod` by using a remote node with `wownero-wallet-rpc` by adding `--daemon-address node.wowne.ro:34568` to the `wownero-wallet-rpc.service` file.
Note on security: using this option, while the most secure, requires you to run the Monero wallet RPC program on your server. Best practice for this is to use a view-only wallet since otherwise your server would be running a hot-wallet and a security breach could allow hackers to empty your funds.
Note on security: using this option, while the most secure, requires you to run the Wownero wallet RPC program on your server. Best practice for this is to use a view-only wallet since otherwise your server would be running a hot-wallet and a security breach could allow hackers to empty your funds.
## Configuration
* `Enable / Disable` - Turn on or off Monero gateway. (Default: Disable)
* `Title` - Name of the payment gateway as displayed to the customer. (Default: Monero Gateway)
* `Discount for using Monero` - Percentage discount applied to orders for paying with Monero. Can also be negative to apply a surcharge. (Default: 0)
* `Enable / Disable` - Turn on or off Wownero gateway. (Default: Disable)
* `Title` - Name of the payment gateway as displayed to the customer. (Default: Wownero Gateway)
* `Discount for using Wownero` - Percentage discount applied to orders for paying with Wownero. Can also be negative to apply a surcharge. (Default: 0)
* `Order valid time` - Number of seconds after order is placed that the transaction must be seen in the mempool. (Default: 3600 [1 hour])
* `Number of confirmations` - Number of confirmations the transaction must recieve before the order is marked as complete. Use `0` for nearly instant confirmation. (Default: 5)
* `Confirmation Type` - Confirm transactions with either your viewkey, or by using `monero-wallet-rpc`. (Default: viewkey)
* `Monero Address` (if confirmation type is viewkey) - Your public Monero address starting with 4. (No default)
* `Confirmation Type` - Confirm transactions with either your viewkey, or by using `wownero-wallet-rpc`. (Default: viewkey)
* `Wownero Address` (if confirmation type is viewkey) - Your public Wownero address starting with 4. (No default)
* `Secret Viewkey` (if confirmation type is viewkey) - Your *private* viewkey (No default)
* `Monero wallet RPC Host/IP` (if confirmation type is `monero-wallet-rpc`) - IP address where the wallet rpc is running. It is highly discouraged to run the wallet anywhere other than the local server! (Default: 127.0.0.1)
* `Monero wallet RPC port` (if confirmation type is `monero-wallet-rpc`) - Port the wallet rpc is bound to with the `--rpc-bind-port` argument. (Default 18080)
* `Wownero wallet RPC Host/IP` (if confirmation type is `wownero-wallet-rpc`) - IP address where the wallet rpc is running. It is highly discouraged to run the wallet anywhere other than the local server! (Default: 127.0.0.1)
* `Wownero wallet RPC port` (if confirmation type is `wownero-wallet-rpc`) - Port the wallet rpc is bound to with the `--rpc-bind-port` argument. (Default 18080)
* `Testnet` - Check this to change the blockchain explorer links to the testnet explorer. (Default: unchecked)
* `SSL warnings` - Check this to silence SSL warnings. (Default: unchecked)
* `Show QR Code` - Show payment QR codes. There is no Monero software that can read QR codes at this time (Default: unchecked)
* `Show Prices in Monero` - Convert all prices on the frontend to Monero. Experimental feature, only use if you do not accept any other payment option. (Default: unchecked)
* `Display Decimals` (if show prices in Monero is enabled) - Number of decimals to round prices to on the frontend. The final order amount will not be rounded and will be displayed down to the nanoMonero. (Default: 12)
* `Show QR Code` - Show payment QR codes. There is no Wownero software that can read QR codes at this time (Default: unchecked)
* `Show Prices in Wownero` - Convert all prices on the frontend to Wownero. Experimental feature, only use if you do not accept any other payment option. (Default: unchecked)
* `Display Decimals` (if show prices in Wownero is enabled) - Number of decimals to round prices to on the frontend. The final order amount will not be rounded and will be displayed down to the nanoWownero. (Default: 11)
## Shortcodes
@ -71,35 +71,36 @@ This plugin makes available two shortcodes that you can use in your theme.
#### Live price shortcode
This will display the price of Monero in the selected currency. If no currency is provided, the store's default currency will be used.
This will display the price of Wownero in the selected currency. If no currency is provided, the store's default currency will be used.
```
[monero-price]
[monero-price currency="BTC"]
[monero-price currency="USD"]
[monero-price currency="CAD"]
[monero-price currency="EUR"]
[monero-price currency="GBP"]
[wownero-price]
[wownero-price currency="BTC"]
[wownero-price currency="USD"]
[wownero-price currency="CAD"]
[wownero-price currency="EUR"]
[wownero-price currency="GBP"]
```
Will display:
```
1 XMR = 123.68000 USD
1 XMR = 0.01827000 BTC
1 XMR = 123.68000 USD
1 XMR = 168.43000 CAD
1 XMR = 105.54000 EUR
1 XMR = 94.84000 GBP
1 WOW = 123.68000 USD
1 WOW = 0.01827000 BTC
1 WOW = 123.68000 USD
1 WOW = 168.43000 CAD
1 WOW = 105.54000 EUR
1 WOW = 94.84000 GBP
```
#### Monero accepted here badge
#### Wownero accepted here badge
This will display a badge showing that you accept Monero-currency.
This will display a badge showing that you accept Wownero-currency.
`[monero-accepted-here]`
`[wownero-accepted-here]`
![Monero Accepted Here](/assets/images/monero-accepted-here.png?raw=true "Monero Accepted Here")
![Wownero Accepted Here](/assets/images/wownero-accepted-here.png?raw=true "Wownero Accepted Here")
## Donations
monero-integrations: 44krVcL6TPkANjpFwS2GWvg1kJhTrN7y9heVeQiDJ3rP8iGbCd5GeA4f3c2NKYHC1R4mCgnW7dsUUUae2m9GiNBGT4T8s2X
guy who converted it to wownero: Wo57gnyJUihhnfpr7rbjv8Q9eJ8igcbyFPtbPogbLoGaLrYCV3RZHANc1SCJoL3WkCD6XGHbVaWYminF6rCzei6Y1Bhix1iRn

View file

@ -1,26 +1,26 @@
#monero_payment_messages > span {
#wownero_payment_messages > span {
display:none;
}
.monero_details_row {
.wownero_details_row {
display: flex !important;
align-items: center;
margin:0 -8px;
}
.monero_details_row > * {
.wownero_details_row > * {
padding:0 8px;
}
.monero_details_left {
.wownero_details_left {
}
.monero_details_main {
.wownero_details_main {
flex-grow: 1;
word-break:break-all;
}
.monero_details_right.button-row {
.wownero_details_right.button-row {
display:flex;
margin-top: 5px;
align-self: self-start;
}
.monero_details_right.button-row button {
.wownero_details_right.button-row button {
width: 32px;
height: 32px;
padding: 6px 2px;
@ -28,10 +28,10 @@
line-height:28px;
text-align:center;
}
#monero_integrated_address {
#wownero_integrated_address {
line-height: 16px;
}
#monero_qr_code_container {
#wownero_qr_code_container {
position:fixed;
top:0;
left:0;
@ -40,7 +40,7 @@
z-index:9999;
background:rgba(0,0,0,0.5);
}
#monero_qr_code {
#wownero_qr_code {
position: absolute;
width: 256px;
height: 256px;
@ -52,13 +52,13 @@
background: white;
border-radius: 5px;
}
#monero_toast {
#wownero_toast {
position: fixed;
z-index: 999;
top: 32px;
right: 12px;
}
#monero_toast > div {
#wownero_toast > div {
display: block;
position: relative;
overflow: hidden;
@ -70,9 +70,9 @@
color: white;
right: -400px;
}
#monero_toast > div.success {
#wownero_toast > div.success {
background: rgba(68, 190, 117, 0.8);
}
#monero_toast > div.error {
#wownero_toast > div.error {
background: rgba(195, 60, 60, 0.8);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 413 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 377 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4 KiB

View file

@ -1,161 +0,0 @@
/*
* Copyright (c) 2018, Ryo Currency Project
*/
function monero_showNotification(message, type='success') {
var toast = jQuery('<div class="' + type + '"><span>' + message + '</span></div>');
jQuery('#monero_toast').append(toast);
toast.animate({ "right": "12px" }, "fast");
setInterval(function() {
toast.animate({ "right": "-400px" }, "fast", function() {
toast.remove();
});
}, 2500)
}
function monero_showQR(show=true) {
jQuery('#monero_qr_code_container').toggle(show);
}
function monero_fetchDetails() {
var data = {
'_': jQuery.now(),
'order_id': monero_details.order_id
};
jQuery.get(monero_ajax_url, data, function(response) {
if (typeof response.error !== 'undefined') {
console.log(response.error);
} else {
monero_details = response;
monero_updateDetails();
}
});
}
function monero_updateDetails() {
var details = monero_details;
jQuery('#monero_payment_messages').children().hide();
switch(details.status) {
case 'unpaid':
jQuery('.monero_payment_unpaid').show();
jQuery('.monero_payment_expire_time').html(details.order_expires);
break;
case 'partial':
jQuery('.monero_payment_partial').show();
jQuery('.monero_payment_expire_time').html(details.order_expires);
break;
case 'paid':
jQuery('.monero_payment_paid').show();
jQuery('.monero_confirm_time').html(details.time_to_confirm);
jQuery('.button-row button').prop("disabled",true);
break;
case 'confirmed':
jQuery('.monero_payment_confirmed').show();
jQuery('.button-row button').prop("disabled",true);
break;
case 'expired':
jQuery('.monero_payment_expired').show();
jQuery('.button-row button').prop("disabled",true);
break;
case 'expired_partial':
jQuery('.monero_payment_expired_partial').show();
jQuery('.button-row button').prop("disabled",true);
break;
}
jQuery('#monero_exchange_rate').html('1 XMR = '+details.rate_formatted+' '+details.currency);
jQuery('#monero_total_amount').html(details.amount_total_formatted);
jQuery('#monero_total_paid').html(details.amount_paid_formatted);
jQuery('#monero_total_due').html(details.amount_due_formatted);
jQuery('#monero_integrated_address').html(details.integrated_address);
if(monero_show_qr) {
var qr = jQuery('#monero_qr_code').html('');
new QRCode(qr.get(0), details.qrcode_uri);
}
if(details.txs.length) {
jQuery('#monero_tx_table').show();
jQuery('#monero_tx_none').hide();
jQuery('#monero_tx_table tbody').html('');
for(var i=0; i < details.txs.length; i++) {
var tx = details.txs[i];
var height = tx.height == 0 ? 'N/A' : tx.height;
var row = ''+
'<tr>'+
'<td style="word-break: break-all">'+
'<a href="'+monero_explorer_url+'/tx/'+tx.txid+'" target="_blank">'+tx.txid+'</a>'+
'</td>'+
'<td>'+height+'</td>'+
'<td>'+tx.amount_formatted+' Monero</td>'+
'</tr>';
jQuery('#monero_tx_table tbody').append(row);
}
} else {
jQuery('#monero_tx_table').hide();
jQuery('#monero_tx_none').show();
}
// Show state change notifications
var new_txs = details.txs;
var old_txs = monero_order_state.txs;
if(new_txs.length != old_txs.length) {
for(var i = 0; i < new_txs.length; i++) {
var is_new_tx = true;
for(var j = 0; j < old_txs.length; j++) {
if(new_txs[i].txid == old_txs[j].txid && new_txs[i].amount == old_txs[j].amount) {
is_new_tx = false;
break;
}
}
if(is_new_tx) {
monero_showNotification('Transaction received for '+new_txs[i].amount_formatted+' Monero');
}
}
}
if(details.status != monero_order_state.status) {
switch(details.status) {
case 'paid':
monero_showNotification('Your order has been paid in full');
break;
case 'confirmed':
monero_showNotification('Your order has been confirmed');
break;
case 'expired':
case 'expired_partial':
monero_showNotification('Your order has expired', 'error');
break;
}
}
monero_order_state = {
status: monero_details.status,
txs: monero_details.txs
};
}
jQuery(document).ready(function($) {
if (typeof monero_details !== 'undefined') {
monero_order_state = {
status: monero_details.status,
txs: monero_details.txs
};
setInterval(monero_fetchDetails, 30000);
monero_updateDetails();
new ClipboardJS('.clipboard').on('success', function(e) {
e.clearSelection();
if(e.trigger.disabled) return;
switch(e.trigger.getAttribute('data-clipboard-target')) {
case '#monero_integrated_address':
monero_showNotification('Copied destination address!');
break;
case '#monero_total_due':
monero_showNotification('Copied total amount due!');
break;
}
e.clearSelection();
});
}
});

View file

@ -0,0 +1,161 @@
/*
* Copyright (c) 2018, Ryo Currency Project
*/
function wownero_showNotification(message, type='success') {
var toast = jQuery('<div class="' + type + '"><span>' + message + '</span></div>');
jQuery('#wownero_toast').append(toast);
toast.animate({ "right": "12px" }, "fast");
setInterval(function() {
toast.animate({ "right": "-400px" }, "fast", function() {
toast.remove();
});
}, 2500)
}
function wownero_showQR(show=true) {
jQuery('#wownero_qr_code_container').toggle(show);
}
function wownero_fetchDetails() {
var data = {
'_': jQuery.now(),
'order_id': wownero_details.order_id
};
jQuery.get(wownero_ajax_url, data, function(response) {
if (typeof response.error !== 'undefined') {
console.log(response.error);
} else {
wownero_details = response;
wownero_updateDetails();
}
});
}
function wownero_updateDetails() {
var details = wownero_details;
jQuery('#wownero_payment_messages').children().hide();
switch(details.status) {
case 'unpaid':
jQuery('.wownero_payment_unpaid').show();
jQuery('.wownero_payment_expire_time').html(details.order_expires);
break;
case 'partial':
jQuery('.wownero_payment_partial').show();
jQuery('.wownero_payment_expire_time').html(details.order_expires);
break;
case 'paid':
jQuery('.wownero_payment_paid').show();
jQuery('.wownero_confirm_time').html(details.time_to_confirm);
jQuery('.button-row button').prop("disabled",true);
break;
case 'confirmed':
jQuery('.wownero_payment_confirmed').show();
jQuery('.button-row button').prop("disabled",true);
break;
case 'expired':
jQuery('.wownero_payment_expired').show();
jQuery('.button-row button').prop("disabled",true);
break;
case 'expired_partial':
jQuery('.wownero_payment_expired_partial').show();
jQuery('.button-row button').prop("disabled",true);
break;
}
jQuery('#wownero_exchange_rate').html('1 WOW = '+details.rate_formatted+' '+details.currency);
jQuery('#wownero_total_amount').html(details.amount_total_formatted);
jQuery('#wownero_total_paid').html(details.amount_paid_formatted);
jQuery('#wownero_total_due').html(details.amount_due_formatted);
jQuery('#wownero_integrated_address').html(details.integrated_address);
if(wownero_show_qr) {
var qr = jQuery('#wownero_qr_code').html('');
new QRCode(qr.get(0), details.qrcode_uri);
}
if(details.txs.length) {
jQuery('#wownero_tx_table').show();
jQuery('#wownero_tx_none').hide();
jQuery('#wownero_tx_table tbody').html('');
for(var i=0; i < details.txs.length; i++) {
var tx = details.txs[i];
var height = tx.height == 0 ? 'N/A' : tx.height;
var row = ''+
'<tr>'+
'<td style="word-break: break-all">'+
'<a href="'+wownero_explorer_url+'/tx/'+tx.txid+'" target="_blank">'+tx.txid+'</a>'+
'</td>'+
'<td>'+height+'</td>'+
'<td>'+tx.amount_formatted+' wownero</td>'+
'</tr>';
jQuery('#wownero_tx_table tbody').append(row);
}
} else {
jQuery('#wownero_tx_table').hide();
jQuery('#wownero_tx_none').show();
}
// Show state change notifications
var new_txs = details.txs;
var old_txs = wownero_order_state.txs;
if(new_txs.length != old_txs.length) {
for(var i = 0; i < new_txs.length; i++) {
var is_new_tx = true;
for(var j = 0; j < old_txs.length; j++) {
if(new_txs[i].txid == old_txs[j].txid && new_txs[i].amount == old_txs[j].amount) {
is_new_tx = false;
break;
}
}
if(is_new_tx) {
wownero_showNotification('Transaction received for '+new_txs[i].amount_formatted+' wownero');
}
}
}
if(details.status != wownero_order_state.status) {
switch(details.status) {
case 'paid':
wownero_showNotification('Your order has been paid in full');
break;
case 'confirmed':
wownero_showNotification('Your order has been confirmed');
break;
case 'expired':
case 'expired_partial':
wownero_showNotification('Your order has expired', 'error');
break;
}
}
wownero_order_state = {
status: wownero_details.status,
txs: wownero_details.txs
};
}
jQuery(document).ready(function($) {
if (typeof wownero_details !== 'undefined') {
wownero_order_state = {
status: wownero_details.status,
txs: wownero_details.txs
};
setInterval(wownero_fetchDetails, 30000);
wownero_updateDetails();
new ClipboardJS('.clipboard').on('success', function(e) {
e.clearSelection();
if(e.trigger.disabled) return;
switch(e.trigger.getAttribute('data-clipboard-target')) {
case '#wownero_integrated_address':
wownero_showNotification('Copied destination address!');
break;
case '#wownero_total_due':
wownero_showNotification('Copied total amount due!');
break;
}
e.clearSelection();
});
}
});

View file

@ -1,14 +0,0 @@
[Unit]
Description=Monero Wallet RPC
After=network.target monerod.service
[Service]
User=moneroservices
Group=moneroservices
WorkingDirectory=/opt/monero-wallets
Type=simple
ExecStart=/opt/monero-bin/monero-wallet-rpc --wallet-file /opt/monero-wallets/woocommerce --rpc-bind-port 18080 --password-file /opt/monero-wallets/woocommerce.password --disable-rpc-login --log-file /var/log/monero-wallet.log
Restart=always
[Install]
WantedBy=multi-user.target

View file

@ -1,14 +0,0 @@
[Unit]
Description=Monero Full Node
After=network.target
[Service]
User=moneroservices
Group=moneroservices
WorkingDirectory=/opt/monero-data-dir
Type=simple
LimitNOFILE=65535
ExecStart=/usr/bin/monerod --log-file /var/log/monerod.log --data-dir /opt/monero-data-dir --non-interactive
Restart=always
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,14 @@
[Unit]
Description=Wownero Wallet RPC
After=network.target wownerod.service
[Service]
User=wowneroservices
Group=wowneroservices
WorkingDirectory=/opt/wownero-wallets
Type=simple
ExecStart=/opt/wownero-bin/wownero-wallet-rpc --wallet-file /opt/wownero-wallets/woocommerce --rpc-bind-port 18080 --password-file /opt/wownero-wallets/woocommerce.password --disable-rpc-login --log-file /var/log/wownero-wallet.log
Restart=always
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,14 @@
[Unit]
Description=Wownero Full Node
After=network.target
[Service]
User=wowneroservices
Group=wowneroservices
WorkingDirectory=/opt/wownero-data-dir
Type=simple
LimitNOFILE=65535
ExecStart=/usr/bin/wownerod --log-file /var/log/wownerod.log --data-dir /opt/wownero-data-dir --non-interactive
Restart=always
[Install]
WantedBy=multi-user.target

View file

@ -1,19 +1,19 @@
<?php
/*
* Copyright (c) 2018, Ryo Currency Project
* Admin interface for Monero gateway
* Admin interface for Wownero gateway
* Authors: mosu-forge
*/
defined( 'ABSPATH' ) || exit;
require_once('class-monero-admin-payments-list.php');
require_once('class-wownero-admin-payments-list.php');
if (class_exists('Monero_Admin_Interface', false)) {
return new Monero_Admin_Interface();
if (class_exists('Wownero_Admin_Interface', false)) {
return new Wownero_Admin_Interface();
}
class Monero_Admin_Interface {
class Wownero_Admin_Interface {
public function __construct() {
add_action('add_meta_boxes', array($this, 'meta_boxes'));
@ -26,8 +26,8 @@ class Monero_Admin_Interface {
*/
public function meta_boxes() {
add_meta_box(
'monero_admin_order_details',
__('Monero Gateway','monero_gateway'),
'wownero_admin_order_details',
__('Wownero Gateway','wownero_gateway'),
array($this, 'meta_box_order_details'),
'shop_order',
'normal',
@ -39,7 +39,7 @@ class Monero_Admin_Interface {
* Meta box for order page
*/
public function meta_box_order_details($order) {
Monero_Gateway::admin_order_page($order);
Wownero_Gateway::admin_order_page($order);
}
/**
@ -47,30 +47,30 @@ class Monero_Admin_Interface {
*/
public function admin_menu() {
add_menu_page(
__('Monero', 'monero_gateway'),
__('Monero', 'monero_gateway'),
__('Wownero', 'wownero_gateway'),
__('Wownero', 'wownero_gateway'),
'manage_woocommerce',
'monero_gateway',
'wownero_gateway',
array($this, 'orders_page'),
MONERO_GATEWAY_PLUGIN_URL.'/assets/images/monero-icon-admin.png',
MONERO_GATEWAY_PLUGIN_URL.'/assets/images/wownero-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'),
'wownero_gateway',
__('Payments', 'wownero_gateway'),
__('Payments', 'wownero_gateway'),
'manage_woocommerce',
'monero_gateway_payments',
'wownero_gateway_payments',
array($this, 'payments_page')
);
$settings_page = add_submenu_page(
'monero_gateway',
__('Settings', 'monero_gateway'),
__('Settings', 'monero_gateway'),
'wownero_gateway',
__('Settings', 'wownero_gateway'),
__('Settings', 'wownero_gateway'),
'manage_options',
'monero_gateway_settings',
'wownero_gateway_settings',
array($this, 'settings_page')
);
add_action('load-'.$settings_page, array($this, 'settings_page_init'));
@ -81,22 +81,22 @@ class Monero_Admin_Interface {
*/
public function admin_menu_update() {
global $submenu;
if (isset($submenu['monero_gateway'])) {
unset($submenu['monero_gateway'][0]);
if (isset($submenu['wownero_gateway'])) {
unset($submenu['wownero_gateway'][0]);
}
}
/**
* Monero payments page
* Wownero payments page
*/
public function payments_page() {
$payments_list = new Monero_Admin_Payments_List();
$payments_list = new Wownero_Admin_Payments_List();
$payments_list->prepare_items();
$payments_list->display();
}
/**
* Monero settings page
* Wownero settings page
*/
public function settings_page() {
WC_Admin_Settings::output();
@ -105,7 +105,7 @@ class Monero_Admin_Interface {
public function settings_page_init() {
global $current_tab, $current_section;
$current_section = 'monero_gateway';
$current_section = 'wownero_gateway';
$current_tab = 'checkout';
// Include settings pages.
@ -130,4 +130,4 @@ class Monero_Admin_Interface {
}
return new Monero_Admin_Interface();
return new Wownero_Admin_Interface();

View file

@ -1,7 +1,7 @@
<?php
/*
* Copyright (c) 2018, Ryo Currency Project
* Admin interface for Monero gateway
* Admin interface for Wownero gateway
* Authors: mosu-forge
*/
@ -9,7 +9,7 @@ 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 {
class Wownero_Admin_Payments_List extends WP_List_Table {
function __construct() {
parent::__construct(array(
@ -54,8 +54,8 @@ class Monero_Admin_Payments_List extends WP_List_Table {
} 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();
if(Wownero_Gateway::get_confirm_type() == 'wownero-wallet-rpc') {
$balance = Wownero_Gateway::admin_balance_info();
$balance_info = <<<HTML
<div style="border:1px solid #ddd;padding:5px 10px;">
Wallet height: {$balance['height']}</br>
@ -69,37 +69,37 @@ HTML;
}
echo <<<HTML
<div class="wrap">
<h1 class="wp-heading-inline">Monero Payments</h1>
<h1 class="wp-heading-inline">Wownero 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']}>
<a href="?page=wownero_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']}>
<a href="?page=wownero_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']}>
<a href="?page=wownero_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']}>
<a href="?page=wownero_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']}>
<a href="?page=wownero_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">
<form id="wownero-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="">
@ -107,7 +107,7 @@ HTML;
</p>
$hidden_fields
</form>
<h2 class="screen-reader-text">Monero Payments List</h2>
<h2 class="screen-reader-text">Wownero Payments List</h2>
<style>
#col_order_id { width: 150px; }
#col_payment_id { width: 150px; }
@ -145,7 +145,7 @@ HTML;
echo $item->height;
break;
case 'col_amount':
echo Monero_Gateway::format_monero($item->amount).' Monero';
echo Wownero_Gateway::format_wownero($item->amount).' Wownero';
break;
}
}
@ -200,7 +200,7 @@ HTML;
}
public function no_items() {
esc_html_e('No Monero payments found', 'monero_gateway');
esc_html_e('No Wownero payments found', 'wownero_gateway');
}
protected function get_filter_vars() {
@ -212,8 +212,8 @@ HTML;
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';
$table_name_1 = $wpdb->prefix.'wownero_gateway_quotes';
$table_name_2 = $wpdb->prefix.'wownero_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);
@ -249,8 +249,8 @@ HTML;
$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';
$table_name_1 = $wpdb->prefix.'wownero_gateway_quotes';
$table_name_2 = $wpdb->prefix.'wownero_gateway_quotes_txids';
$query_where = ' WHERE 1=1 ';

View file

@ -4,111 +4,111 @@ defined( 'ABSPATH' ) || exit;
return array(
'enabled' => array(
'title' => __('Enable / Disable', 'monero_gateway'),
'label' => __('Enable this payment gateway', 'monero_gateway'),
'title' => __('Enable / Disable', 'wownero_gateway'),
'label' => __('Enable this payment gateway', 'wownero_gateway'),
'type' => 'checkbox',
'default' => 'no'
),
'title' => array(
'title' => __('Title', 'monero_gateway'),
'title' => __('Title', 'wownero_gateway'),
'type' => 'text',
'desc_tip' => __('Payment title the customer will see during the checkout process.', 'monero_gateway'),
'default' => __('Monero Gateway', 'monero_gateway')
'desc_tip' => __('Payment title the customer will see during the checkout process.', 'wownero_gateway'),
'default' => __('Wownero Gateway', 'wownero_gateway')
),
'description' => array(
'title' => __('Description', 'monero_gateway'),
'title' => __('Description', 'wownero_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')
'desc_tip' => __('Payment description the customer will see during the checkout process.', 'wownero_gateway'),
'default' => __('Pay securely using Wownero. You will be provided payment details after checkout.', 'wownero_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'),
'title' => __('Discount for using Wownero', 'wownero_gateway'),
'desc_tip' => __('Provide a discount to your customers for making a private payment with Wownero', 'wownero_gateway'),
'description' => __('Enter a percentage discount (i.e. 5 for 5%) or leave this empty if you do not wish to provide a discount', 'wownero_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'),
'title' => __('Order valid time', 'wownero_gateway'),
'desc_tip' => __('Amount of time order is valid before expiring', 'wownero_gateway'),
'description' => __('Enter the number of seconds that the funds must be received in after order is placed. 3600 seconds = 1 hour', 'wownero_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'),
'title' => __('Number of confirmations', 'wownero_gateway'),
'desc_tip' => __('Number of confirms a transaction must have to be valid', 'wownero_gateway'),
'description' => __('Enter the number of confirms that transactions must have. Enter 0 to zero-confim. Each confirm will take approximately four minutes', 'wownero_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'),
'title' => __('Confirmation Type', 'wownero_gateway'),
'desc_tip' => __('Select the method for confirming transactions', 'wownero_gateway'),
'description' => __('Select the method for confirming transactions', 'wownero_gateway'),
'type' => 'select',
'options' => array(
'viewkey' => __('viewkey', 'monero_gateway'),
'monero-wallet-rpc' => __('monero-wallet-rpc', 'monero_gateway')
'viewkey' => __('viewkey', 'wownero_gateway'),
'wownero-wallet-rpc' => __('wownero-wallet-rpc', 'wownero_gateway')
),
'default' => 'viewkey'
),
'monero_address' => array(
'title' => __('Monero Address', 'monero_gateway'),
'wownero_address' => array(
'title' => __('Wownero Address', 'wownero_gateway'),
'label' => __('Useful for people that have not a daemon online'),
'type' => 'text',
'desc_tip' => __('Monero Wallet Address (MoneroL)', 'monero_gateway')
'desc_tip' => __('Wownero Wallet Address (Wownero)', 'wownero_gateway')
),
'viewkey' => array(
'title' => __('Secret Viewkey', 'monero_gateway'),
'title' => __('Secret Viewkey', 'wownero_gateway'),
'label' => __('Secret Viewkey'),
'type' => 'text',
'desc_tip' => __('Your secret Viewkey', 'monero_gateway')
'desc_tip' => __('Your secret Viewkey', 'wownero_gateway')
),
'daemon_host' => array(
'title' => __('Monero wallet RPC Host/IP', 'monero_gateway'),
'title' => __('Wownero wallet RPC Host/IP', 'wownero_gateway'),
'type' => 'text',
'desc_tip' => __('This is the Daemon Host/IP to authorize the payment with', 'monero_gateway'),
'desc_tip' => __('This is the Daemon Host/IP to authorize the payment with', 'wownero_gateway'),
'default' => '127.0.0.1',
),
'daemon_port' => array(
'title' => __('Monero wallet RPC port', 'monero_gateway'),
'title' => __('Wownero wallet RPC port', 'wownero_gateway'),
'type' => __('number'),
'desc_tip' => __('This is the Wallet RPC port to authorize the payment with', 'monero_gateway'),
'desc_tip' => __('This is the Wallet RPC port to authorize the payment with', 'wownero_gateway'),
'default' => '18080',
),
'testnet' => array(
'title' => __(' Testnet', 'monero_gateway'),
'label' => __(' Check this if you are using testnet ', 'monero_gateway'),
'title' => __(' Testnet', 'wownero_gateway'),
'label' => __(' Check this if you are using testnet ', 'wownero_gateway'),
'type' => 'checkbox',
'description' => __('Advanced usage only', 'monero_gateway'),
'description' => __('Advanced usage only', 'wownero_gateway'),
'default' => 'no'
),
'onion_service' => array(
'title' => __(' SSL warnings ', 'monero_gateway'),
'label' => __(' Check to Silence SSL warnings', 'monero_gateway'),
'title' => __(' SSL warnings ', 'wownero_gateway'),
'label' => __(' Check to Silence SSL warnings', 'wownero_gateway'),
'type' => 'checkbox',
'description' => __('Check this box if you are running on an Onion Service (Suppress SSL errors)', 'monero_gateway'),
'description' => __('Check this box if you are running on an Onion Service (Suppress SSL errors)', 'wownero_gateway'),
'default' => 'no'
),
'show_qr' => array(
'title' => __('Show QR Code', 'monero_gateway'),
'label' => __('Show QR Code', 'monero_gateway'),
'title' => __('Show QR Code', 'wownero_gateway'),
'label' => __('Show QR Code', 'wownero_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'),
'use_wownero_price' => array(
'title' => __('Show Prices in Wownero', 'wownero_gateway'),
'label' => __('Show Prices in Wownero', 'wownero_gateway'),
'type' => 'checkbox',
'description' => __('Enable this to convert ALL prices on the frontend to Monero (experimental)'),
'description' => __('Enable this to convert ALL prices on the frontend to Wownero (experimental)'),
'default' => 'no'
),
'use_monero_price_decimals' => array(
'title' => __('Display Decimals', 'monero_gateway'),
'use_wownero_price_decimals' => array(
'title' => __('Display Decimals', 'wownero_gateway'),
'type' => __('number'),
'description' => __('Number of decimal places to display on frontend. Upon checkout exact price will be displayed.'),
'default' => 12,
'default' => 11,
),
);

View file

@ -10,7 +10,7 @@
defined( 'ABSPATH' ) || exit;
class Monero_base58 {
class Wownero_base58 {
/**
* @var string
*/

View file

@ -11,15 +11,15 @@ if(!class_exists('SHA3'))
if(!class_exists('ed25519'))
require_once('crypto/ed25519.php');
require_once('class-monero-base58.php');
require_once('class-wownero-base58.php');
class Monero_Cryptonote
class Wownero_Cryptonote
{
protected $ed25519;
public function __construct()
{
$this->ed25519 = new ed25519();
$this->base58 = new Monero_base58();
$this->base58 = new Wownero_base58();
$this->address_prefix = MONERO_GATEWAY_ADDRESS_PREFIX;
$this->address_prefix_integrated = MONERO_GATEWAY_ADDRESS_PREFIX_INTEGRATED;
}
@ -222,12 +222,12 @@ class Monero_Cryptonote
}
/*
* Create a valid base58 encoded Monero address from public keys
* Create a valid base58 encoded Wownero address from public keys
*
* @param string Public spend key
* @param string Public view key
*
* @return string Base58 encoded Monero address
* @return string Base58 encoded Wownero address
*/
public function encode_address($pSpendKey, $pViewKey)
{
@ -246,9 +246,9 @@ class Monero_Cryptonote
}
/*
* Decode a base58 encoded Monero address
* Decode a base58 encoded Wownero address
*
* @param string A base58 encoded Monero address
* @param string A base58 encoded Wownero address
*
* @return array An array containing the Address network byte, public spend key, and public view key
*/
@ -291,11 +291,11 @@ class Monero_Cryptonote
}
/*
* Generate a Monero address from seed
* Generate a Wownero address from seed
*
* @param string Hex string to use as seed
*
* @return string A base58 encoded Monero address
* @return string A base58 encoded Wownero address
*/
public function address_from_seed($hex_seed)
{

View file

@ -1,9 +1,9 @@
<?php
/**
* monero_explorer_tools.php
* wownero_explorer_tools.php
*
* Uses CURL to call API functions from the block explorer
* https://xmrchain.net/
* https://explore.wownero.com/
*
* @author Serhack
* @author cryptochangements
@ -13,7 +13,7 @@
defined( 'ABSPATH' ) || exit;
class Monero_Explorer_Tools
class Wownero_Explorer_Tools
{
private $url;
public function __construct($testnet = false)

View file

@ -1,19 +1,19 @@
<?php
/*
* Main Gateway of Monero using either a local daemon or the explorer
* Main Gateway of Wownero using either a local daemon or the explorer
* Authors: Serhack, cryptochangements, mosu-forge
*/
defined( 'ABSPATH' ) || exit;
require_once('class-monero-cryptonote.php');
require_once('class-wownero-cryptonote.php');
class Monero_Gateway extends WC_Payment_Gateway
class Wownero_Gateway extends WC_Payment_Gateway
{
private static $_id = 'monero_gateway';
private static $_title = 'Monero Gateway';
private static $_method_title = 'Monero Gateway';
private static $_method_description = 'Monero Gateway Plug-in for WooCommerce.';
private static $_id = 'wownero_gateway';
private static $_title = 'Wownero Gateway';
private static $_method_title = 'Wownero Gateway';
private static $_method_description = 'Wownero Gateway Plug-in for WooCommerce.';
private static $_errors = [];
private static $discount = false;
@ -27,29 +27,28 @@ class Monero_Gateway extends WC_Payment_Gateway
private static $testnet = false;
private static $onion_service = false;
private static $show_qr = false;
private static $use_monero_price = false;
private static $use_monero_price_decimals = MONERO_GATEWAY_ATOMIC_UNITS;
private static $use_wownero_price = false;
private static $use_wownero_price_decimals = MONERO_GATEWAY_ATOMIC_UNITS;
private static $cryptonote;
private static $monero_wallet_rpc;
private static $monero_explorer_tools;
private static $wownero_wallet_rpc;
private static $wownero_explorer_tools;
private static $log;
private static $currencies = array('BTC','USD','EUR','CAD','INR','GBP','COP','SGD','JPY');
private static $rates = array();
private static $payment_details = array();
public function get_icon()
{
return apply_filters('woocommerce_gateway_icon', '<img src="'.MONERO_GATEWAY_PLUGIN_URL.'assets/images/monero-icon.png"/>');
return apply_filters('woocommerce_gateway_icon', '<img src="'.MONERO_GATEWAY_PLUGIN_URL.'assets/images/wownero-icon.png"/>');
}
function __construct($add_action=true)
{
$this->id = self::$_id;
$this->method_title = __(self::$_method_title, 'monero_gateway');
$this->method_description = __(self::$_method_description, 'monero_gateway');
$this->method_title = __(self::$_method_title, 'wownero_gateway');
$this->method_description = __(self::$_method_description, 'wownero_gateway');
$this->has_fields = false;
$this->supports = array(
'products',
@ -74,15 +73,15 @@ class Monero_Gateway extends WC_Payment_Gateway
self::$valid_time = $this->settings['valid_time'];
self::$confirms = $this->settings['confirms'];
self::$confirm_type = $this->settings['confirm_type'];
self::$address = $this->settings['monero_address'];
self::$address = $this->settings['wownero_address'];
self::$viewkey = $this->settings['viewkey'];
self::$host = $this->settings['daemon_host'];
self::$port = $this->settings['daemon_port'];
self::$testnet = $this->settings['testnet'] == 'yes';
self::$onion_service = $this->settings['onion_service'] == 'yes';
self::$show_qr = $this->settings['show_qr'] == 'yes';
self::$use_monero_price = $this->settings['use_monero_price'] == 'yes';
self::$use_monero_price_decimals = $this->settings['use_monero_price_decimals'];
self::$use_wownero_price = $this->settings['use_wownero_price'] == 'yes';
self::$use_wownero_price_decimals = $this->settings['use_wownero_price_decimals'];
$explorer_url = self::$testnet ? MONERO_GATEWAY_TESTNET_EXPLORER_URL : MONERO_GATEWAY_MAINNET_EXPLORER_URL;
defined('MONERO_GATEWAY_EXPLORER_URL') || define('MONERO_GATEWAY_EXPLORER_URL', $explorer_url);
@ -91,13 +90,13 @@ class Monero_Gateway extends WC_Payment_Gateway
add_action('woocommerce_update_options_payment_gateways_'.$this->id, array($this, 'process_admin_options'));
// Initialize helper classes
self::$cryptonote = new Monero_Cryptonote();
if(self::$confirm_type == 'monero-wallet-rpc') {
require_once('class-monero-wallet-rpc.php');
self::$monero_wallet_rpc = new Monero_Wallet_Rpc(self::$host, self::$port);
self::$cryptonote = new Wownero_Cryptonote();
if(self::$confirm_type == 'wownero-wallet-rpc') {
require_once('class-wownero-wallet-rpc.php');
self::$wownero_wallet_rpc = new Wownero_Wallet_Rpc(self::$host, self::$port);
} else {
require_once('class-monero-explorer-tools.php');
self::$monero_explorer_tools = new Monero_Explorer_Tools(self::$testnet);
require_once('class-wownero-explorer-tools.php');
self::$wownero_explorer_tools = new Wownero_Explorer_Tools(self::$testnet);
}
self::$log = new WC_Logger();
@ -105,16 +104,16 @@ class Monero_Gateway extends WC_Payment_Gateway
public function init_form_fields()
{
$this->form_fields = include 'admin/monero-gateway-admin-settings.php';
$this->form_fields = include 'admin/wownero-gateway-admin-settings.php';
}
public function validate_monero_address_field($key,$address)
public function validate_wownero_address_field($key,$address)
{
if($this->settings['confirm_type'] == 'viewkey') {
if (strlen($address) == 95 && substr($address, 0, 1) == '4')
if (strlen($address) == 97 && substr($address, 0, 1) == 'W')
if(self::$cryptonote->verify_checksum($address))
return $address;
self::$_errors[] = 'Monero address is invalid';
self::$_errors[] = 'Wownero address is invalid';
}
return $address;
}
@ -149,12 +148,12 @@ class Monero_Gateway extends WC_Payment_Gateway
public function admin_options()
{
$confirm_type = self::$confirm_type;
if($confirm_type === 'monero-wallet-rpc')
if($confirm_type === 'wownero-wallet-rpc')
$balance = self::admin_balance_info();
$settings_html = $this->generate_settings_html(array(), false);
$errors = array_merge(self::$_errors, $this->admin_php_module_check(), $this->admin_ssl_check());
include MONERO_GATEWAY_PLUGIN_DIR . '/templates/monero-gateway/admin/settings-page.php';
include MONERO_GATEWAY_PLUGIN_DIR . '/templates/wownero-gateway/admin/settings-page.php';
}
public static function admin_balance_info()
@ -166,11 +165,11 @@ class Monero_Gateway extends WC_Payment_Gateway
'unlocked_balance' => 'Not Available',
);
}
$wallet_amount = self::$monero_wallet_rpc->getbalance();
$height = self::$monero_wallet_rpc->getheight();
$wallet_amount = self::$wownero_wallet_rpc->getbalance();
$height = self::$wownero_wallet_rpc->getheight();
if (!isset($wallet_amount)) {
self::$_errors[] = 'Cannot connect to monero-wallet-rpc';
self::$log->add('Monero_Payments', '[ERROR] Cannot connect to monero-wallet-rpc');
self::$_errors[] = 'Cannot connect to wownero-wallet-rpc';
self::$log->add('Wownero_Payments', '[ERROR] Cannot connect to wownero-wallet-rpc');
return array(
'height' => 'Not Available',
'balance' => 'Not Available',
@ -179,8 +178,8 @@ class Monero_Gateway extends WC_Payment_Gateway
} else {
return array(
'height' => $height,
'balance' => self::format_monero($wallet_amount['balance']).' Monero',
'unlocked_balance' => self::format_monero($wallet_amount['unlocked_balance']).' Monero'
'balance' => self::format_wownero($wallet_amount['balance']).' Wownero',
'unlocked_balance' => self::format_wownero($wallet_amount['unlocked_balance']).' Wownero'
);
}
}
@ -205,7 +204,7 @@ class Monero_Gateway extends WC_Payment_Gateway
public function process_payment($order_id)
{
global $wpdb;
$table_name = $wpdb->prefix.'monero_gateway_quotes';
$table_name = $wpdb->prefix.'wownero_gateway_quotes';
$order = wc_get_order($order_id);
@ -219,17 +218,17 @@ class Monero_Gateway extends WC_Payment_Gateway
$currency = $order->get_currency();
$rate = self::get_live_rate($currency);
$fiat_amount = $order->get_total('');
$monero_amount = 1e8 * $fiat_amount / $rate;
$wownero_amount = 1e8 * $fiat_amount / $rate;
if(self::$discount)
$monero_amount = $monero_amount - $monero_amount * self::$discount / 100;
$wownero_amount = $wownero_amount - $wownero_amount * self::$discount / 100;
$monero_amount = intval($monero_amount * MONERO_GATEWAY_ATOMIC_UNITS_POW);
$wownero_amount = intval($wownero_amount * MONERO_GATEWAY_ATOMIC_UNITS_POW);
$query = $wpdb->prepare("INSERT INTO $table_name (order_id, payment_id, currency, rate, amount) VALUES (%d, %s, %s, %d, %d)", array($order_id, $payment_id, $currency, $rate, $monero_amount));
$query = $wpdb->prepare("INSERT INTO $table_name (order_id, payment_id, currency, rate, amount) VALUES (%d, %s, %s, %d, %d)", array($order_id, $payment_id, $currency, $rate, $wownero_amount));
$wpdb->query($query);
$order->update_status('on-hold', __('Awaiting offline payment', 'monero_gateway'));
$order->update_status('on-hold', __('Awaiting offline payment', 'wownero_gateway'));
$order->reduce_order_stock(); // Reduce stock levels
WC()->cart->empty_cart(); // Remove cart
@ -243,13 +242,13 @@ class Monero_Gateway extends WC_Payment_Gateway
* function for verifying payments
* This cron runs every 30 seconds
*/
public static function do_update_event()
{
global $wpdb;
// Get Live Price
$currencies = implode(',', self::$currencies);
$api_link = 'https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms='.$currencies.'&extraParams=monero_woocommerce';
// Get usd and btc price for wownero
$api_link = 'https://api.coingecko.com/api/v3/coins/wownero/tickers?page=1';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
@ -258,27 +257,55 @@ class Monero_Gateway extends WC_Payment_Gateway
$resp = curl_exec($curl);
curl_close($curl);
$price = json_decode($resp, true);
if( ! isset( $price['tickers'][0]['converted_last']['usd'] ) ||
! isset( $price['tickers'][0]['converted_last']['btc'] ) ) {
$this->log->add('Wownero_Gateway', '[ERROR] coingecko.com api');
}
else {
$usd = $price['tickers'][0]['converted_last']['usd'];
$btc = $price['tickers'][0]['converted_last']['btc'];
if(!isset($price['Response']) || $price['Response'] != 'Error') {
$table_name = $wpdb->prefix.'monero_gateway_live_rates';
foreach($price as $currency=>$rate) {
// shift decimal eight places for precise int storage
$rate = intval($rate * 1e8);
$query = $wpdb->prepare("INSERT INTO $table_name (currency, rate, updated) VALUES (%s, %d, NOW()) ON DUPLICATE KEY UPDATE rate=%d, updated=NOW()", array($currency, $rate, $rate));
$wpdb->query($query);
// get other currency rates based off usd
$api_link = 'https://api.exchangeratesapi.io/latest?base=USD';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $api_link,
));
$resp = curl_exec($curl);
curl_close($curl);
$price = json_decode($resp, true);
if( ! isset( $price['rates'] ) ) {
$this->log->add('Wownero_Gateway', '[ERROR] exchangeratesapi.io');
}
else {
$rates = $price['rates'];
$table_name = $wpdb->prefix.'wownero_gateway_live_rates';
// usd
$query = $wpdb->prepare("INSERT INTO $table_name (currency, rate, updated) VALUES (%s, %d, NOW()) ON DUPLICATE KEY UPDATE rate=%d, updated=NOW()", array('BTC', $btc, $btc));
$query = $wpdb->prepare("INSERT INTO $table_name (currency, rate, updated) VALUES (%s, %d, NOW()) ON DUPLICATE KEY UPDATE rate=%d, updated=NOW()", array('USD', $usd, $usd));
foreach( $rates as $currency=>$rate ) {
if( $currency == 'USD' ) continue;
$rate = intval($rate * 1e8);
$query = $wpdb->prepare("INSERT INTO $table_name (currency, rate, updated) VALUES (%s, %d, NOW()) ON DUPLICATE KEY UPDATE rate=%d, updated=NOW()", array($currency, $usd*$rate, $usd*$rate));
$wpdb->query($query);
}
}
}
// Get current network/wallet height
if(self::$confirm_type == 'monero-wallet-rpc')
$height = self::$monero_wallet_rpc->getheight();
if(self::$confirm_type == 'wownero-wallet-rpc')
$height = self::$wownero_wallet_rpc->getheight();
else
$height = self::$monero_explorer_tools->getheight();
set_transient('monero_gateway_network_height', $height);
$height = self::$wownero_explorer_tools->getheight();
set_transient('wownero_gateway_network_height', $height);
// Get pending payments
$table_name_1 = $wpdb->prefix.'monero_gateway_quotes';
$table_name_2 = $wpdb->prefix.'monero_gateway_quotes_txids';
$table_name_1 = $wpdb->prefix.'wownero_gateway_quotes';
$table_name_2 = $wpdb->prefix.'wownero_gateway_quotes_txids';
$query = $wpdb->prepare("SELECT *, $table_name_1.payment_id AS payment_id, $table_name_1.amount AS amount_total, $table_name_2.amount AS amount_paid, NOW() as now FROM $table_name_1 LEFT JOIN $table_name_2 ON $table_name_1.payment_id = $table_name_2.payment_id WHERE pending=1", array());
$rows = $wpdb->get_results($query);
@ -304,9 +331,9 @@ class Monero_Gateway extends WC_Payment_Gateway
$order_id = $quote->order_id;
$order = wc_get_order($order_id);
$payment_id = self::sanatize_id($quote->payment_id);
$amount_monero = $quote->amount_total;
$amount_wownero = $quote->amount_total;
if(self::$confirm_type == 'monero-wallet-rpc')
if(self::$confirm_type == 'wownero-wallet-rpc')
$new_txs = self::check_payment_rpc($payment_id);
else
$new_txs = self::check_payment_explorer($payment_id);
@ -335,7 +362,7 @@ class Monero_Gateway extends WC_Payment_Gateway
$heights[] = $tx->height;
}
$paid = $amount_paid > $amount_monero - MONERO_GATEWAY_ATOMIC_UNIT_THRESHOLD;
$paid = $amount_paid > $amount_wownero - MONERO_GATEWAY_ATOMIC_UNIT_THRESHOLD;
if($paid) {
if(self::$confirms == 0) {
@ -353,20 +380,20 @@ class Monero_Gateway extends WC_Payment_Gateway
}
if($paid && $confirmed) {
self::$log->add('Monero_Payments', "[SUCCESS] Payment has been confirmed for order id $order_id and payment id $payment_id");
self::$log->add('Wownero_Payments', "[SUCCESS] Payment has been confirmed for order id $order_id and payment id $payment_id");
$query = $wpdb->prepare("UPDATE $table_name_1 SET confirmed=1,paid=1,pending=0 WHERE payment_id=%s", array($payment_id));
$wpdb->query($query);
unset(self::$payment_details[$order_id]);
if(self::is_virtual_in_cart($order_id) == true){
$order->update_status('completed', __('Payment has been received.', 'monero_gateway'));
$order->update_status('completed', __('Payment has been received.', 'wownero_gateway'));
} else {
$order->update_status('processing', __('Payment has been received.', 'monero_gateway'));
$order->update_status('processing', __('Payment has been received.', 'wownero_gateway'));
}
} else if($paid) {
self::$log->add('Monero_Payments', "[SUCCESS] Payment has been received for order id $order_id and payment id $payment_id");
self::$log->add('Wownero_Payments', "[SUCCESS] Payment has been received for order id $order_id and payment id $payment_id");
$query = $wpdb->prepare("UPDATE $table_name_1 SET paid=1 WHERE payment_id=%s", array($payment_id));
$wpdb->query($query);
@ -377,13 +404,13 @@ class Monero_Gateway extends WC_Payment_Gateway
$timestamp_now = new DateTime($quote->now);
$order_age_seconds = $timestamp_now->getTimestamp() - $timestamp_created->getTimestamp();
if($order_age_seconds > self::$valid_time) {
self::$log->add('Monero_Payments', "[FAILED] Payment has expired for order id $order_id and payment id $payment_id");
self::$log->add('Wownero_Payments', "[FAILED] Payment has expired for order id $order_id and payment id $payment_id");
$query = $wpdb->prepare("UPDATE $table_name_1 SET pending=0 WHERE payment_id=%s", array($payment_id));
$wpdb->query($query);
unset(self::$payment_details[$order_id]);
$order->update_status('cancelled', __('Payment has expired.', 'monero_gateway'));
$order->update_status('cancelled', __('Payment has expired.', 'wownero_gateway'));
}
}
}
@ -392,7 +419,7 @@ class Monero_Gateway extends WC_Payment_Gateway
protected static function check_payment_rpc($payment_id)
{
$txs = array();
$payments = self::$monero_wallet_rpc->get_all_payments($payment_id);
$payments = self::$wownero_wallet_rpc->get_all_payments($payment_id);
foreach($payments as $payment) {
$txs[] = array(
'amount' => $payment['amount'],
@ -406,7 +433,7 @@ class Monero_Gateway extends WC_Payment_Gateway
public static function check_payment_explorer($payment_id)
{
$txs = array();
$outputs = self::$monero_explorer_tools->get_outputs(self::$address, self::$viewkey);
$outputs = self::$wownero_explorer_tools->get_outputs(self::$address, self::$viewkey);
foreach($outputs as $payment) {
if($payment['payment_id'] == $payment_id) {
$txs[] = array(
@ -428,8 +455,8 @@ class Monero_Gateway extends WC_Payment_Gateway
return self::$payment_details[$order_id];
global $wpdb;
$table_name_1 = $wpdb->prefix.'monero_gateway_quotes';
$table_name_2 = $wpdb->prefix.'monero_gateway_quotes_txids';
$table_name_1 = $wpdb->prefix.'wownero_gateway_quotes';
$table_name_2 = $wpdb->prefix.'wownero_gateway_quotes_txids';
$query = $wpdb->prepare("SELECT *, $table_name_1.payment_id AS payment_id, $table_name_1.amount AS amount_total, $table_name_2.amount AS amount_paid, NOW() as now FROM $table_name_1 LEFT JOIN $table_name_2 ON $table_name_1.payment_id = $table_name_2.payment_id WHERE order_id=%d", array($order_id));
$details = $wpdb->get_results($query);
if (count($details)) {
@ -443,7 +470,7 @@ class Monero_Gateway extends WC_Payment_Gateway
'txid' => $tx->txid,
'height' => $tx->height,
'amount' => $tx->amount_paid,
'amount_formatted' => self::format_monero($tx->amount_paid)
'amount_formatted' => self::format_wownero($tx->amount_paid)
);
$amount_paid += $tx->amount_paid;
$heights[] = $tx->height;
@ -455,7 +482,7 @@ class Monero_Gateway extends WC_Payment_Gateway
});
if(count($heights) && !in_array(0, $heights)) {
$height = get_transient('monero_gateway_network_height');
$height = get_transient('wownero_gateway_network_height');
$highest_block = max($heights);
$confirms = $height - $highest_block;
$blocks_to_confirm = self::$confirms - $confirms;
@ -476,12 +503,12 @@ class Monero_Gateway extends WC_Payment_Gateway
$address = self::$address;
$payment_id = self::sanatize_id($details[0]->payment_id);
if(self::$confirm_type == 'monero-wallet-rpc') {
$array_integrated_address = self::$monero_wallet_rpc->make_integrated_address($payment_id);
if(self::$confirm_type == 'wownero-wallet-rpc') {
$array_integrated_address = self::$wownero_wallet_rpc->make_integrated_address($payment_id);
if (isset($array_integrated_address['integrated_address'])) {
$integrated_addr = $array_integrated_address['integrated_address'];
} else {
self::$log->add('Monero_Gateway', '[ERROR] Unable get integrated address');
self::$log->add('Wownero_Gateway', '[ERROR] Unable get integrated address');
return '[ERROR] Unable get integrated address';
}
} else {
@ -491,8 +518,8 @@ class Monero_Gateway extends WC_Payment_Gateway
$pub_viewkey = $decoded_address['viewkey'];
$integrated_addr = self::$cryptonote->integrated_addr_from_keys($pub_spendkey, $pub_viewkey, $payment_id);
} else {
self::$log->add('Monero_Gateway', '[ERROR] Merchant has not set Monero address');
return '[ERROR] Merchant has not set Monero address';
self::$log->add('Wownero_Gateway', '[ERROR] Merchant has not set Wownero address');
return '[ERROR] Merchant has not set Wownero address';
}
}
@ -519,7 +546,7 @@ class Monero_Gateway extends WC_Payment_Gateway
}
}
$qrcode_uri = 'monero:'.$address.'?tx_amount='.$amount_due.'&tx_payment_id='.$payment_id;
$qrcode_uri = 'wownero:'.$address.'?tx_amount='.$amount_due.'&tx_payment_id='.$payment_id;
$my_order_url = wc_get_endpoint_url('view-order', $order_id, wc_get_page_permalink('myaccount'));
$payment_details = array(
@ -534,9 +561,9 @@ class Monero_Gateway extends WC_Payment_Gateway
'amount_total' => $amount_total,
'amount_paid' => $amount_paid,
'amount_due' => $amount_due,
'amount_total_formatted' => self::format_monero($amount_total),
'amount_paid_formatted' => self::format_monero($amount_paid),
'amount_due_formatted' => self::format_monero($amount_due),
'amount_total_formatted' => self::format_wownero($amount_total),
'amount_paid_formatted' => self::format_wownero($amount_paid),
'amount_due_formatted' => self::format_wownero($amount_due),
'status' => $status,
'created' => $details[0]->created,
'order_age' => $order_age_seconds,
@ -566,7 +593,7 @@ class Monero_Gateway extends WC_Payment_Gateway
self::ajax_output(array('error' => '[ERROR] Order does not belong to this user'));
if($order->get_payment_method() != self::$_id)
self::ajax_output(array('error' => '[ERROR] Order not paid for with Monero'));
self::ajax_output(array('error' => '[ERROR] Order not paid for with Wownero'));
$details = self::get_payment_details($order);
if(!is_array($details))
@ -592,10 +619,10 @@ class Monero_Gateway extends WC_Payment_Gateway
$details = self::get_payment_details($order);
if(!is_array($details)) {
$error = $details;
include MONERO_GATEWAY_PLUGIN_DIR . '/templates/monero-gateway/admin/order-history-error-page.php';
include MONERO_GATEWAY_PLUGIN_DIR . '/templates/wownero-gateway/admin/order-history-error-page.php';
return;
}
include MONERO_GATEWAY_PLUGIN_DIR . '/templates/monero-gateway/admin/order-history-page.php';
include MONERO_GATEWAY_PLUGIN_DIR . '/templates/wownero-gateway/admin/order-history-page.php';
}
public static function customer_order_page($order)
@ -614,13 +641,13 @@ class Monero_Gateway extends WC_Payment_Gateway
$details = self::get_payment_details($order_id);
if(!is_array($details)) {
$error = $details;
include MONERO_GATEWAY_PLUGIN_DIR . '/templates/monero-gateway/customer/order-error-page.php';
include MONERO_GATEWAY_PLUGIN_DIR . '/templates/wownero-gateway/customer/order-error-page.php';
return;
}
$show_qr = self::$show_qr;
$details_json = json_encode($details);
$ajax_url = WC_AJAX::get_endpoint('monero_gateway_payment_details');
include MONERO_GATEWAY_PLUGIN_DIR . '/templates/monero-gateway/customer/order-page.php';
$ajax_url = WC_AJAX::get_endpoint('wownero_gateway_payment_details');
include MONERO_GATEWAY_PLUGIN_DIR . '/templates/wownero-gateway/customer/order-page.php';
}
public static function customer_order_email($order)
@ -638,10 +665,10 @@ class Monero_Gateway extends WC_Payment_Gateway
$method_title = self::$_title;
$details = self::get_payment_details($order_id);
if(!is_array($details)) {
include MONERO_GATEWAY_PLUGIN_DIR . '/templates/monero-gateway/customer/order-email-error-block.php';
include MONERO_GATEWAY_PLUGIN_DIR . '/templates/wownero-gateway/customer/order-email-error-block.php';
return;
}
include MONERO_GATEWAY_PLUGIN_DIR . '/templates/monero-gateway/customer/order-email-block.php';
include MONERO_GATEWAY_PLUGIN_DIR . '/templates/wownero-gateway/customer/order-email-block.php';
}
public static function get_id()
@ -659,23 +686,23 @@ class Monero_Gateway extends WC_Payment_Gateway
return self::$show_qr;
}
public static function use_monero_price()
public static function use_wownero_price()
{
return self::$use_monero_price;
return self::$use_wownero_price;
}
public static function convert_wc_price($price, $currency)
{
$rate = self::get_live_rate($currency);
$monero_amount = intval(MONERO_GATEWAY_ATOMIC_UNITS_POW * 1e8 * $price / $rate) / MONERO_GATEWAY_ATOMIC_UNITS_POW;
$monero_amount_formatted = sprintf('%.'.self::$use_monero_price_decimals.'f', $monero_amount);
$wownero_amount = intval(MONERO_GATEWAY_ATOMIC_UNITS_POW * 1e8 * $price / $rate) / MONERO_GATEWAY_ATOMIC_UNITS_POW;
$wownero_amount_formatted = sprintf('%.'.self::$use_wownero_price_decimals.'f', $wownero_amount);
return <<<HTML
<span class="woocommerce-Price-amount amount" data-price="$price" data-currency="$currency"
data-rate="$rate" data-rate-type="live">
$monero_amount_formatted
<span class="woocommerce-Price-currencySymbol">XMR</span>
$wownero_amount_formatted
<span class="woocommerce-Price-currencySymbol">WOW</span>
</span>
HTML;
@ -699,14 +726,14 @@ HTML;
$price = array_pop($matches);
$currency = $payment_details['currency'];
$rate = $payment_details['rate'];
$monero_amount = intval(MONERO_GATEWAY_ATOMIC_UNITS_POW * 1e8 * $price / $rate) / MONERO_GATEWAY_ATOMIC_UNITS_POW;
$monero_amount_formatted = sprintf('%.'.MONERO_GATEWAY_ATOMIC_UNITS.'f', $monero_amount);
$wownero_amount = intval(MONERO_GATEWAY_ATOMIC_UNITS_POW * 1e8 * $price / $rate) / MONERO_GATEWAY_ATOMIC_UNITS_POW;
$wownero_amount_formatted = sprintf('%.'.MONERO_GATEWAY_ATOMIC_UNITS.'f', $wownero_amount);
return <<<HTML
<span class="woocommerce-Price-amount amount" data-price="$price" data-currency="$currency"
data-rate="$rate" data-rate-type="fixed">
$monero_amount_formatted
<span class="woocommerce-Price-currencySymbol">XMR</span>
$wownero_amount_formatted
<span class="woocommerce-Price-currencySymbol">WOW</span>
</span>
HTML;
@ -718,7 +745,7 @@ HTML;
return self::$rates[$currency];
global $wpdb;
$table_name = $wpdb->prefix.'monero_gateway_live_rates';
$table_name = $wpdb->prefix.'wownero_gateway_live_rates';
$query = $wpdb->prepare("SELECT rate FROM $table_name WHERE currency=%s", array($currency));
$rate = $wpdb->get_row($query)->rate;
@ -750,7 +777,7 @@ HTML;
return $virtual_items == $cart_size;
}
public static function format_monero($atomic_units) {
public static function format_wownero($atomic_units) {
return sprintf(MONERO_GATEWAY_ATOMIC_UNITS_SPRINTF, $atomic_units / MONERO_GATEWAY_ATOMIC_UNITS_POW);
}

View file

@ -1,6 +1,6 @@
<?php
/**
* monero_wallet_rpc
* wownero_wallet_rpc
*
* Written using the JSON RPC specification -
* http://json-rpc.org/wiki/specification
@ -13,7 +13,7 @@
defined( 'ABSPATH' ) || exit;
class Monero_Wallet_Rpc
class Wownero_Wallet_Rpc
{
protected $url = null, $is_debug = false;
protected $curl_options = array(
@ -178,7 +178,7 @@ class Monero_Wallet_Rpc
// check for curl error
if (0 < curl_errno($ch)) {
if(is_admin())
echo '[ERROR] Failed to connect to monero-wallet-rpc at ' . $this->host . ' port '. $this->port .'</br>';
echo '[ERROR] Failed to connect to wownero-wallet-rpc at ' . $this->host . ' port '. $this->port .'</br>';
}
// close the connection
curl_close($ch);
@ -214,7 +214,7 @@ class Monero_Wallet_Rpc
}
/*
* The following functions can all be called to interact with the Monero RPC wallet
* The following functions can all be called to interact with the Wownero RPC wallet
* They will majority of them will return the result as an array
* Example: $daemon->address(); where $daemon is an instance of this class, will return the wallet address as string within an array
*/

View file

@ -1,249 +0,0 @@
<?php
/*
Plugin Name: Monero Woocommerce Gateway
Plugin URI: https://github.com/monero-integrations/monerowp
Description: Extends WooCommerce by adding a Monero Gateway
Version: 3.0.0
Tested up to: 4.9.8
Author: mosu-forge, SerHack
Author URI: https://monerointegrations.com/
*/
// This code isn't for Dark Net Markets, please report them to Authority!
defined( 'ABSPATH' ) || exit;
// Constants, you can edit these if you fork this repo
define('MONERO_GATEWAY_MAINNET_EXPLORER_URL', 'https://xmrchain.net/');
define('MONERO_GATEWAY_TESTNET_EXPLORER_URL', 'https://testnet.xmrchain.com/');
define('MONERO_GATEWAY_ADDRESS_PREFIX', 0x12);
define('MONERO_GATEWAY_ADDRESS_PREFIX_INTEGRATED', 0x13);
define('MONERO_GATEWAY_ATOMIC_UNITS', 12);
define('MONERO_GATEWAY_ATOMIC_UNIT_THRESHOLD', 10); // Amount under in atomic units payment is valid
define('MONERO_GATEWAY_DIFFICULTY_TARGET', 120);
// Do not edit these constants
define('MONERO_GATEWAY_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('MONERO_GATEWAY_PLUGIN_URL', plugin_dir_url(__FILE__));
define('MONERO_GATEWAY_ATOMIC_UNITS_POW', pow(10, MONERO_GATEWAY_ATOMIC_UNITS));
define('MONERO_GATEWAY_ATOMIC_UNITS_SPRINTF', '%.'.MONERO_GATEWAY_ATOMIC_UNITS.'f');
// Include our Gateway Class and register Payment Gateway with WooCommerce
add_action('plugins_loaded', 'monero_init', 1);
function monero_init() {
// If the class doesn't exist (== WooCommerce isn't installed), return NULL
if (!class_exists('WC_Payment_Gateway')) return;
// If we made it this far, then include our Gateway Class
require_once('include/class-monero-gateway.php');
// Create a new instance of the gateway so we have static variables set up
new Monero_Gateway($add_action=false);
// Include our Admin interface class
require_once('include/admin/class-monero-admin-interface.php');
add_filter('woocommerce_payment_gateways', 'monero_gateway');
function monero_gateway($methods) {
$methods[] = 'Monero_Gateway';
return $methods;
}
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'monero_payment');
function monero_payment($links) {
$plugin_links = array(
'<a href="'.admin_url('admin.php?page=monero_gateway_settings').'">'.__('Settings', 'monero_gateway').'</a>'
);
return array_merge($plugin_links, $links);
}
add_filter('cron_schedules', 'monero_cron_add_one_minute');
function monero_cron_add_one_minute($schedules) {
$schedules['one_minute'] = array(
'interval' => 60,
'display' => __('Once every minute', 'monero_gateway')
);
return $schedules;
}
add_action('wp', 'monero_activate_cron');
function monero_activate_cron() {
if(!wp_next_scheduled('monero_update_event')) {
wp_schedule_event(time(), 'one_minute', 'monero_update_event');
}
}
add_action('monero_update_event', 'monero_update_event');
function monero_update_event() {
Monero_Gateway::do_update_event();
}
add_action('woocommerce_thankyou_'.Monero_Gateway::get_id(), 'monero_order_confirm_page');
add_action('woocommerce_order_details_after_order_table', 'monero_order_page');
add_action('woocommerce_email_after_order_table', 'monero_order_email');
function monero_order_confirm_page($order_id) {
Monero_Gateway::customer_order_page($order_id);
}
function monero_order_page($order) {
if(!is_wc_endpoint_url('order-received'))
Monero_Gateway::customer_order_page($order);
}
function monero_order_email($order) {
Monero_Gateway::customer_order_email($order);
}
add_action('wc_ajax_monero_gateway_payment_details', 'monero_get_payment_details_ajax');
function monero_get_payment_details_ajax() {
Monero_Gateway::get_payment_details_ajax();
}
add_filter('woocommerce_currencies', 'monero_add_currency');
function monero_add_currency($currencies) {
$currencies['Monero'] = __('Monero', 'monero_gateway');
return $currencies;
}
add_filter('woocommerce_currency_symbol', 'monero_add_currency_symbol', 10, 2);
function monero_add_currency_symbol($currency_symbol, $currency) {
switch ($currency) {
case 'Monero':
$currency_symbol = 'XMR';
break;
}
return $currency_symbol;
}
if(Monero_Gateway::use_monero_price()) {
// This filter will replace all prices with amount in Monero (live rates)
add_filter('wc_price', 'monero_live_price_format', 10, 3);
function monero_live_price_format($price_html, $price_float, $args) {
if(!isset($args['currency']) || !$args['currency']) {
global $woocommerce;
$currency = strtoupper(get_woocommerce_currency());
} else {
$currency = strtoupper($args['currency']);
}
return Monero_Gateway::convert_wc_price($price_float, $currency);
}
// These filters will replace the live rate with the exchange rate locked in for the order
// We must be careful to hit all the hooks for price displays associated with an order,
// else the exchange rate can change dynamically (which it should for an order)
add_filter('woocommerce_order_formatted_line_subtotal', 'monero_order_item_price_format', 10, 3);
function monero_order_item_price_format($price_html, $item, $order) {
return Monero_Gateway::convert_wc_price_order($price_html, $order);
}
add_filter('woocommerce_get_formatted_order_total', 'monero_order_total_price_format', 10, 2);
function monero_order_total_price_format($price_html, $order) {
return Monero_Gateway::convert_wc_price_order($price_html, $order);
}
add_filter('woocommerce_get_order_item_totals', 'monero_order_totals_price_format', 10, 3);
function monero_order_totals_price_format($total_rows, $order, $tax_display) {
foreach($total_rows as &$row) {
$price_html = $row['value'];
$row['value'] = Monero_Gateway::convert_wc_price_order($price_html, $order);
}
return $total_rows;
}
}
add_action('wp_enqueue_scripts', 'monero_enqueue_scripts');
function monero_enqueue_scripts() {
if(Monero_Gateway::use_monero_price())
wp_dequeue_script('wc-cart-fragments');
if(Monero_Gateway::use_qr_code())
wp_enqueue_script('monero-qr-code', MONERO_GATEWAY_PLUGIN_URL.'assets/js/qrcode.min.js');
wp_enqueue_script('monero-clipboard-js', MONERO_GATEWAY_PLUGIN_URL.'assets/js/clipboard.min.js');
wp_enqueue_script('monero-gateway', MONERO_GATEWAY_PLUGIN_URL.'assets/js/monero-gateway-order-page.js');
wp_enqueue_style('monero-gateway', MONERO_GATEWAY_PLUGIN_URL.'assets/css/monero-gateway-order-page.css');
}
// [monero-price currency="USD"]
// currency: BTC, GBP, etc
// if no none, then default store currency
function monero_price_func( $atts ) {
global $woocommerce;
$a = shortcode_atts( array(
'currency' => get_woocommerce_currency()
), $atts );
$currency = strtoupper($a['currency']);
$rate = Monero_Gateway::get_live_rate($currency);
if($currency == 'BTC')
$rate_formatted = sprintf('%.8f', $rate / 1e8);
else
$rate_formatted = sprintf('%.5f', $rate / 1e8);
return "<span class=\"monero-price\">1 XMR = $rate_formatted $currency</span>";
}
add_shortcode('monero-price', 'monero_price_func');
// [monero-accepted-here]
function monero_accepted_func() {
return '<img src="'.MONERO_GATEWAY_PLUGIN_URL.'assets/images/monero-accepted-here.png" />';
}
add_shortcode('monero-accepted-here', 'monero_accepted_func');
}
register_deactivation_hook(__FILE__, 'monero_deactivate');
function monero_deactivate() {
$timestamp = wp_next_scheduled('monero_update_event');
wp_unschedule_event($timestamp, 'monero_update_event');
}
register_activation_hook(__FILE__, 'monero_install');
function monero_install() {
global $wpdb;
require_once( ABSPATH . '/wp-admin/includes/upgrade.php' );
$charset_collate = $wpdb->get_charset_collate();
$table_name = $wpdb->prefix . "monero_gateway_quotes";
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$sql = "CREATE TABLE $table_name (
order_id BIGINT(20) UNSIGNED NOT NULL,
payment_id VARCHAR(16) DEFAULT '' NOT NULL,
currency VARCHAR(6) DEFAULT '' NOT NULL,
rate BIGINT UNSIGNED DEFAULT 0 NOT NULL,
amount BIGINT UNSIGNED DEFAULT 0 NOT NULL,
paid TINYINT NOT NULL DEFAULT 0,
confirmed TINYINT NOT NULL DEFAULT 0,
pending TINYINT NOT NULL DEFAULT 1,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (order_id)
) $charset_collate;";
dbDelta($sql);
}
$table_name = $wpdb->prefix . "monero_gateway_quotes_txids";
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$sql = "CREATE TABLE $table_name (
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
payment_id VARCHAR(16) DEFAULT '' NOT NULL,
txid VARCHAR(64) DEFAULT '' NOT NULL,
amount BIGINT UNSIGNED DEFAULT 0 NOT NULL,
height MEDIUMINT UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (id),
UNIQUE KEY (payment_id, txid, amount)
) $charset_collate;";
dbDelta($sql);
}
$table_name = $wpdb->prefix . "monero_gateway_live_rates";
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$sql = "CREATE TABLE $table_name (
currency VARCHAR(6) DEFAULT '' NOT NULL,
rate BIGINT UNSIGNED DEFAULT 0 NOT NULL,
updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (currency)
) $charset_collate;";
dbDelta($sql);
}
}

View file

@ -1,54 +0,0 @@
<?php foreach($errors as $error): ?>
<div class="error"><p><strong>Monero Gateway Error</strong>: <?php echo $error; ?></p></div>
<?php endforeach; ?>
<h1>Monero Gateway Settings</h1>
<?php if($confirm_type === 'monero-wallet-rpc'): ?>
<div style="border:1px solid #ddd;padding:5px 10px;">
<?php
echo 'Wallet height: ' . $balance['height'] . '</br>';
echo 'Your balance is: ' . $balance['balance'] . '</br>';
echo 'Unlocked balance: ' . $balance['unlocked_balance'] . '</br>';
?>
</div>
<?php endif; ?>
<table class="form-table">
<?php echo $settings_html ?>
</table>
<h4><a href="https://github.com/monero-integrations/monerowp">Learn more about using the Monero payment gateway</a></h4>
<script>
function moneroUpdateFields() {
var confirmType = jQuery("#woocommerce_monero_gateway_confirm_type").val();
if(confirmType == "monero-wallet-rpc") {
jQuery("#woocommerce_monero_gateway_monero_address").closest("tr").hide();
jQuery("#woocommerce_monero_gateway_viewkey").closest("tr").hide();
jQuery("#woocommerce_monero_gateway_daemon_host").closest("tr").show();
jQuery("#woocommerce_monero_gateway_daemon_port").closest("tr").show();
} else {
jQuery("#woocommerce_monero_gateway_monero_address").closest("tr").show();
jQuery("#woocommerce_monero_gateway_viewkey").closest("tr").show();
jQuery("#woocommerce_monero_gateway_daemon_host").closest("tr").hide();
jQuery("#woocommerce_monero_gateway_daemon_port").closest("tr").hide();
}
var useMoneroPrices = jQuery("#woocommerce_monero_gateway_use_monero_price").is(":checked");
if(useMoneroPrices) {
jQuery("#woocommerce_monero_gateway_use_monero_price_decimals").closest("tr").show();
} else {
jQuery("#woocommerce_monero_gateway_use_monero_price_decimals").closest("tr").hide();
}
}
moneroUpdateFields();
jQuery("#woocommerce_monero_gateway_confirm_type").change(moneroUpdateFields);
jQuery("#woocommerce_monero_gateway_use_monero_price").change(moneroUpdateFields);
</script>
<style>
#woocommerce_monero_gateway_monero_address,
#woocommerce_monero_gateway_viewkey {
width: 100%;
}
</style>

View file

@ -1,23 +1,23 @@
<table class="striped" style="width:100%" cellspacing="0" cellpadding="5">
<tr>
<td>Exchange rate</td>
<td>1 XMR = <?php echo $details['rate_formatted'].' '.$details['currency']; ?></td>
<td>1 WOW = <?php echo $details['rate_formatted'].' '.$details['currency']; ?></td>
</tr>
<tr>
<td>Total amount</td>
<td><?php echo $details['amount_total_formatted']; ?> XMR</td>
<td><?php echo $details['amount_total_formatted']; ?> WOW</td>
</tr>
<tr>
<td>Total paid</td>
<td><?php echo $details['amount_paid_formatted']; ?> XMR</td>
<td><?php echo $details['amount_paid_formatted']; ?> WOW</td>
</tr>
<tr>
<td>Total due</td>
<td><?php echo $details['amount_due_formatted']; ?> XMR</td>
<td><?php echo $details['amount_due_formatted']; ?> WOW</td>
</tr>
<tr>
<td>Order age</td>
<td><?php echo Monero_Gateway::format_seconds_to_time($details['order_age']) ?> ago</td>
<td><?php echo Wownero_Gateway::format_seconds_to_time($details['order_age']) ?> ago</td>
</tr>
<tr>
<td>Order exipires</td>

View file

@ -0,0 +1,54 @@
<?php foreach($errors as $error): ?>
<div class="error"><p><strong>Wownero Gateway Error</strong>: <?php echo $error; ?></p></div>
<?php endforeach; ?>
<h1>Wownero Gateway Settings</h1>
<?php if($confirm_type === 'wownero-wallet-rpc'): ?>
<div style="border:1px solid #ddd;padding:5px 10px;">
<?php
echo 'Wallet height' . $balance['height'] . '</br>';
echo 'Your balance is: ' . $balance['balance'] . '</br>';
echo 'Unlocked balance: ' . $balance['unlocked_balance'] . '</br>';
?>
</div>
<?php endif; ?>
<table class="form-table">
<?php echo $settings_html ?>
</table>
<h4><a href="https://github.com/monero-integrations/monerowp">Learn more about using the Wownero payment gateway</a></h4>
<script>
function wowneroUpdateFields() {
var confirmType = jQuery("#woocommerce_wownero_gateway_confirm_type").val();
if(confirmType == "wownero-wallet-rpc") {
jQuery("#woocommerce_wownero_gateway_wownero_address").closest("tr").hide();
jQuery("#woocommerce_wownero_gateway_viewkey").closest("tr").hide();
jQuery("#woocommerce_wownero_gateway_daemon_host").closest("tr").show();
jQuery("#woocommerce_wownero_gateway_daemon_port").closest("tr").show();
} else {
jQuery("#woocommerce_wownero_gateway_wownero_address").closest("tr").show();
jQuery("#woocommerce_wownero_gateway_viewkey").closest("tr").show();
jQuery("#woocommerce_wownero_gateway_daemon_host").closest("tr").hide();
jQuery("#woocommerce_wownero_gateway_daemon_port").closest("tr").hide();
}
var useWowneroPrices = jQuery("#woocommerce_wownero_gateway_use_wownero_price").is(":checked");
if(useWowneroPrices) {
jQuery("#woocommerce_wownero_gateway_use_wownero_price_decimals").closest("tr").show();
} else {
jQuery("#woocommerce_wownero_gateway_use_wownero_price_decimals").closest("tr").hide();
}
}
wowneroUpdateFields();
jQuery("#woocommerce_wownero_gateway_confirm_type").change(wowneroUpdateFields);
jQuery("#woocommerce_wownero_gateway_use_wownero_price").change(wowneroUpdateFields);
</script>
<style>
#woocommerce_wownero_gateway_wownero_address,
#woocommerce_wownero_gateway_viewkey {
width: 100%;
}
</style>

View file

@ -4,7 +4,7 @@
<?php echo $method_title ?>
</h2>
<p style="margin: 0 0 16px;">Your order has been confirmed. Thank you for paying with Monero!</p>
<p style="margin: 0 0 16px;">Your order has been confirmed. Thank you for paying with Wownero!</p>
<?php elseif($details['status'] == 'expired' || $details['status'] == 'expired_partial'): ?>
@ -37,7 +37,7 @@
<td class="td" style="text-align: left; vertical-align: middle; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; word-wrap: break-word; color: #636363; border: 1px solid #e5e5e5; padding: 12px;">
TOTAL DUE: <br/>
<strong>
<?php echo $details['amount_total_formatted']; ?> XMR
<?php echo $details['amount_total_formatted']; ?> WOW
</strong>
</td>
</tr>
@ -45,7 +45,7 @@
<td class="td" style="text-align: left; vertical-align: middle; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; word-wrap: break-word; color: #636363; border: 1px solid #e5e5e5; padding: 12px;">
EXCHANGE RATE: <br/>
<strong>
1 XMR = <?php echo $details['rate_formatted'] . ' ' . $details['currency']; ?>
1 WOW = <?php echo $details['rate_formatted'] . ' ' . $details['currency']; ?>
</strong>
</td>
</tr>
@ -53,4 +53,4 @@
</table>
</div>
<?php endif; ?>
<?php endif; ?>

View file

@ -2,35 +2,35 @@
<h2 class="woocommerce-order-details__title"><?php echo $method_title ?></h2>
<noscript><h1>You must enable javascript in order to confirm your order</h1></noscript>
<strong id="monero_payment_messages">
<strong id="wownero_payment_messages">
<span class="monero_payment_unpaid">Please pay the amount due to complete your transactions. Your order will expire in <span class="monero_payment_expire_time"></span> if payment is not received.</span>
<span class="wownero_payment_unpaid">Please pay the amount due to complete your transactions. Your order will expire in <span class="wownero_payment_expire_time"></span> if payment is not received.</span>
<span class="monero_payment_partial">We have received partial payment. Please pay the remaining amount to complete your transactions. Your order will expire in <span class="monero_payment_expire_time"></span> if payment is not received.</span>
<span class="wownero_payment_partial">We have received partial payment. Please pay the remaining amount to complete your transactions. Your order will expire in <span class="wownero_payment_expire_time"></span> if payment is not received.</span>
<span class="monero_payment_paid">We have received your payment in full. Please wait while amount is confirmed. Approximate confirm time is <span class="monero_confirm_time"></span>. <?php if(is_wc_endpoint_url('order-received')): ?><br/>You can <a href="<?php echo $details['my_order_url']; ?>">check your payment status</a> anytime in your account dashboard.<?php endif; ?></span>
<span class="wownero_payment_paid">We have received your payment in full. Please wait while amount is confirmed. Approximate confirm time is <span class="wownero_confirm_time"></span>. <?php if(is_wc_endpoint_url('order-received')): ?><br/>You can <a href="<?php echo $details['my_order_url']; ?>">check your payment status</a> anytime in your account dashboard.<?php endif; ?></span>
<span class="monero_payment_confirmed">Your order has been confirmed. Thank you for paying with Monero!</span>
<span class="wownero_payment_confirmed">Your order has been confirmed. Thank you for paying with Wownero!</span>
<span class="monero_payment_expired">Your order has expired. Please place another order to complete your purchase.</span>
<span class="wownero_payment_expired">Your order has expired. Please place another order to complete your purchase.</span>
<span class="monero_payment_expired_partial">Your order has expired. Please contact the store owner to receive refund on your partial payment.</span>
<span class="wownero_payment_expired_partial">Your order has expired. Please contact the store owner to receive refund on your partial payment.</span>
</strong>
<ul class="order_details" style="margin-top:30px">
<li>
Pay to:
<strong class="monero_details_row">
<span class="monero_details_main" id="monero_integrated_address"></span>
<span class="monero_details_right button-row">
<strong class="wownero_details_row">
<span class="wownero_details_main" id="wownero_integrated_address"></span>
<span class="wownero_details_right button-row">
<?php if($show_qr): ?>
<button href="#" class="button" title="Show QR Code" onclick="monero_showQR()">
<button href="#" class="button" title="Show QR Code" onclick="wownero_showQR()">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 512 512" version="1"><path d="M0 512h233V279H0zm47-186h139v139H47z"/><path d="M93 372h47v47H93zm279 93h47v47h-47zm93 0h47v47h-47z"/><path d="M465 326h-46v-47H279v233h47V372h46v47h140V279h-47zM0 233h233V0H0zM47 47h139v139H47z"/><path d="M93 93h47v47H93zM279 0v233h233V0zm186 186H326V47h139z"/><path d="M372 93h47v47h-47z"/></svg>
</button>
<?php endif; ?>
<button href="#" class="button clipboard" title="Copy Address"
data-clipboard-target="#monero_integrated_address">
data-clipboard-target="#wownero_integrated_address">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 512 512" version="1"><path d="M504 118c-6-6-12-8-20-8H365c-11 0-23 3-36 11V27c0-7-3-14-8-19s-12-8-20-8H183c-8 0-16 2-25 6-10 4-17 8-22 13L19 136c-5 5-9 12-13 22-4 9-6 17-6 25v192c0 7 3 14 8 19s12 8 19 8h156v82c0 8 2 14 8 20 5 5 12 8 19 8h274c8 0 14-3 20-8 5-6 8-12 8-20V137c0-8-3-14-8-19zm-175 52v86h-85l85-86zM146 61v85H61l85-85zm56 185c-5 5-10 12-14 21-3 9-5 18-5 25v73H37V183h118c8 0 14-3 20-8 5-6 8-12 8-20V37h109v118l-90 91zm273 229H219V292h119c8 0 14-2 19-8 6-5 8-11 8-19V146h110v329z"/></svg>
</button>
</span>
@ -38,13 +38,13 @@
</li>
<li>
Total due:
<strong class="monero_details_row">
<span class="monero_details_main">
<span id="monero_total_due"></span> XMR
<strong class="wownero_details_row">
<span class="wownero_details_main">
<span id="wownero_total_due"></span> WOW
</span>
<span class="monero_details_right button-row">
<span class="wownero_details_right button-row">
<button href="#" class="button clipboard" title="Copy Amount"
data-clipboard-target="#monero_total_due">
data-clipboard-target="#wownero_total_due">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 512 512" version="1"><path d="M504 118c-6-6-12-8-20-8H365c-11 0-23 3-36 11V27c0-7-3-14-8-19s-12-8-20-8H183c-8 0-16 2-25 6-10 4-17 8-22 13L19 136c-5 5-9 12-13 22-4 9-6 17-6 25v192c0 7 3 14 8 19s12 8 19 8h156v82c0 8 2 14 8 20 5 5 12 8 19 8h274c8 0 14-3 20-8 5-6 8-12 8-20V137c0-8-3-14-8-19zm-175 52v86h-85l85-86zM146 61v85H61l85-85zm56 185c-5 5-10 12-14 21-3 9-5 18-5 25v73H37V183h118c8 0 14-3 20-8 5-6 8-12 8-20V37h109v118l-90 91zm273 229H219V292h119c8 0 14-2 19-8 6-5 8-11 8-19V146h110v329z"/></svg>
</button>
</span>
@ -53,23 +53,23 @@
<li style="display:none">
Total order amount:
<strong>
<span id="monero_total_amount"></span> XMR
<span id="wownero_total_amount"></span> WOW
</strong>
</li>
<li>
Total paid:
<strong>
<span id="monero_total_paid"></span> XMR
<span id="wownero_total_paid"></span> WOW
</strong>
</li>
<li>
Exchange rate:<strong id="monero_exchange_rate"></strong>
Exchange rate:<strong id="wownero_exchange_rate"></strong>
</li>
</ul>
<table id="monero_tx_table" style="display:none;">
<table id="wownero_tx_table" style="display:none;">
<thead>
<tr>
<th>Transaction id</th>
@ -80,21 +80,21 @@
<tbody>
</tbody>
</table>
<div id="monero_tx_none" style="display:none;">
<div id="wownero_tx_none" style="display:none;">
</div>
<div id="monero_qr_code_container" style="display:none;" onclick="monero_showQR(false)">
<div id="monero_qr_code">
<div id="wownero_qr_code_container" style="display:none;" onclick="wownero_showQR(false)">
<div id="wownero_qr_code">
</div>
</div>
</section>
<div id="monero_toast"></div>
<div id="wownero_toast"></div>
<script type="text/javascript">
var monero_show_qr = <?php echo $show_qr ? 'true' : 'false'; ?>;
var monero_ajax_url = '<?php echo $ajax_url; ?>';
var monero_explorer_url = '<?php echo MONERO_GATEWAY_EXPLORER_URL; ?>';
var monero_details = <?php echo $details_json; ?>;
var wownero_show_qr = <?php echo $show_qr ? 'true' : 'false'; ?>;
var wownero_ajax_url = '<?php echo $ajax_url; ?>';
var wownero_explorer_url = '<?php echo MONERO_GATEWAY_EXPLORER_URL; ?>';
var wownero_details = <?php echo $details_json; ?>;
</script>

View file

@ -0,0 +1,249 @@
<?php
/*
Plugin Name: Wownero Woocommerce Gateway
Plugin URI: https://github.com/monero-integrations/monerowp
Description: Extends WooCommerce by adding a Wownero Gateway
Version: 3.0.0
Tested up to: 4.9.8
Author: mosu-forge, SerHack
Author URI: https://monerointegrations.com/
*/
// This code isn't for Dark Net Markets, please report them to Authority!
defined( 'ABSPATH' ) || exit;
// Constants, you can edit these if you fork this repo
define('MONERO_GATEWAY_MAINNET_EXPLORER_URL', 'https://explore.wownero.com/');
define('MONERO_GATEWAY_TESTNET_EXPLORER_URL', 'http://explorer.wowne.ro:8082/');
define('MONERO_GATEWAY_ADDRESS_PREFIX', 0x12);
define('MONERO_GATEWAY_ADDRESS_PREFIX_INTEGRATED', 0x13);
define('MONERO_GATEWAY_ATOMIC_UNITS', 11);
define('MONERO_GATEWAY_ATOMIC_UNIT_THRESHOLD', 10); // Amount under in atomic units payment is valid
define('MONERO_GATEWAY_DIFFICULTY_TARGET', 120);
// Do not edit these constants
define('MONERO_GATEWAY_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('MONERO_GATEWAY_PLUGIN_URL', plugin_dir_url(__FILE__));
define('MONERO_GATEWAY_ATOMIC_UNITS_POW', pow(10, MONERO_GATEWAY_ATOMIC_UNITS));
define('MONERO_GATEWAY_ATOMIC_UNITS_SPRINTF', '%.'.MONERO_GATEWAY_ATOMIC_UNITS.'f');
// Include our Gateway Class and register Payment Gateway with WooCommerce
add_action('plugins_loaded', 'wownero_init', 1);
function wownero_init() {
// If the class doesn't exist (== WooCommerce isn't installed), return NULL
if (!class_exists('WC_Payment_Gateway')) return;
// If we made it this far, then include our Gateway Class
require_once('include/class-wownero-gateway.php');
// Create a new instance of the gateway so we have static variables set up
new Wownero_Gateway($add_action=false);
// Include our Admin interface class
require_once('include/admin/class-wownero-admin-interface.php');
add_filter('woocommerce_payment_gateways', 'wownero_gateway');
function wownero_gateway($methods) {
$methods[] = 'Wownero_Gateway';
return $methods;
}
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'wownero_payment');
function wownero_payment($links) {
$plugin_links = array(
'<a href="'.admin_url('admin.php?page=wownero_gateway_settings').'">'.__('Settings', 'wownero_gateway').'</a>'
);
return array_merge($plugin_links, $links);
}
add_filter('cron_schedules', 'wownero_cron_add_one_minute');
function wownero_cron_add_one_minute($schedules) {
$schedules['one_minute'] = array(
'interval' => 60,
'display' => __('Once every minute', 'wownero_gateway')
);
return $schedules;
}
add_action('wp', 'wownero_activate_cron');
function wownero_activate_cron() {
if(!wp_next_scheduled('wownero_update_event')) {
wp_schedule_event(time(), 'one_minute', 'wownero_update_event');
}
}
add_action('wownero_update_event', 'wownero_update_event');
function wownero_update_event() {
Wownero_Gateway::do_update_event();
}
add_action('woocommerce_thankyou_'.Wownero_Gateway::get_id(), 'wownero_order_confirm_page');
add_action('woocommerce_order_details_after_order_table', 'wownero_order_page');
add_action('woocommerce_email_after_order_table', 'wownero_order_email');
function wownero_order_confirm_page($order_id) {
Wownero_Gateway::customer_order_page($order_id);
}
function wownero_order_page($order) {
if(!is_wc_endpoint_url('order-received'))
Wownero_Gateway::customer_order_page($order);
}
function wownero_order_email($order) {
Wownero_Gateway::customer_order_email($order);
}
add_action('wc_ajax_wownero_gateway_payment_details', 'wownero_get_payment_details_ajax');
function wownero_get_payment_details_ajax() {
Wownero_Gateway::get_payment_details_ajax();
}
add_filter('woocommerce_currencies', 'wownero_add_currency');
function wownero_add_currency($currencies) {
$currencies['Wownero'] = __('Wownero', 'wownero_gateway');
return $currencies;
}
add_filter('woocommerce_currency_symbol', 'wownero_add_currency_symbol', 10, 2);
function wownero_add_currency_symbol($currency_symbol, $currency) {
switch ($currency) {
case 'Wownero':
$currency_symbol = 'WOW';
break;
}
return $currency_symbol;
}
if(Wownero_Gateway::use_wownero_price()) {
// This filter will replace all prices with amount in Wownero (live rates)
add_filter('wc_price', 'wownero_live_price_format', 10, 3);
function wownero_live_price_format($price_html, $price_float, $args) {
if(!isset($args['currency']) || !$args['currency']) {
global $woocommerce;
$currency = strtoupper(get_woocommerce_currency());
} else {
$currency = strtoupper($args['currency']);
}
return Wownero_Gateway::convert_wc_price($price_float, $currency);
}
// These filters will replace the live rate with the exchange rate locked in for the order
// We must be careful to hit all the hooks for price displays associated with an order,
// else the exchange rate can change dynamically (which it should for an order)
add_filter('woocommerce_order_formatted_line_subtotal', 'wownero_order_item_price_format', 10, 3);
function wownero_order_item_price_format($price_html, $item, $order) {
return Wownero_Gateway::convert_wc_price_order($price_html, $order);
}
add_filter('woocommerce_get_formatted_order_total', 'wownero_order_total_price_format', 10, 2);
function wownero_order_total_price_format($price_html, $order) {
return Wownero_Gateway::convert_wc_price_order($price_html, $order);
}
add_filter('woocommerce_get_order_item_totals', 'wownero_order_totals_price_format', 10, 3);
function wownero_order_totals_price_format($total_rows, $order, $tax_display) {
foreach($total_rows as &$row) {
$price_html = $row['value'];
$row['value'] = Wownero_Gateway::convert_wc_price_order($price_html, $order);
}
return $total_rows;
}
}
add_action('wp_enqueue_scripts', 'wownero_enqueue_scripts');
function wownero_enqueue_scripts() {
if(Wownero_Gateway::use_wownero_price())
wp_dequeue_script('wc-cart-fragments');
if(Wownero_Gateway::use_qr_code())
wp_enqueue_script('wownero-qr-code', MONERO_GATEWAY_PLUGIN_URL.'assets/js/qrcode.min.js');
wp_enqueue_script('wownero-clipboard-js', MONERO_GATEWAY_PLUGIN_URL.'assets/js/clipboard.min.js');
wp_enqueue_script('wownero-gateway', MONERO_GATEWAY_PLUGIN_URL.'assets/js/wownero-gateway-order-page.js');
wp_enqueue_style('wownero-gateway', MONERO_GATEWAY_PLUGIN_URL.'assets/css/wownero-gateway-order-page.css');
}
// [wownero-price currency="USD"]
// currency: BTC, GBP, etc
// if no none, then default store currency
function wownero_price_func( $atts ) {
global $woocommerce;
$a = shortcode_atts( array(
'currency' => get_woocommerce_currency()
), $atts );
$currency = strtoupper($a['currency']);
$rate = Wownero_Gateway::get_live_rate($currency);
if($currency == 'BTC')
$rate_formatted = sprintf('%.8f', $rate / 1e8);
else
$rate_formatted = sprintf('%.5f', $rate / 1e8);
return "<span class=\"wownero-price\">1 XMR = $rate_formatted $currency</span>";
}
add_shortcode('wownero-price', 'wownero_price_func');
// [wownero-accepted-here]
function wownero_accepted_func() {
return '<img src="'.MONERO_GATEWAY_PLUGIN_URL.'assets/images/wownero-accepted-here.png" />';
}
add_shortcode('wownero-accepted-here', 'wownero_accepted_func');
}
register_deactivation_hook(__FILE__, 'wownero_deactivate');
function wownero_deactivate() {
$timestamp = wp_next_scheduled('wownero_update_event');
wp_unschedule_event($timestamp, 'wownero_update_event');
}
register_activation_hook(__FILE__, 'wownero_install');
function wownero_install() {
global $wpdb;
require_once( ABSPATH . '/wp-admin/includes/upgrade.php' );
$charset_collate = $wpdb->get_charset_collate();
$table_name = $wpdb->prefix . "wownero_gateway_quotes";
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$sql = "CREATE TABLE $table_name (
order_id BIGINT(20) UNSIGNED NOT NULL,
payment_id VARCHAR(16) DEFAULT '' NOT NULL,
currency VARCHAR(6) DEFAULT '' NOT NULL,
rate BIGINT UNSIGNED DEFAULT 0 NOT NULL,
amount BIGINT UNSIGNED DEFAULT 0 NOT NULL,
paid TINYINT NOT NULL DEFAULT 0,
confirmed TINYINT NOT NULL DEFAULT 0,
pending TINYINT NOT NULL DEFAULT 1,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (order_id)
) $charset_collate;";
dbDelta($sql);
}
$table_name = $wpdb->prefix . "wownero_gateway_quotes_txids";
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$sql = "CREATE TABLE $table_name (
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
payment_id VARCHAR(16) DEFAULT '' NOT NULL,
txid VARCHAR(64) DEFAULT '' NOT NULL,
amount BIGINT UNSIGNED DEFAULT 0 NOT NULL,
height MEDIUMINT UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (id),
UNIQUE KEY (payment_id, txid, amount)
) $charset_collate;";
dbDelta($sql);
}
$table_name = $wpdb->prefix . "wownero_gateway_live_rates";
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$sql = "CREATE TABLE $table_name (
currency VARCHAR(6) DEFAULT '' NOT NULL,
rate BIGINT UNSIGNED DEFAULT 0 NOT NULL,
updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (currency)
) $charset_collate;";
dbDelta($sql);
}
}