commit fe9063b615100e37be0f0d4cc75d9c574c3f30bb Author: fekt Date: Sat May 21 19:42:04 2022 -0400 Initial commit diff --git a/hush-woocommerce-gateway.php b/hush-woocommerce-gateway.php new file mode 100644 index 0000000..203e72b --- /dev/null +++ b/hush-woocommerce-gateway.php @@ -0,0 +1,278 @@ +' . __( 'Configure', 'hush-wc-gateway' ) . '' + ); + + return array_merge( $plugin_links, $links ); +} + + +/** + * Set and save expected Hush payment details when order created + */ +add_action('woocommerce_checkout_create_order', 'set_hush_payment_details', 20, 2); +function set_hush_payment_details( $order, $data ) { + + // Get order amount + $orderAmt = $order->get_total(); + + // Get plugin options + $options = get_option('woocommerce_hush_gateway_settings', 'default text'); + + // Get HUSH price from CoinGecko and convert amount to send + $request = wp_remote_get('https://api.coingecko.com/api/v3/simple/price?ids=hush&vs_currencies=btc%2Cusd%2Ceur%2Ceth%2Cgbp%2Ccny%2Cjpy%2Cidr%2Crub%2Ccad%2Csgd%2Cchf%2Cinr%2Caud%2Cinr%2Ckrw%2Cthb%2Cnzd%2Czar%2Cvef%2Cxau%2Cxag%2Cvnd%2Csar%2Ctwd%2Caed%2Cars%2Cbdt%2Cbhd%2Cbmd%2Cbrl%2Cclp%2Cczk%2Cdkk%2Chuf%2Cils%2Ckwd%2Clkr%2Cpkr%2Cnok%2Ctry%2Csek%2Cmxn%2Cuah%2Chkd&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true'); + + if( is_wp_error( $request ) ) { + return false; + } + + $body = wp_remote_retrieve_body( $request ); + $data = json_decode( $body, true); + + if( ! empty( $data ) ) { + $hushPrice = $data['hush']['usd']; + } + + // Convert addresses to an array + $hushAddressArray = explode(",", $options['hushAddresses']); + + // Shuffle for random address + shuffle($hushAddressArray); + $hushAddress = trim($hushAddressArray[0]); + + // Get volatility markup option + $markup = $options['volatilityMarkup']; + + // Set amount that should be sent based on USD and markup + $hushAmt = $orderAmt / $hushPrice; + $hushAmt = $hushAmt + ($hushAmt * $markup); + $hushAmt = number_format((float)$hushAmt, 8, '.', ''); + + // Save payment instruction related meta for verifying orders later + $order->update_meta_data( '_hush_price', $hushPrice ); + $order->update_meta_data( '_hush_receive_address', $hushAddress); + $order->update_meta_data( '_hush_expected', $hushAmt ); + $order->save(); +} + + +/** + * Display expected HUSH payment details on the admin order edit page + */ +add_action( 'woocommerce_admin_order_data_after_billing_address', 'hush_display_admin_order_meta', 10, 1 ); +function hush_display_admin_order_meta($order){ + echo "

Receive Address: ". get_post_meta( $order->get_id(), '_hush_receive_address', true ) . "

"; + echo "

Expected HUSH: ". get_post_meta( $order->get_id(), '_hush_expected', true ) . "

"; + echo "

Exchange Rate: $". get_post_meta( $order->get_id(), '_hush_price', true ) . " USD

