From 7d8b5b1b400102a27d28ff220f2ec3e1c0ae3c4b Mon Sep 17 00:00:00 2001 From: KhutsoC Date: Fri, 5 Apr 2019 02:09:24 +0200 Subject: [PATCH 1/7] Add basic custom post type functionality --- blockonomics-woocommerce.php | 49 +++++++++++++++ css/order.css | 1 - js/app.js | 9 ++- php/WC_Gateway_Blockonomics.php | 14 ++--- templates/order.htm | 102 ++++++++++++++++++++++++++++++++ 5 files changed, 163 insertions(+), 12 deletions(-) mode change 100644 => 100755 php/WC_Gateway_Blockonomics.php create mode 100755 templates/order.htm diff --git a/blockonomics-woocommerce.php b/blockonomics-woocommerce.php index 6ff4cd8a..bce97316 100755 --- a/blockonomics-woocommerce.php +++ b/blockonomics-woocommerce.php @@ -60,6 +60,8 @@ function blockonomics_woocommerce_init() add_action('woocommerce_email_customer_details', 'nolo_bnomics_woocommerce_email_customer_details', 10, 1); add_filter('woocommerce_payment_gateways', 'woocommerce_add_blockonomics_gateway'); add_action('wp_enqueue_scripts', 'bnomics_enqueue_stylesheets' ); + add_action('wp_enqueue_scripts', 'bnomics_enqueue_scripts' ); + add_action( 'init', 'bnomics_register_bitcoin_order_post_type' ); /** * Add this Gateway to WooCommerce @@ -400,6 +402,53 @@ function bnomics_email_woocommerce_style($email, $subject, $heading, $message) { // Send the email using woocommerce mailer send $mailer->send( $email, $subject, $html_message, array('Content-Type: text/html; charset=UTF-8') ); } + + // Create custom post type page from order details + function bnomics_register_bitcoin_order_post_type($order) { + $labels = array( + 'name' => _x( 'Bitcoin Orders', 'post type general name' ), + 'singular_name' => _x( 'Bitcoin Order', 'post type singular name' ), + ); + $args = array( + 'labels' => $labels, + 'description' => 'Blockonomics order pages', + 'public' => true, + ); + register_post_type( 'bitcoin_orders', $args ); + $show_page = get_page_by_title( 'Show', OBJECT, 'bitcoin_orders' ); + $track_page = get_page_by_title( 'Track', OBJECT, 'bitcoin_orders' ); + if ( ! $show_page || ! $track_page ) { + bnomics_create_pages(); + flush_rewrite_rules(); + } + } + + function bnomics_create_pages() { + $template_url = plugins_url('templates/order.htm', __FILE__); + $checkout_page = array( + 'post_title' => wp_strip_all_tags( 'Show' ), + 'post_content' => '
+
+
+
', + 'post_status' => 'publish', + 'post_author' => 1, + 'post_type' => 'bitcoin_orders', + ); + wp_insert_post( $checkout_page ); + + $altcoin_page = array( + 'post_title' => wp_strip_all_tags( 'Track' ), + 'post_content' => '
+
+
+
', + 'post_status' => 'publish', + 'post_author' => 1, + 'post_type' => 'bitcoin_orders', + ); + wp_insert_post( $altcoin_page ); + } } // After all plugins have been loaded, initialize our payment gateway plugin diff --git a/css/order.css b/css/order.css index c2aadf22..22dab264 100755 --- a/css/order.css +++ b/css/order.css @@ -9,7 +9,6 @@ } .bnomics-order-container { - margin: 12vh auto; padding: 10px; max-width: 700px; } diff --git a/js/app.js b/js/app.js index fe0ff68a..42d9e03b 100755 --- a/js/app.js +++ b/js/app.js @@ -57,9 +57,12 @@ service.factory('WpAjax', function($resource) { app = angular.module("shopping-cart-demo", ["monospaced.qrcode", "shoppingcart.services"]); -app.config(function($compileProvider) { +app.config(function($compileProvider,$sceDelegateProvider) { $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|data|chrome-extension|bitcoin|ethereum|litecoin):/); // Angular before v1.2 uses $compileProvider.urlSanitizationWhitelist(...) + $sceDelegateProvider.resourceUrlWhitelist([ + 'http://localhost/**' + ]); }); function getParameterByNameBlocko(name, url) { @@ -77,11 +80,11 @@ function getParameterByNameBlocko(name, url) { //CheckoutController app.controller('CheckoutController', function($scope, $interval, Order, $httpParamSerializer, $timeout) { //get order id from url - $scope.address = getParameterByNameBlocko("show_order"); + $scope.address = getParameterByNameBlocko("order"); var totalProgress = 100; $scope.copyshow = false; //blockonomics_time_period is defined on JS file as global var - var totalTime = blockonomics_time_period * 60; + var totalTime = 10 * 60; //Create url when the order is received $scope.finish_order_url = function() { diff --git a/php/WC_Gateway_Blockonomics.php b/php/WC_Gateway_Blockonomics.php old mode 100644 new mode 100755 index 9bf2b390..918275d3 --- a/php/WC_Gateway_Blockonomics.php +++ b/php/WC_Gateway_Blockonomics.php @@ -154,15 +154,13 @@ public function check_blockonomics_callback() $address = isset($_REQUEST["show_order"]) ? $_REQUEST["show_order"] : ""; $uuid = isset($_REQUEST["uuid"]) ? $_REQUEST["uuid"] : ""; if ($address) { - $dir = plugin_dir_path(__FILE__); - add_action('wp_enqueue_scripts', 'bnomics_enqueue_scripts' ); - include $dir."../templates/order.php"; - exit(); + $post = get_page_by_path( 'show', OBJECT, 'bitcoin_orders' ); + wp_redirect( get_post_permalink($post->ID). "?order=".$address ); + exit; }else if ($uuid){ - $dir = plugin_dir_path(__FILE__); - add_action('wp_enqueue_scripts', 'bnomics_enqueue_scripts' ); - include $dir."../templates/track.php"; - exit(); + $post = get_page_by_path( 'track', OBJECT, 'bitcoin_orders' ); + wp_redirect( get_post_permalink($post->ID). "?uuid=".$uuid ); + exit; } $address = isset($_REQUEST["finish_order"]) ? $_REQUEST["finish_order"] : ""; if ($address) { diff --git a/templates/order.htm b/templates/order.htm new file mode 100755 index 00000000..3aff02ca --- /dev/null +++ b/templates/order.htm @@ -0,0 +1,102 @@ +
+
+
+ +
+
+
+ Pay with + + BTCAltcoins + +

+
+ Order #{{order.order_id}} +
+
+
+ +
+
+ +
+
+ +
+ +
Click on the QR code to open in the wallet
+
+ +
+
+ +
+ To confirm your order, please send the exact amount of BTC to the given address + Payment Expired (Use the browser back button and try again) + Payment Error +
+

+ {{order.satoshi/1.0e8}} BTC +

+
+
≈ + {{order.value}} + {{order.currency}} +
+ +
+ + file_copy +
+
Copied to clipboard
+ +
+
+
+
+
+ {{clock*1000 | date:'mm:ss' : 'UTC'}} min left to pay your order +
+ +
+ Powered by Blockonomics +
+
+
+
+ +
+
+
+
+ Select your preferred Altcoin then click on the button below. +
+
+ +
+ +
+ +
+
+
+ +
+
+
+ + +
+
\ No newline at end of file From 1d9d383a9516b49fc214db029d0c972e668e2fc4 Mon Sep 17 00:00:00 2001 From: KhutsoC Date: Wed, 10 Apr 2019 12:07:19 +0200 Subject: [PATCH 2/7] Add enigma-laptop to whitelist --- js/app.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/js/app.js b/js/app.js index 42d9e03b..8b948673 100755 --- a/js/app.js +++ b/js/app.js @@ -61,7 +61,11 @@ app.config(function($compileProvider,$sceDelegateProvider) { $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|data|chrome-extension|bitcoin|ethereum|litecoin):/); // Angular before v1.2 uses $compileProvider.urlSanitizationWhitelist(...) $sceDelegateProvider.resourceUrlWhitelist([ - 'http://localhost/**' + // Allow same origin resource loads. + 'self', + // Allow localhost resource loads. + 'http://localhost/**', + 'http://enigma-laptop.local/**' ]); }); From f9a87f2635cb226a99863b6df22bda38e96b13d3 Mon Sep 17 00:00:00 2001 From: DarrenWestwood Date: Fri, 3 May 2019 12:16:55 +0200 Subject: [PATCH 3/7] Use relative path to include order template --- blockonomics-woocommerce.php | 2 +- js/app.js | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/blockonomics-woocommerce.php b/blockonomics-woocommerce.php index bce97316..588c1bb7 100755 --- a/blockonomics-woocommerce.php +++ b/blockonomics-woocommerce.php @@ -429,7 +429,7 @@ function bnomics_create_pages() { 'post_title' => wp_strip_all_tags( 'Show' ), 'post_content' => '
-
+
', 'post_status' => 'publish', 'post_author' => 1, diff --git a/js/app.js b/js/app.js index 8b948673..3bbdab5d 100755 --- a/js/app.js +++ b/js/app.js @@ -62,10 +62,7 @@ app.config(function($compileProvider,$sceDelegateProvider) { // Angular before v1.2 uses $compileProvider.urlSanitizationWhitelist(...) $sceDelegateProvider.resourceUrlWhitelist([ // Allow same origin resource loads. - 'self', - // Allow localhost resource loads. - 'http://localhost/**', - 'http://enigma-laptop.local/**' + 'self' ]); }); From 007e07caecc5efa13a0c49fad468cffb20022b3a Mon Sep 17 00:00:00 2001 From: DarrenWestwood Date: Fri, 3 May 2019 13:24:05 +0200 Subject: [PATCH 4/7] Fix order.htm --- templates/order.htm | 174 ++++++++++++++++++++++---------------------- 1 file changed, 85 insertions(+), 89 deletions(-) diff --git a/templates/order.htm b/templates/order.htm index 3aff02ca..213632c8 100755 --- a/templates/order.htm +++ b/templates/order.htm @@ -1,102 +1,98 @@ -
-
-
- -
-
-
- Pay with - - BTCAltcoins - -

-
- Order #{{order.order_id}} -
-
+
+ +
+
+
+ Pay with + + BTCAltcoins + +

+
+ Order #{{order.order_id}}
- -
-
+
+
+ +
+
-
-
- -
- -
Click on the QR code to open in the wallet
-
- -
-
- -
- To confirm your order, please send the exact amount of BTC to the given address - Payment Expired (Use the browser back button and try again) - Payment Error -
-

- {{order.satoshi/1.0e8}} BTC -

-
-
≈ - {{order.value}} - {{order.currency}} -
- -
- - file_copy -
-
Copied to clipboard
- -
-
-
-
+
+
+ +
+ +
Click on the QR code to open in the wallet
+
+ +
+
+ +
+ To confirm your order, please send the exact amount of BTC to the given address + Payment Expired (Use the browser back button and try again) + Payment Error +
+

+ {{order.satoshi/1.0e8}} BTC +

+
+
≈ + {{order.value}} + {{order.currency}}
- {{clock*1000 | date:'mm:ss' : 'UTC'}} min left to pay your order -
- -
- Powered by Blockonomics + +
+ + file_copy
+
Copied to clipboard
+ +
+
+
+ {{clock*1000 | date:'mm:ss' : 'UTC'}} min left to pay your order
- -
-
-
-
- Select your preferred Altcoin then click on the button below. -
-
- -
- -
- -
-
+ +
+ Powered by Blockonomics +
+
+
+
+
+
+
+ Select your preferred Altcoin then click on the button below. +
+
+ +
+ +
+ +
+
- -
-
\ No newline at end of file +
+ + From 32bde37fd547d5b09dd16962de318a7fe929b334 Mon Sep 17 00:00:00 2001 From: DarrenWestwood Date: Fri, 3 May 2019 23:14:25 +0200 Subject: [PATCH 5/7] Update cpt post content format --- blockonomics-woocommerce.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/blockonomics-woocommerce.php b/blockonomics-woocommerce.php index 588c1bb7..086994e5 100755 --- a/blockonomics-woocommerce.php +++ b/blockonomics-woocommerce.php @@ -425,24 +425,25 @@ function bnomics_register_bitcoin_order_post_type($order) { function bnomics_create_pages() { $template_url = plugins_url('templates/order.htm', __FILE__); + $post_content = '
'; + $post_content .= '
'; + $post_content .= '
'; $checkout_page = array( 'post_title' => wp_strip_all_tags( 'Show' ), - 'post_content' => '
-
-
-
', + 'post_content' => $post_content, 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'bitcoin_orders', ); wp_insert_post( $checkout_page ); + $template_url = plugins_url('templates/track.htm', __FILE__); + $post_content = '
'; + $post_content .= '
'; + $post_content .= '
'; $altcoin_page = array( 'post_title' => wp_strip_all_tags( 'Track' ), - 'post_content' => '
-
-
-
', + 'post_content' => $post_content, 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'bitcoin_orders', From ae494341c1eeae3829afd80d7b68d2d4ee49b800 Mon Sep 17 00:00:00 2001 From: DarrenWestwood Date: Mon, 6 May 2019 14:22:56 +0200 Subject: [PATCH 6/7] Fix altcoin integration --- blockonomics-woocommerce.php | 2 +- js/app.js | 12 +-- php/WC_Gateway_Blockonomics.php | 7 +- templates/track.htm | 134 ++++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 8 deletions(-) create mode 100755 templates/track.htm diff --git a/blockonomics-woocommerce.php b/blockonomics-woocommerce.php index 086994e5..c83e0118 100755 --- a/blockonomics-woocommerce.php +++ b/blockonomics-woocommerce.php @@ -353,7 +353,7 @@ function bnomics_enqueue_scripts(){ wp_enqueue_script( 'angular-resource', plugins_url('js/angular-resource.min.js', __FILE__) ); wp_enqueue_script( 'app', plugins_url('js/app.js', __FILE__) ); wp_localize_script( 'app', 'ajax_object', - array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); + array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'wc_url' => WC()->api_request_url('WC_Gateway_Blockonomics') ) ); wp_enqueue_script( 'angular-qrcode', plugins_url('js/angular-qrcode.js', __FILE__) ); wp_enqueue_script( 'vendors', plugins_url('js/vendors.min.js', __FILE__) ); wp_enqueue_script( 'reconnecting-websocket', plugins_url('js/reconnecting-websocket.min.js', __FILE__) ); diff --git a/js/app.js b/js/app.js index 3bbdab5d..f1c23a31 100755 --- a/js/app.js +++ b/js/app.js @@ -11,7 +11,7 @@ service.factory('Order', function($resource) { }; else param = {}; - var item = $resource(window.location.pathname, param); + var item = $resource(ajax_object.wc_url, param); return item; }); @@ -97,7 +97,7 @@ app.controller('CheckoutController', function($scope, $interval, Order, $httpPar else params = {}; params.finish_order = $scope.address; - url = window.location.pathname; + url = ajax_object.wc_url; var serializedParams = $httpParamSerializer(params); if (serializedParams.length > 0) { url += ((url.indexOf('?') === -1) ? '?' : '&') + serializedParams; @@ -119,7 +119,7 @@ app.controller('CheckoutController', function($scope, $interval, Order, $httpPar params.amount = amount; params.address = address; params.order_id = order_id; - url = window.location.pathname; + url = ajax_object.wc_url; var serializedParams = $httpParamSerializer(params); if (serializedParams.length > 0) { url += ((url.indexOf('?') === -1) ? '?' : '&') + serializedParams; @@ -140,13 +140,13 @@ app.controller('CheckoutController', function($scope, $interval, Order, $httpPar }; //Pay with altcoin button clicked - $scope.pay_altcoins = function() { + $scope.pay_altcoins = function(data) { $interval.cancel($scope.alt_tick_interval); $scope.order.altaddress = ''; $scope.order.altamount = ''; $scope.altcoin_waiting = true; $scope.alt_clock = 600; - var altcoin = getAltKeyByValue($scope.altcoins, $scope.altcoinselect); + var altcoin = getAltKeyByValue($scope.altcoins, data); $scope.order.altsymbol = getAltKeyByValue($scope.altcoins, $scope.altcoinselect); var amount = $scope.order.satoshi / 1.0e8; var address = $scope.order.address; @@ -241,7 +241,7 @@ app.controller('AltcoinController', function($scope, $interval, Order, AltcoinNe else params = {}; params.uuid = uuid; - url = window.location.pathname; + url = ajax_object.wc_url; var serializedParams = $httpParamSerializer(params); if (serializedParams.length > 0) { url += ((url.indexOf('?') === -1) ? '?' : '&') + serializedParams; diff --git a/php/WC_Gateway_Blockonomics.php b/php/WC_Gateway_Blockonomics.php index 918275d3..ccc1f57f 100755 --- a/php/WC_Gateway_Blockonomics.php +++ b/php/WC_Gateway_Blockonomics.php @@ -158,8 +158,13 @@ public function check_blockonomics_callback() wp_redirect( get_post_permalink($post->ID). "?order=".$address ); exit; }else if ($uuid){ + $amount = isset($_REQUEST["amount"]) ? $_REQUEST["amount"] : ""; $post = get_page_by_path( 'track', OBJECT, 'bitcoin_orders' ); - wp_redirect( get_post_permalink($post->ID). "?uuid=".$uuid ); + if ($amount){ + wp_redirect( get_post_permalink($post->ID). "?uuid=".$uuid. "&amount=".$amount. "&altcoin=".$_REQUEST["altcoin"]. "&address=".$_REQUEST["address"]. "&order_id=".$_REQUEST["order_id"] ); + }else{ + wp_redirect( get_post_permalink($post->ID). "?uuid=".$uuid ); + } exit; } $address = isset($_REQUEST["finish_order"]) ? $_REQUEST["finish_order"] : ""; diff --git a/templates/track.htm b/templates/track.htm new file mode 100755 index 00000000..655443d1 --- /dev/null +++ b/templates/track.htm @@ -0,0 +1,134 @@ +
+ +
+
+
+ Order # {{order.order_id}} +
+
+
+ +
+ +
+
+
+
+
+ +
+
+ +
+ +
+ Click on the QR code to open in the wallet +
+
+
+
+
+ +
+ + To confirm your order, please send the exact amount of {{altcoinselect}} to the given address + +
+

+ {{order.altamount}} {{order.altsymbol}} +

+ +
+ + file_copy +
+
+ Copied to clipboard +
+ +
+
+
+
+
+
+ {{alt_clock*1000 | date:'mm:ss' : 'UTC'}} min left to pay your order + +
+
+ Click here to go back +
+ +
+ Powered by Blockonomics +
+
+
+ +
+

Received

+

check_circle

+ Your payment has been received and your order will be processed shortly. +
+ +
+

Refund Required

+

Your order couldn\'t be processed as you didn\'t pay the exact expected amount.
The amount you paid will be refunded.

+

error

+

Enter your refund address and click the button below to recieve your refund.

+ +
+ +
+ +
+

Refund Submitted

+

Your refund details have been submitted. You should recieve your refund shortly.

+

autorenew

+

If you don\'t get refunded in a few hours, contact hello@flyp.me with the following uuid:
{{altuuid}}

+
+ +
+

Refunded

+

autorenew

+

This payment has been refunded.

+
+ Refund Details: +
Transaction ID:
+
{{order.alttxid}}
+
Transaction URL:
+ +
+
+ +
+

Expired

+

timer

+

Payment Expired. Use the browser back button and try again.

+
+ +
+

Error

+

error

+

Order amount too {{lowhigh}} for {{order.altsymbol}} payment.

+

Click here to go back and use BTC to complete the payment.

+
+
+ +
Powered by Blockonomics
+
+
+
+
+ + \ No newline at end of file From 8c4814f68aceaed97de8607fd4c981e991bac4ec Mon Sep 17 00:00:00 2001 From: DarrenWestwood Date: Mon, 6 May 2019 14:34:46 +0200 Subject: [PATCH 7/7] Fix selected altcoin --- templates/order.htm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/order.htm b/templates/order.htm index 213632c8..e5bfbca6 100755 --- a/templates/order.htm +++ b/templates/order.htm @@ -81,7 +81,7 @@