Some code style
This commit is contained in:
parent
dbac9f8482
commit
63398d630a
@ -1,9 +1,11 @@
|
||||
<?php
|
||||
/* Main Gateway of Monero using a daemon online */
|
||||
|
||||
class Monero_Gateway extends WC_Payment_Gateway {
|
||||
class Monero_Gateway extends WC_Payment_Gateway
|
||||
{
|
||||
|
||||
function __construct() {
|
||||
function __construct()
|
||||
{
|
||||
|
||||
$this->id = "monero_gateway";
|
||||
$this->method_title = __("Monero GateWay", 'monero_gateway');
|
||||
@ -29,19 +31,28 @@ class Monero_Gateway extends WC_Payment_Gateway {
|
||||
}
|
||||
|
||||
|
||||
add_action('admin_notices', array( $this, 'do_ssl_check' ) );
|
||||
add_action('admin_notices', array( $this, 'validate_fields'));
|
||||
add_action('admin_notices', array(
|
||||
$this,
|
||||
'do_ssl_check'
|
||||
));
|
||||
add_action('admin_notices', array(
|
||||
$this,
|
||||
'validate_fields'
|
||||
));
|
||||
//if($this->get_option('light_mode') != true){
|
||||
|
||||
|
||||
add_action('woocommerce_thankyou_' . $this->id, array( $this, 'instruction' ) ));
|
||||
if (is_admin()) {
|
||||
/* Save Settings */
|
||||
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
|
||||
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array(
|
||||
$this,
|
||||
'process_admin_options'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public function admin_options(){
|
||||
public function admin_options()
|
||||
{
|
||||
echo "<h1>Monero Payment Gateway</h1>";
|
||||
echo "<p>Welcome to Monero Extension for WooCommerce. Getting started: Add your address :D <a href='https://reddit.com/u/serhack'>Support Me</a>";
|
||||
echo "<table class='form-table'>";
|
||||
@ -52,33 +63,34 @@ class Monero_Gateway extends WC_Payment_Gateway {
|
||||
|
||||
|
||||
|
||||
public function init_form_fields() {
|
||||
public function init_form_fields()
|
||||
{
|
||||
$this->form_fields = array(
|
||||
'enabled' => array(
|
||||
'title' => __('Enable / Disable', 'monero_gateway'),
|
||||
'label' => __('Enable this payment gateway', 'monero_gateway'),
|
||||
'type' => 'checkbox',
|
||||
'default' => 'no',
|
||||
'default' => 'no'
|
||||
),
|
||||
|
||||
'title' => array(
|
||||
'title' => __('Title', 'monero_gateway'),
|
||||
'type' => 'text',
|
||||
'desc_tip' => __('Payment title the customer will see during the checkout process.', 'monero_gateway'),
|
||||
'default' => __('Monero XMR Payment', 'monero_gateway' ),
|
||||
'default' => __('Monero XMR Payment', 'monero_gateway')
|
||||
),
|
||||
'description' => array(
|
||||
'title' => __('Description', 'monero_gateway'),
|
||||
'type' => 'textarea',
|
||||
'desc_tip' => __('Payment description the customer will see during the checkout process.', 'monero_gateway'),
|
||||
'default' => __('Pay securely using XMR.', 'monero_gateway' ),
|
||||
'default' => __('Pay securely using XMR.', 'monero_gateway')
|
||||
|
||||
),
|
||||
'monero_address' => array(
|
||||
'title' => __('Monero Address', 'monero_gateway'),
|
||||
'label' => __('Useful for people that have not a daemon online'),
|
||||
'type' => 'text',
|
||||
'desc_tip' => __('Monero Wallet Address', 'monero_gateway' ),
|
||||
'desc_tip' => __('Monero Wallet Address', 'monero_gateway')
|
||||
),
|
||||
/* 'daemon_host' => array(
|
||||
'title' => __('Daemon Host/ IP', 'monero_gateway'),
|
||||
@ -98,13 +110,14 @@ class Monero_Gateway extends WC_Payment_Gateway {
|
||||
'label' => __('Enable Test Mode', 'monero_gateway'),
|
||||
'type' => 'checkbox',
|
||||
'description' => __('Place the payment gateway in test mode.', 'monero_gateway'),
|
||||
'default' => 'no',
|
||||
'default' => 'no'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function retriveprice($currency) {
|
||||
public function retriveprice($currency)
|
||||
{
|
||||
$xmr_price = file_get_contents('https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=BTC,USD,EUR&extraParams=your_app_name');
|
||||
$l = json_decode($xmr_price, TRUE);
|
||||
if ($currency == 'USD') {
|
||||
@ -115,7 +128,8 @@ class Monero_Gateway extends WC_Payment_Gateway {
|
||||
}
|
||||
}
|
||||
|
||||
public function changeto($amount, $currency){
|
||||
public function changeto($amount, $currency)
|
||||
{
|
||||
$xmr_live_price = $this->retriveprice($currency);
|
||||
$new_amount = $amount / $xmr_live_price;
|
||||
return $new_amount;
|
||||
@ -123,7 +137,8 @@ class Monero_Gateway extends WC_Payment_Gateway {
|
||||
|
||||
|
||||
// Submit payment and handle response
|
||||
public function process_payment( $order_id ) {
|
||||
public function process_payment($order_id)
|
||||
{
|
||||
$order = wc_get_order($order_id);
|
||||
$order->update_status('on-hold', __('Awaiting offline payment', 'monero_gateway'));
|
||||
// Reduce stock levels
|
||||
@ -143,7 +158,8 @@ class Monero_Gateway extends WC_Payment_Gateway {
|
||||
|
||||
|
||||
// Validate fields
|
||||
public function validate_fields() {
|
||||
public function validate_fields()
|
||||
{
|
||||
if ($this->check_monero() != TRUE) {
|
||||
echo "<div class=\"error\"><p>Your Monero Address Seems not valid. Have you checked it?</p></div>";
|
||||
}
|
||||
@ -151,18 +167,18 @@ class Monero_Gateway extends WC_Payment_Gateway {
|
||||
}
|
||||
|
||||
|
||||
public function check_monero(){
|
||||
public function check_monero()
|
||||
{
|
||||
$monero_address = $this->settings['monero_address'];
|
||||
if (
|
||||
strlen($monero_address) == 95 && substr($monero_address, 1)
|
||||
) {
|
||||
if (strlen($monero_address) == 95 && substr($monero_address, 1)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function instruction($order_id){
|
||||
public function instruction($order_id)
|
||||
{
|
||||
$order = wc_get_order($order_id);
|
||||
$amount = floatval(preg_replace('#[^\d.]#', '', $order->order_total));
|
||||
$currency = $order->currency;
|
||||
@ -232,7 +248,8 @@ class Monero_Gateway extends WC_Payment_Gateway {
|
||||
|
||||
// Check if we are forcing SSL on checkout pages
|
||||
// Custom function not required by the Gateway
|
||||
public function do_ssl_check() {
|
||||
public function do_ssl_check()
|
||||
{
|
||||
if ($this->enabled == "yes") {
|
||||
if (get_option('woocommerce_force_ssl_checkout') == "no") {
|
||||
echo "<div class=\"error\"><p>" . sprintf(__("<strong>%s</strong> is enabled and WooCommerce is not forcing the SSL certificate on your checkout page. Please ensure that you have a valid SSL certificate and that you are <a href=\"%s\">forcing the checkout pages to be secured.</a>"), $this->method_title, admin_url('admin.php?page=wc-settings&tab=checkout')) . "</p></div>";
|
||||
|
Loading…
Reference in New Issue
Block a user