"; +} + + +/** + * Hush Payment Gateway + * Provides simple instructions for customers to pay with Hush + * We load it later to ensure WC is loaded first since we're extending it. + * + * @class Hush_WC_Gateway + * @extends WC_Payment_Gateway + * @version 1.0.0 + * @package WooCommerce/Classes/Payment + * @author Hush Developers + */ +add_action( 'plugins_loaded', 'hush_gateway_init', 11 ); +function hush_gateway_init() { + + class Hush_WC_Gateway extends WC_Payment_Gateway { + + /** + * Constructor for the gateway. + */ + public function __construct() { + + $this->id = 'hush_gateway'; + $this->icon = apply_filters('woocommerce_hush_icon', ''); + $this->has_fields = false; + $this->method_title = __( 'HUSH', 'hush-wc-gateway' ); + $this->method_description = __( 'Provides simple instructions for customers to pay with HUSH', 'hush-wc-gateway' ); + + // Load the settings. + $this->init_form_fields(); + $this->init_settings(); + + // Define user set variables + $this->title = $this->get_option( 'title' ); + $this->volatilityMarkup = $this->get_option( 'volatilityMarkup' ); + $this->checkoutInstructions = $this->get_option( 'checkoutInstructions' ); + $this->hushAddresses = $this->get_option( 'hushAddresses' ); + + // Actions + add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); + add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'thankyou_page' ) ); + + } + + + /** + * Initialize Gateway Settings Form Fields + * This is where the Store Owners will enter all of their Hush Settings. + */ + public function init_form_fields() { + + $this->form_fields = apply_filters( 'hush_form_fields', array( + + 'enabled' => array( + 'title' => __( 'Enable/Disable:', 'hush-wc-gateway' ), + 'type' => 'checkbox', + 'label' => __( 'Enable HUSH', 'hush-wc-gateway' ), + 'default' => 'yes' + ), + + 'checkoutInstructions' => array( + 'title' => __( 'Checkout Payment Instructions:', 'hush-wc-gateway' ), + 'type' => 'textarea', + 'description' => __( 'This text will be displayed on the order confirmation/thank you page, letting the customer know where to send payment.' ), + 'default' => __( 'Thank you for supporting the Hush network. Manual payment instructions are below. Your order will remain on hold until payment is manually verified as being received. Please send payment as soon as possible. We reserve the right to cancel any orders due to extreme market volatility conditions.', 'hush-wc-gateway' ), + 'desc_tip' => true, + ), + + 'title' => array( + 'title' => __( 'Title:', 'hush-wc-gateway' ), + 'type' => 'text', + 'description' => __( 'This controls the title for the payment method the customer sees during checkout.', 'hush-wc-gateway' ), + 'default' => __( 'HUSH', 'hush-wc-gateway' ), + 'desc_tip' => true, + ), + + 'hushAddresses' => array( + 'title' => __( 'HUSH Address:', 'hush-wc-gateway' ), + 'type' => 'textarea', + 'description' => __( 'Enter a comma separated list of Hush addresses to be used for receiving payments. You can enter as many as you want and update this setting as often as you like for added privacy. During checkout, 1 address from this list will be chosen randomly for the customer to send payment to. It is recommended to submit at least 10 addresses and change once a month for privacy.' ), + 'default' => __( '', 'hush-wc-gateway' ), + 'desc_tip' => true, + ), + + 'volatilityMarkup' => array( + 'title' => __( 'Volatility markup:', 'hush-wc-gateway' ), + 'type' => 'text', + 'description' => __( 'This allows setting a percentage markup to apply to current HUSH price to help with any market volatility. Enter as decimal (IE: 2% markup enter as 0.02)', 'hush-wc-gateway' ), + 'default' => __( '0.02', 'hush-wc-gateway' ), + 'desc_tip' => true, + ), + + ) ); + } + + + /** + * Output for the order received page. + */ + public function thankyou_page( $order_id ) { + + // Get Hush price at time of order + $hushPrice = get_post_meta($order_id, '_hush_price', true); + + // Get address to send to + $hushAddress = get_post_meta($order_id, '_hush_receive_address', true); + + // Get expected amount to be received + $hushAmt = get_post_meta($order_id, '_hush_expected', true); + + // Generate HUSH URI + $hushURI = "hush:".$hushAddress."?amt=".$hushAmt; + + // Display instructions for customer to send payment to + $htmlOutput .= "

HUSH Payment Instructions

"; + $htmlOutput .= $this->checkoutInstructions."

"; + $htmlOutput .= "Address to send HUSH to:

"; + $htmlOutput .= "Amount to send: (Exchange Rate is ".$hushPrice." USD + ". $this->volatilityMarkup * 100 ."% volatility markup)


"; + $htmlOutput .= "Memo is not required, but you may include with any message, notes, or special instructions


"; + $htmlOutput .= "An auto-generated HUSH URI may be used instead for easier/quicker payment. In lite or full wallet, go to File > Pay HUSH URI and copy paste the URI below. Do not modify this URI. Orders will only be fulfilled if expected amount of HUSH is received.

"; + $htmlOutput .= "Pay HUSH URI:


