diff --git a/blockonomics-woocommerce.php b/blockonomics-woocommerce.php
index 6ff4cd8a..c83e0118 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
@@ -351,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__) );
@@ -400,6 +402,54 @@ 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__);
+ $post_content = '
';
+ $post_content .= '
';
+ $post_content .= '
';
+ $checkout_page = array(
+ 'post_title' => wp_strip_all_tags( 'Show' ),
+ '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_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..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;
});
@@ -57,9 +57,13 @@ 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([
+ // Allow same origin resource loads.
+ 'self'
+ ]);
});
function getParameterByNameBlocko(name, url) {
@@ -77,11 +81,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() {
@@ -93,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;
@@ -115,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;
@@ -136,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;
@@ -237,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
old mode 100644
new mode 100755
index 9bf2b390..ccc1f57f
--- a/php/WC_Gateway_Blockonomics.php
+++ b/php/WC_Gateway_Blockonomics.php
@@ -154,15 +154,18 @@ 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();
+ $amount = isset($_REQUEST["amount"]) ? $_REQUEST["amount"] : "";
+ $post = get_page_by_path( 'track', OBJECT, 'bitcoin_orders' );
+ 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"] : "";
if ($address) {
diff --git a/templates/order.htm b/templates/order.htm
new file mode 100755
index 00000000..e5bfbca6
--- /dev/null
+++ b/templates/order.htm
@@ -0,0 +1,98 @@
+
+
+
+
+
+ Pay with
+
+ BTC Altcoins
+
+
+
+ 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.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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
+
+
+
+
+
+ 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
+
+
+
+
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