"; + echo $htmlOutput; + + } + + + /** + * Process the payment and return the result + * This will put the order into on-hold status, reduce inventory levels, and empty customer shopping cart. + * + * @param int $order_id + * @return array + */ + public function process_payment( $order_id ) { + + $order = wc_get_order( $order_id ); + + // Mark as on-hold (we're awaiting the payment) + $order->update_status( 'on-hold', __( 'Awaiting HUSH payment', 'hush-wc-gateway' ) ); + + // Reduce stock levels + wc_reduce_stock_levels($order_id); + + // Remove cart + WC()->cart->empty_cart(); + + // Return thankyou redirect + return array( + 'result' => 'success', + 'redirect' => $this->get_return_url( $order ) + ); + } + + } // end \Hush_WC_Gateway class +} diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..84b893d --- /dev/null +++ b/readme.txt @@ -0,0 +1,93 @@ +=== Hush Woocommerce Gateway === +Contributors: Hush Develeopers +Donate link: https://hush.is +Tags: cryptocurrency, crypto, checkout, woocommerce, e-commerce, ecommerce, store, payments, gateway, paypal, cryptocurrency checkout, hush, zk-snarks, equihash, silentdragon, silentdragonlite +Requires at least: 4.7 +Tested up to: 5.9.3 +Stable tag: 1.0.0 +Requires PHP: 5.2 +License: GPLv3 +License URI: https://www.gnu.org/licenses/gpl-3.0.html + +This plugin provides a simple way to allow WooCommerce customers to pay with HUSH + + + +== Description == + += Minimum Requirements = +* PHP 5.2 or greater is recommended +* WordPress 4.7 or greater is recommended +* WooCommerce 2.1 or greater is recommended + + += What This Plugin Does: = +This plugin allows your WooCommerce Store to accept payments in HUSH. It provides simple instructions to the customer for sending payment and does not require running a node 24/7. All orders are manually approved after verifying payment is received. It is expected that store owners using this plugin already have or know how to run their own Hush wallet to generate addresses to configure the plugin and receive payments. + + += No Middleman or Third Party Risk: = +The Hush WooCommerce Gateway allows customers to pay directly from their personal wallet to your stores personal wallet by following simple instructions. The customer and store owner are in full control and there are no third-parties involved, provided both the customer and store owner are running their own wallets, in control of their private keys, and not using a third-party exchange or custodial wallet service. We recommend storing your HUSH in SilentDragon or SilentDragonLite. + + += How does it work?: = +When an order is submitted via the HUSH payment method, the order will be placed in "on-hold" status inside your WooCommerce Store's Dashboard, no different than a cheque or cash payment method. During the checkout process, the customer will receive instructions for payment on the order confirmation/thank you page. This will include a random z-address chosen from your list of addresses configured in the plugin settings and the amount based on current exchange conversion rate from CoinGecko, with any added volatility mark-up applied. A copy/paste HUSH Pay URI will also be generated. After the Customer sends payment, the store owner will verify that the coins have arrived in their wallet and mark the order as Processing/Completed in their WooCommerce Dashboard. + + += Why use HUSH? = + +* Extreme Privacy with enforced z-z transactions using zero knowledge mathematics! +* HUSH currently has the largest anonymity set of any cryptocurrency, making it one of the most private in the world. +* The plugin allows stores to use any wallet of their choosing, including SilentDragon and SilentDragonLite + + +== Installation == + += Minimum Requirements = +* PHP 5.2 or greater is recommended +* WordPress 4.7 or greater is recommended +* WooCommerce 2.1 or greater is recommended + +Visit hush.is/privacy for more details on HUSH + + += Manual installation = + +In some cases you may have to manually install the plugin, to do so is fairly simple. + +* FTP into your webserver + + +* Go into the public_html/your_wordpress_folder/wp-content/plugins folder. + + +* Upload the hush-wooCommerce-gateway.zip file. + + +* Extract the zip file contents into the plugins folder. The extracted files should be located at: public_html/your_wordpress_folder/wp-content/plugins/hush-woocommerce-gateway + + +* In your Wordpress Admin Dashboard, go to "Plugins" Section, and Click "Installed Plugins", Activate the Hush WooCommerce Gateway. + + +* Go to the WooCommerce Section, click Settings, Press the "Payments" Tab at the top, Enable Hush, and press Manage. + + +* Configure the plugin with a list of your HUSH addresses you would like to receive payments at, change any messaging you desire to customize, and set volatility markup. + + + +== Screenshots == + +1. WooCommerce Checkout Page Example. + +2. WooCommerce Thank You Page Example. + +3. Hush Woocommerce Gateway settings. + + + +== Changelog == + += 1.0 = + +* Initial release. hush.is/privacy - Speak And Transact Freely. \ No newline at end of file