Removing Mijireh from core 2.3

This commit is contained in:
Mike Jolley 2014-11-18 16:37:43 +00:00
parent 003094c9c3
commit b3782fa1a5
22 changed files with 1 additions and 1646 deletions

View File

@ -5,7 +5,6 @@ filter:
- includes/api/v1/*
- includes/libraries/*
- includes/updates/*
- includes/gateways/mijireh/includes/*
- includes/gateways/simplify-commerce/includes/*
checks:

View File

@ -210,7 +210,7 @@ module.exports = function( grunt ) {
apigen: {
command: [
'cd apigen/',
'php apigen.php --source ../ --destination ../wc-apidocs --download yes --template-config ./templates/woodocs/config.neon --title "WooCommerce" --exclude "*/mijireh/*" --exclude "*/includes/libraries/*" --exclude "*/api/*" --exclude "*/i18n/*" --exclude "*/node_modules/*" --exclude "*/apigen/*" --exclude "*/wc-apidocs/*"'
'php apigen.php --source ../ --destination ../wc-apidocs --download yes --template-config ./templates/woodocs/config.neon --title "WooCommerce" --exclude "*/includes/libraries/*" --exclude "*/api/*" --exclude "*/i18n/*" --exclude "*/node_modules/*" --exclude "*/apigen/*" --exclude "*/wc-apidocs/*"'
].join( '&&' )
}
},

View File

@ -28,7 +28,6 @@ class WC_Admin_Meta_Boxes {
add_action( 'add_meta_boxes', array( $this, 'remove_meta_boxes' ), 10 );
add_action( 'add_meta_boxes', array( $this, 'rename_meta_boxes' ), 20 );
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 30 );
add_action( 'add_meta_boxes', array( 'WC_Gateway_Mijireh', 'add_page_slurp_meta' ) );
add_action( 'save_post', array( $this, 'save_meta_boxes' ), 1, 2 );
/**

View File

@ -74,10 +74,6 @@ class WC_Admin_Notices {
wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ) );
add_action( 'admin_notices', array( $this, 'translation_upgrade_notice' ) );
}
if ( ! class_exists( 'WC_Mijireh_Checkout' ) && ( $mijireh = get_option( 'woocommerce_mijireh_checkout_settings', false ) ) && ! empty( $mijireh['enabled'] ) && $mijireh['enabled'] === 'yes' && empty( $_GET['action'] ) ) {
add_action( 'admin_notices', array( $this, 'mijireh_notice' ) );
}
}
/**
@ -151,13 +147,6 @@ class WC_Admin_Notices {
include( 'views/html-notice-template-check.php' );
}
}
/**
* Notice to say Mijireh has been deprecated in 2.2
*/
public function mijireh_notice() {
include( 'views/html-notice-mijireh.php' );
}
}
endif;

View File

@ -1,23 +0,0 @@
<?php
/**
* Admin View: Notice - Mijireh
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
$plugin_slug = 'woocommerce-mijireh-checkout';
if ( current_user_can( 'install_plugins' ) ) {
$url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $plugin_slug ), 'install-plugin_' . $plugin_slug );
} else {
$url = 'http://wordpress.org/plugins/' . $plugin_slug;
}
?>
<div id="message" class="updated woocommerce-message wc-connect">
<p><?php _e( '<strong>The Mijireh payment gateway is deprecated</strong> &#8211; It is recommended that you install the replacement Mijireh plugin from WordPress.org as soon as possible. Mijireh will be removed from WC core completely as part of a future update.', 'woocommerce' ); ?></p>
<p class="submit"><a href="<?php echo esc_url( $url ); ?>" class="wc-update-now button-primary"><?php _e( 'Install the new Mijireh plugin', 'woocommerce' ); ?></a></p>
</div>

View File

@ -74,8 +74,6 @@ class WC_AJAX {
add_action( 'wp_ajax_nopriv_woocommerce_' . $ajax_event, array( __CLASS__, $ajax_event ) );
}
}
add_action( 'wp_ajax_page_slurp', array( 'WC_Gateway_Mijireh', 'page_slurp' ) );
}
/**

View File

@ -79,11 +79,6 @@ class WC_Payment_Gateways {
'WC_Gateway_Paypal',
);
// Conditional loading of core gateways
if ( ! class_exists( 'WC_Mijireh_Checkout' ) && ( $mijireh = get_option( 'woocommerce_mijireh_checkout_settings', false ) ) && ! empty( $mijireh['enabled'] ) && $mijireh['enabled'] === 'yes' ) {
$load_gateways[] = 'WC_Gateway_Mijireh';
}
if ( 'US' === WC()->countries->get_base_country() ) {
if ( class_exists( 'WC_Subscriptions_Order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) {
$load_gateways[] = 'WC_Addons_Gateway_Simplify_Commerce';

View File

@ -1,155 +0,0 @@
#mijireh_notice {
background: #5bc0de url(../images/mijireh-logo.png) no-repeat 15px 18px;
border: 1px solid #339bb9;
padding: 15px 15px 15px 152px !important;
box-shadow: inset 1px 1px 0 rgba( 255, 255, 255, 0.5 ), inset -1px -1px 0 rgba( 255, 255, 255, 0.5 );
-moz-box-shadow: inset 1px 1px 0 rgba( 255, 255, 255, 0.5 ), inset -1px -1px 0 rgba( 255, 255, 255, 0.5 );
-webkit-box-shadow: inset 1px 1px 0 rgba( 255, 255, 255, 0.5 ), inset -1px -1px 0 rgba( 255, 255, 255, 0.5 );
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
color: #fff;
text-shadow: 0 1px 0 #4a94ac;
}
#mijireh_notice.alert-danger, #mijireh_notice.alert-error {
background-color: #e0534e;
border: 1px solid #e0534e;
text-shadow: 0 1px 0 #e0534e;
}
#mijireh_notice.success {
background-color: #62c462;
border: 1px solid #62c462;
text-shadow: 0 1px 0 #4fbd4f;
}
#slurp_meta_box .inside {
padding:0 !important;
margin:0 !important;
}
#slurp_meta_box .alert-message {
margin:0 !important;
}
#slurp_meta_box h2 {
color:#fff;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
margin: 0;
}
#slurp_meta_box a {
color: #fff;
}
#slurp_meta_box a.button-primary {
margin-right: 10px;
}
#slurp_meta_box p {
line-height: 22px;
margin-bottom: 1em;
margin-top: 0;
}
/* Progress Bar Styles */
.progress {
overflow: hidden;
line-height:18px!important;
height: 18px!important;
margin-bottom: 18px!important;
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #f5f5f5), color-stop(100%, #f9f9f9));
background: -webkit-linear-gradient(#f5f5f5, #f9f9f9);
background: -moz-linear-gradient(#f5f5f5, #f9f9f9);
background: -o-linear-gradient(#f5f5f5, #f9f9f9);
background: -ms-linear-gradient(#f5f5f5, #f9f9f9);
background: linear-gradient(#f5f5f5, #f9f9f9);
-webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
-moz-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
-ms-border-radius: 4px;
-o-border-radius: 4px;
border-radius: 4px;
}
.progress .bar {
width: 0%;
height: 18px!important;
line-height: 18px!important;
color: white;
font-size: 12px;
text-align: center;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #149bdf), color-stop(100%, #0480be));
background: -webkit-linear-gradient(#149bdf, #0480be);
background: -moz-linear-gradient(#149bdf, #0480be);
background: -o-linear-gradient(#149bdf, #0480be);
background: -ms-linear-gradient(#149bdf, #0480be);
background: linear-gradient(#149bdf, #0480be);
-webkit-box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15), inset 0 1px 2px rgba(0, 0, 0, 0.4);
-moz-box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15), inset 0 1px 2px rgba(0, 0, 0, 0.4);
box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15), inset 0 1px 2px rgba(0, 0, 0, 0.4);
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
-webkit-transition: width 0.6s ease;
-moz-transition: width 0.6s ease;
transition: width 0.6s ease;
}
.progress-striped .bar {
background-color: #62c462;
background-image: -webkit-gradient(linear, 0 100%, 100% 0, color-stop(0.25, rgba(255, 255, 255, 0.15)), color-stop(0.25, transparent), color-stop(0.5, transparent), color-stop(0.5, rgba(255, 255, 255, 0.15)), color-stop(0.75, rgba(255, 255, 255, 0.15)), color-stop(0.75, transparent), to(transparent));
background-image: -webkit-linear-gradient(-45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
background-image: -moz-linear-gradient(-45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
background-image: -ms-linear-gradient(-45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
background-image: -o-linear-gradient(-45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
-webkit-background-size: 40px 40px;
-moz-background-size: 40px 40px;
-o-background-size: 40px 40px;
background-size: 40px 40px;
}
.progress.active .bar {
-webkit-animation: progress-bar-stripes 2s linear infinite;
-moz-animation: progress-bar-stripes 2s linear infinite;
animation: progress-bar-stripes 2s linear infinite;
}
.progress-danger .bar {
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #ee5f5b), color-stop(100%, #c43c35));
background: -webkit-linear-gradient(#ee5f5b, #c43c35);
background: -moz-linear-gradient(#ee5f5b, #c43c35);
background: -o-linear-gradient(#ee5f5b, #c43c35);
background: -ms-linear-gradient(#ee5f5b, #c43c35);
background: linear-gradient(#ee5f5b, #c43c35);
}
.progress-danger.progress-striped .bar {
background-color: #ee5f5b;
background-image: -webkit-gradient(linear, 0 100%, 100% 0, color-stop(0.25, rgba(255, 255, 255, 0.15)), color-stop(0.25, transparent), color-stop(0.5, transparent), color-stop(0.5, rgba(255, 255, 255, 0.15)), color-stop(0.75, rgba(255, 255, 255, 0.15)), color-stop(0.75, transparent), to(transparent));
background-image: -webkit-linear-gradient(-45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
background-image: -moz-linear-gradient(-45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
background-image: -ms-linear-gradient(-45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
background-image: -o-linear-gradient(-45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
}
.progress-success .bar {
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #62c462), color-stop(100%, #57a957));
background: -webkit-linear-gradient(#62c462, #57a957);
background: -moz-linear-gradient(#62c462, #57a957);
background: -o-linear-gradient(#62c462, #57a957);
background: -ms-linear-gradient(#62c462, #57a957);
background: linear-gradient(#62c462, #57a957);
}
.progress-success.progress-striped .bar {
background-color: #62c462;
background-image: -webkit-gradient(linear, 0 100%, 100% 0, color-stop(0.25, rgba(255, 255, 255, 0.15)), color-stop(0.25, transparent), color-stop(0.5, transparent), color-stop(0.5, rgba(255, 255, 255, 0.15)), color-stop(0.75, rgba(255, 255, 255, 0.15)), color-stop(0.75, transparent), to(transparent));
background-image: -webkit-linear-gradient(-45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
background-image: -moz-linear-gradient(-45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
background-image: -ms-linear-gradient(-45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
background-image: -o-linear-gradient(-45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
}
.progress.info .bar {
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #5bc0de), color-stop(100%, #339bb9));
background: -webkit-linear-gradient(#5bc0de, #339bb9);
background: -moz-linear-gradient(#5bc0de, #339bb9);
background: -o-linear-gradient(#5bc0de, #339bb9);
background: -ms-linear-gradient(#5bc0de, #339bb9);
background: linear-gradient(#5bc0de, #339bb9);
}
.progress-info.progress-striped .bar {
background-color: #5bc0de;
background-image: -webkit-gradient(linear, 0 100%, 100% 0, color-stop(0.25, rgba(255, 255, 255, 0.15)), color-stop(0.25, transparent), color-stop(0.5, transparent), color-stop(0.5, rgba(255, 255, 255, 0.15)), color-stop(0.75, rgba(255, 255, 255, 0.15)), color-stop(0.75, transparent), to(transparent));
background-image: -webkit-linear-gradient(-45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
background-image: -moz-linear-gradient(-45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
background-image: -ms-linear-gradient(-45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
background-image: -o-linear-gradient(-45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -1,51 +0,0 @@
(function($) {
$('#page_slurp').click(function() {
var page_id = $(this).attr('rel');
var data = {
action: 'page_slurp',
page_id: page_id
};
$('#page_slurp').attr('disabled', 'disabled');
$('#slurp_progress').show();
$('#slurp_progress_bar').html('Starting up');
$.post(ajaxurl, data, function(job_id) {
// The job id is the id for the page slurp job or 0 if the slurp failed
if(job_id.substring(0, 4) === 'http') {
var msg = 'Your PHP configuration does not allow for Page Slurp from within WordPress. Please log into your Mijireh account and Slurp the page by pasting in the URL to this page as shown below.\
\n\n' + job_id + '\n\nPlease set this page to be publicly accessible during the Slurp then set it back to private after the Slurp is complete.';
alert(msg);
}
else {
pusher = new Pusher('7dcd33b15307eb9be5fb');
channel_name = 'slurp-' + job_id;
channel = pusher.subscribe(channel_name);
channel.bind('status_changed', function (data) {
// console.log(data);
if(data.level == 'info') {
$('#slurp_progress_bar').html(data.message);
$('#slurp_progress_bar').width(data.progress + '%');
}
if(data.progress == 100) {
pusher.unsubscribe(channel_name);
$('#slurp_progress').hide();
$('#page_slurp').removeAttr('disabled');
}
});
}
})
.error(function(response) {
$('#slurp_progress').hide();
$('#page_slurp').removeAttr('disabled');
alert('Please make sure your Mijireh access key is correct');
});
return false;
});
})(jQuery.noConflict());

View File

@ -1,369 +0,0 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Mijireh Checkout Gateway
*
* Provides WooCommerce with Mijireh Checkout integration.
*
* @deprecated 2.2
*
* @class WC_Gateway_Mijireh
* @extends WC_Payment_Gateway
* @version 2.0.0
* @package WooCommerce/Classes/Payment
* @author Mijireh
*/
class WC_Gateway_Mijireh extends WC_Payment_Gateway {
/** @var string Access key for mijireh */
var $access_key;
/**
* Constructor for the gateway.
*
* @access public
* @return void
*/
public function __construct() {
$this->id = 'mijireh_checkout';
$this->method_title = __( 'Mijireh Checkout', 'woocommerce' );
$this->icon = apply_filters( 'woocommerce_mijireh_checkout_icon', WC()->plugin_url() . '/includes/gateways/mijireh/assets/images/credit_cards.png' );
$this->has_fields = false;
// Load the settings.
$this->init_form_fields();
$this->init_settings();
// Define user set variables
$this->access_key = $this->get_option( 'access_key' );
$this->title = $this->get_option( 'title' );
$this->description = $this->get_option( 'description' );
if ( $this->enabled && is_admin() ) {
$this->install_slurp_page();
}
// Save options
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
// Payment listener/API hook
add_action( 'woocommerce_api_wc_gateway_mijireh', array( $this, 'mijireh_notification' ) );
}
/**
* install_slurp_page function.
*
* @access public
*/
public function install_slurp_page() {
$slurp_page_installed = get_option( 'slurp_page_installed', false );
if ( $slurp_page_installed != 1 ) {
if( ! get_page_by_path( 'mijireh-secure-checkout' ) ) {
$page = array(
'post_title' => 'Mijireh Secure Checkout',
'post_name' => 'mijireh-secure-checkout',
'post_parent' => 0,
'post_status' => 'private',
'post_type' => 'page',
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_content' => "<h1>Checkout</h1>\n\n{{mj-checkout-form}}",
);
wp_insert_post( $page );
}
update_option( 'slurp_page_installed', 1 );
}
}
/**
* mijireh_notification function.
*
* @access public
* @return void
*/
public function mijireh_notification() {
if ( isset( $_GET['order_number'] ) ) {
$this->init_mijireh();
try {
$mj_order = new Mijireh_Order( esc_attr( $_GET['order_number'] ) );
$wc_order_id = $mj_order->get_meta_value( 'wc_order_id' );
$wc_order = wc_get_order( absint( $wc_order_id ) );
// Mark order complete
$wc_order->payment_complete();
// Empty cart and clear session
WC()->cart->empty_cart();
wp_redirect( $this->get_return_url( $wc_order ) );
exit;
} catch ( Mijireh_Exception $e ) {
wc_add_notice( __( 'Mijireh error:', 'woocommerce' ) . $e->getMessage(), 'error' );
}
}
elseif ( isset( $_POST['page_id'] ) ) {
if ( isset( $_POST['access_key'] ) && $_POST['access_key'] == $this->access_key ) {
wp_update_post( array( 'ID' => $_POST['page_id'], 'post_status' => 'private' ) );
}
}
}
/**
* Initialise Gateway Settings Form Fields
*
* @access public
* @return void
*/
public function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'woocommerce' ),
'type' => 'checkbox',
'label' => __( 'Enable Mijireh Checkout', 'woocommerce' ),
'default' => 'no'
),
'access_key' => array(
'title' => __( 'Access Key', 'woocommerce' ),
'type' => 'text',
'description' => __( 'The Mijireh access key for your store.', 'woocommerce' ),
'default' => '',
'desc_tip' => true,
),
'title' => array(
'title' => __( 'Title', 'woocommerce' ),
'type' => 'text',
'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
'default' => __( 'Credit Card', 'woocommerce' ),
'desc_tip' => true,
),
'description' => array(
'title' => __( 'Description', 'woocommerce' ),
'type' => 'text',
'default' => __( 'Pay securely with your credit card.', 'woocommerce' ),
'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce' ),
'desc_tip' => true,
),
);
}
/**
* Process the payment and return the result
*
* @access public
* @param int $order_id
* @return array
*/
public function process_payment( $order_id ) {
$this->init_mijireh();
$mj_order = new Mijireh_Order();
$wc_order = wc_get_order( $order_id );
// Avoid rounding issues altogether by sending the order as one lump
if ( get_option( 'woocommerce_prices_include_tax' ) == 'yes' ) {
// Don't pass items - Pass 1 item for the order items overall
$item_names = array();
if ( sizeof( $wc_order->get_items() ) > 0 ) {
foreach ( $wc_order->get_items() as $item ) {
if ( $item['qty'] ) {
$item_names[] = $item['name'] . ' x ' . $item['qty'];
}
}
}
$mj_order->add_item( sprintf( __( 'Order #%s' , 'woocommerce'), $wc_order->get_order_number() ) . " - " . implode( ', ', $item_names ), number_format( $wc_order->get_total() - round( $wc_order->get_total_shipping() + $wc_order->get_shipping_tax(), 2 ) + $wc_order->get_order_discount(), 2, '.', '' ), 1 );
if ( ( $wc_order->get_total_shipping() + $wc_order->get_shipping_tax() ) > 0 ) {
$mj_order->shipping = number_format( $wc_order->get_total_shipping() + $wc_order->get_shipping_tax(), 2, '.', '' );
}
$mj_order->show_tax = false;
// No issues when prices exclude tax
} else {
// add items to order
$items = $wc_order->get_items();
foreach( $items as $item ) {
$product = $wc_order->get_product_from_item( $item );
$mj_order->add_item( $item['name'], $wc_order->get_item_subtotal( $item, false, true ), $item['qty'], $product->get_sku() );
}
// Handle fees
$items = $wc_order->get_fees();
foreach( $items as $item ) {
$mj_order->add_item( $item['name'], number_format( $item['line_total'], 2, '.', ',' ), 1, '' );
}
$mj_order->shipping = round( $wc_order->get_total_shipping(), 2 );
$mj_order->tax = $wc_order->get_total_tax();
}
// set order totals
$mj_order->total = $wc_order->get_total();
$mj_order->discount = $wc_order->get_total_discount();
// add billing address to order
$billing = new Mijireh_Address();
$billing->first_name = $wc_order->billing_first_name;
$billing->last_name = $wc_order->billing_last_name;
$billing->street = $wc_order->billing_address_1;
$billing->apt_suite = $wc_order->billing_address_2;
$billing->city = $wc_order->billing_city;
$billing->state_province = $wc_order->billing_state;
$billing->zip_code = $wc_order->billing_postcode;
$billing->country = $wc_order->billing_country;
$billing->company = $wc_order->billing_company;
$billing->phone = $wc_order->billing_phone;
if ( $billing->validate() ) {
$mj_order->set_billing_address( $billing );
}
// add shipping address to order
$shipping = new Mijireh_Address();
$shipping->first_name = $wc_order->shipping_first_name;
$shipping->last_name = $wc_order->shipping_last_name;
$shipping->street = $wc_order->shipping_address_1;
$shipping->apt_suite = $wc_order->shipping_address_2;
$shipping->city = $wc_order->shipping_city;
$shipping->state_province = $wc_order->shipping_state;
$shipping->zip_code = $wc_order->shipping_postcode;
$shipping->country = $wc_order->shipping_country;
$shipping->company = $wc_order->shipping_company;
if ( $shipping->validate() ) {
$mj_order->set_shipping_address( $shipping );
}
// set order name
$mj_order->first_name = $wc_order->billing_first_name;
$mj_order->last_name = $wc_order->billing_last_name;
$mj_order->email = $wc_order->billing_email;
// add meta data to identify woocommerce order
$mj_order->add_meta_data( 'wc_order_id', $order_id );
// Set URL for mijireh payment notificatoin - use WC API
$mj_order->return_url = WC()->api_request_url( 'WC_Gateway_Mijireh' );
// Identify woocommerce
$mj_order->partner_id = 'woo';
try {
$mj_order->create();
$result = array(
'result' => 'success',
'redirect' => $mj_order->checkout_url
);
return $result;
} catch ( Mijireh_Exception $e ) {
wc_add_notice( __( 'Mijireh error:', 'woocommerce' ) . $e->getMessage() . print_r( $mj_order, true ), 'error' );
}
}
/**
* init_mijireh function.
*
* @access public
*/
public function init_mijireh() {
if ( ! class_exists( 'Mijireh' ) ) {
require_once 'includes/Mijireh.php';
if ( ! isset( $this ) ) {
$settings = get_option( 'woocommerce_' . 'mijireh_checkout' . '_settings', null );
$key = ! empty( $settings['access_key'] ) ? $settings['access_key'] : '';
} else {
$key = $this->access_key;
}
Mijireh::$access_key = $key;
}
}
/**
* page_slurp function.
*
* @access public
*/
public static function page_slurp() {
self::init_mijireh();
$page = get_post( absint( $_POST['page_id'] ) );
$url = get_permalink( $page->ID );
$job_id = $url;
if ( wp_update_post( array( 'ID' => $page->ID, 'post_status' => 'publish' ) ) ) {
$job_id = Mijireh::slurp( $url, $page->ID, str_replace( 'https:', 'http:', add_query_arg( 'wc-api', 'WC_Gateway_Mijireh', home_url( '/' ) ) ) );
}
echo $job_id;
die;
}
/**
* add_page_slurp_meta function.
*
* @access public
*/
public static function add_page_slurp_meta() {
if ( self::is_slurp_page() ) {
wp_enqueue_style( 'mijireh_css', WC()->plugin_url() . '/includes/gateways/mijireh/assets/css/mijireh.css' );
wp_enqueue_script( 'pusher', 'https://d3dy5gmtp8yhk7.cloudfront.net/1.11/pusher.min.js', null, false, true );
wp_enqueue_script( 'page_slurp', WC()->plugin_url() . '/includes/gateways/mijireh/assets/js/page_slurp.js', array('jquery'), false, true );
add_meta_box(
'slurp_meta_box', // $id
'Mijireh Page Slurp', // $title
array( 'WC_Gateway_Mijireh', 'draw_page_slurp_meta_box' ), // $callback
'page', // $page
'normal', // $context
'high' // $priority
);
}
}
/**
* is_slurp_page function.
*
* @access public
* @return bool
*/
public static function is_slurp_page() {
global $post;
$is_slurp = false;
if ( isset( $post ) && is_object( $post ) ) {
$content = $post->post_content;
if ( strpos( $content, '{{mj-checkout-form}}') !== false ) {
$is_slurp = true;
}
}
return $is_slurp;
}
/**
* draw_page_slurp_meta_box function.
*
* @access public
* @param mixed $post
*/
public static function draw_page_slurp_meta_box( $post ) {
self::init_mijireh();
echo "<div id='mijireh_notice' class='mijireh-info alert-message info' data-alert='alert'>";
echo "<h2>Slurp your custom checkout page!</h2>";
echo "<p>Get the page designed just how you want and when you're ready, click the button below and slurp it right up.</p>";
echo "<div id='slurp_progress' class='meter progress progress-info progress-striped active' style='display: none;'><div id='slurp_progress_bar' class='bar' style='width: 20%;'>Slurping...</div></div>";
echo "<p><a href='#' id='page_slurp' rel=". $post->ID ." class='button-primary'>Slurp This Page!</a> ";
echo '<a class="nobold" href="' . Mijireh::preview_checkout_link() . '" id="view_slurp" target="_new">Preview Checkout Page</a></p>';
echo "</div>";
}
}

View File

@ -1,54 +0,0 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Mijireh_Address extends Mijireh_Model {
public function __construct() {
$this->init();
}
public function init() {
$this->_data = array(
'first_name' => '',
'last_name' => '',
'street' => '',
'city' => '',
'state_province' => '',
'zip_code' => '',
'country' => '',
'company' => '',
'apt_suite' => '',
'phone' => ''
);
}
/**
* Check required fields
* @return bool
*/
public function validate() {
$is_valid = $this->_check_required_fields();
return $is_valid;
}
/**
* Return true if all of the required fields have a non-empty value
*
* @return boolean
*/
private function _check_required_fields() {
$pass = true;
$fields = array('street', 'city', 'zip_code', 'country');
foreach($fields as $f) {
if(empty($this->_data[$f])) {
$pass = false;
$this->add_error("$f is required");
}
}
return $pass;
}
}

View File

@ -1,62 +0,0 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Mijireh_Item extends Mijireh_Model {
private function _init() {
$this->_data = array(
'name' => null,
'price' => null,
'quantity' => 1,
'sku' => null
);
}
private function _check_required_fields() {
if(empty($this->_data['name'])) {
$this->add_error('item name is required.');
}
if(!is_numeric($this->_data['price'])) {
$this->add_error('price must be a number.');
}
}
private function _check_quantity() {
if($this->_data['quantity'] < 1) {
$this->add_error('quantity must be greater than or equal to 1');
}
}
public function __construct() {
$this->_init();
}
public function __get($key) {
$value = false;
if($key == 'total') {
$value = $this->_data['price'] * $this->_data['quantity'];
$value = number_format($value, 2, '.', '');
}
else {
$value = parent::__get($key);
}
return $value;
}
public function get_data() {
$data = parent::get_data();
$data['total'] = $this->total;
return $data;
}
public function validate() {
$this->_check_required_fields();
$this->_check_quantity();
return count($this->_errors) == 0;
}
}

View File

@ -1,120 +0,0 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
$root_dir = dirname(__FILE__) . DIRECTORY_SEPARATOR;
// Require the mijireh library classes
require_once $root_dir . 'Rest.php';
require_once $root_dir . 'RestJSON.php';
require_once $root_dir . 'Model.php';
require_once $root_dir . 'Address.php';
require_once $root_dir . 'Item.php';
require_once $root_dir . 'Order.php';
class Mijireh_Exception extends Exception {}
class Mijireh_ClientError extends Mijireh_Exception {} /* Status: 400-499 */
class Mijireh_BadRequest extends Mijireh_ClientError {} /* Status: 400 */
class Mijireh_Unauthorized extends Mijireh_ClientError {} /* Status: 401 */
class Mijireh_NotFound extends Mijireh_ClientError {} /* Status: 404 */
class Mijireh_ServerError extends Mijireh_Exception {} /* Status: 500-599 */
class Mijireh_InternalError extends Mijireh_ServerError {} /* Status: 500 */
class Mijireh {
/* Live server urls */
public static $base_url = 'https://secure.mijireh.com/';
public static $url = 'https://secure.mijireh.com/api/1/';
public static $access_key;
/**
* Return the job id of the slurp
*/
public static function slurp($url, $page_id, $return_url) {
$url_format = '/^(https?):\/\/'. // protocol
'(([a-z0-9$_\.\+!\*\'\(\),;\?&=-]|%[0-9a-f]{2})+'. // username
'(:([a-z0-9$_\.\+!\*\'\(\),;\?&=-]|%[0-9a-f]{2})+)?'. // password
'@)?(?#'. // auth requires @
')((([a-z0-9][a-z0-9-]*[a-z0-9]\.)*'. // domain segments AND
'[a-z][a-z0-9-]*[a-z0-9]'. // top level domain OR
'|((\d|[1-9]\d|1\d{2}|2[0-4][0-9]|25[0-5])\.){3}'.
'(\d|[1-9]\d|1\d{2}|2[0-4][0-9]|25[0-5])'. // IP address
')(:\d+)?'. // port
')(((\/+([a-z0-9$_\.\+!\*\'\(\),;:@&=-]|%[0-9a-f]{2})*)*'. // path
'(\?([a-z0-9$_\.\+!\*\'\(\),;:@&=-]|%[0-9a-f]{2})*)'. // query string
'?)?)?'. // path and query string optional
'(#([a-z0-9$_\.\+!\*\'\(\),;:@&=-]|%[0-9a-f]{2})*)?'. // fragment
'$/i';
if(!preg_match($url_format, $url)) {
throw new Mijireh_NotFound('Unable to slurp invalid URL: $url');
}
try {
$rest = new Mijireh_Rest($url);
$data = array(
'url' => $url,
'page_id' => $page_id,
'return_url' => $return_url
);
$rest = new Mijireh_RestJSON(self::$url);
$rest->setupAuth(self::$access_key, '');
$result = $rest->post('slurps', $data);
return $result['job_id'];
}
catch(Mijireh_Rest_Unauthorized $e) {
throw new Mijireh_Unauthorized("Unauthorized. Please check your api access key");
}
catch(Mijireh_Rest_NotFound $e) {
throw new Mijireh_NotFound("Mijireh resource not found: " . $rest->last_request['url']);
}
catch(Mijireh_Rest_ClientError $e) {
throw new Mijireh_ClientError($e->getMessage());
}
catch(Mijireh_Rest_ServerError $e) {
throw new Mijireh_ServerError($e->getMessage());
}
catch(Mijireh_Rest_UnknownResponse $e) {
throw new Mijireh_Exception('Unable to slurp the URL: $url');
}
}
/**
* Return an array of store information
*/
public static function get_store_info() {
$rest = new Mijireh_RestJSON(self::$url);
$rest->setupAuth(self::$access_key, '');
try {
$result = $rest->get('store');
return $result;
}
catch(Mijireh_Rest_BadRequest $e) {
throw new Mijireh_BadRequest($e->getMessage());
}
catch(Mijireh_Rest_Unauthorized $e) {
throw new Mijireh_Unauthorized("Unauthorized. Please check your api access key");
}
catch(Mijireh_Rest_NotFound $e) {
throw new Mijireh_NotFound("Mijireh resource not found: " . $rest->last_request['url']);
}
catch(Mijireh_Rest_ClientError $e) {
throw new Mijireh_ClientError($e->getMessage());
}
catch(Mijireh_Rest_ServerError $e) {
throw new Mijireh_ServerError($e->getMessage());
}
}
public static function preview_checkout_link() {
if(empty(Mijireh::$access_key)) {
throw new Mijireh_Exception('Access key required to view checkout preview');
}
return self::$base_url . 'checkout/' . self::$access_key;
}
}

View File

@ -1,137 +0,0 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Mijireh_Model {
protected $_data = array();
protected $_errors = array();
/**
* Set the value of one of the keys in the private $_data array.
*
* @param string $key The key in the $_data array
* @param string $value The value to assign to the key
* @return boolean
*/
public function __set($key, $value) {
$success = false;
if(array_key_exists($key, $this->_data)) {
$this->_data[$key] = $value;
$success = true;
}
return $success;
}
/**
* Get the value for the key from the private $_data array.
*
* Return false if the requested key does not exist
*
* @param string $key The key from the $_data array
* @return mixed
*/
public function __get($key) {
$value = false;
if(array_key_exists($key, $this->_data)) {
$value = $this->_data[$key];
}
/*
elseif(method_exists($this, $key)) {
$value = call_user_func_array(array($this, $key), func_get_args());
}
*/
return $value;
}
/**
* Return true if the given $key in the private $_data array is set
*
* @param string $key
* @return boolean
*/
public function __isset($key) {
return isset($this->_data[$key]);
}
/**
* Set the value of the $_data array to null for the given key.
*
* @param string $key
* @return void
*/
public function __unset($key) {
if(array_key_exists($key, $this->_data)) {
$this->_data[$key] = null;
}
}
/**
* Return the private $_data array
*
* @return mixed
*/
public function get_data() {
return $this->_data;
}
/**
* Return true if the given $key exists in the private $_data array
*
* @param string $key
* @return boolean
*/
public function field_exists($key) {
return array_key_exists($key, $this->_data);
}
public function copy_from(array $data) {
foreach($data as $key => $value) {
if(array_key_exists($key, $this->_data)) {
$this->_data[$key] = $value;
}
}
}
public function clear() {
foreach($this->_data as $key => $value) {
if($key == 'id') {
$this->_data[$key] = null;
}
else {
$this->_data[$key] = '';
}
}
}
public function add_error($error_message) {
if(!empty($error_message)) {
$this->_errors[] = $error_message;
}
}
public function clear_errors() {
$this->_errors = array();
}
public function get_errors() {
return $this->_errors;
}
public function get_error_lines($glue="\n") {
$error_lines = '';
if(count($this->_errors)) {
$error_lines = implode($glue, $this->_errors);
}
return $error_lines;
}
public function is_valid() {
return count($this->_errors) == 0;
}
}

View File

@ -1,355 +0,0 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Mijireh_Order extends Mijireh_Model {
private function _init() {
$this->_data = array(
'partner_id' => null,
'order_number' => null,
'mode' => null,
'status' => null,
'order_date' => null,
'ip_address' => null,
'checkout_url' => null,
'total' => '',
'return_url' => '',
'items' => array(),
'email' => '',
'first_name' => '',
'last_name' => '',
'meta_data' => array(),
'tax' => '',
'shipping' => '',
'discount' => '',
'shipping_address' => array(),
'billing_address' => array(),
'show_tax' => true
);
}
public function __construct($order_number=null) {
$this->_init();
if(isset($order_number)) {
$this->load($order_number);
}
}
public function load($order_number) {
if(strlen(Mijireh::$access_key) < 5) {
throw new Mijireh_Exception('missing mijireh access key');
}
$rest = new Mijireh_RestJSON(Mijireh::$url);
$rest->setupAuth(Mijireh::$access_key, '');
try {
$order_data = $rest->get("orders/$order_number");
$this->copy_from($order_data);
return $this;
}
catch(Mijireh_Rest_BadRequest $e) {
throw new Mijireh_BadRequest($e->getMessage());
}
catch(Mijireh_Rest_Unauthorized $e) {
throw new Mijireh_Unauthorized("Unauthorized. Please check your api access key");
}
catch(Mijireh_Rest_NotFound $e) {
throw new Mijireh_NotFound("Mijireh resource not found: " . $rest->last_request['url']);
}
catch(Mijireh_Rest_ClientError $e) {
throw new Mijireh_ClientError($e->getMessage());
}
catch(Mijireh_Rest_ServerError $e) {
throw new Mijireh_ServerError($e->getMessage());
}
}
public function copy_from($order_data) {
foreach($order_data as $key => $value) {
if($key == 'items') {
if(is_array($value)) {
$this->clear_items(); // Clear current items before adding new items.
foreach($value as $item_array) {
$item = new Mijireh_Item();
$item->copy_from($item_array);
$this->add_item($item);
}
}
}
elseif($key == 'shipping_address') {
if(is_array($value)) {
$address = new Mijireh_Address();
$address->copy_from($value);
$this->set_shipping_address($address);
}
}
elseif($key == 'billing_address') {
if(is_array($value)) {
$address = new Mijireh_Address();
$address->copy_from($value);
$this->set_billing_address($address);
}
}
elseif($key == 'meta_data') {
if(is_array($value)) {
$this->clear_meta_data(); // Clear current meta data before adding new meta data
$this->_data['meta_data'] = $value;
}
}
else {
$this->$key = $value;
}
}
if(!$this->validate()) {
throw new Mijireh_Exception('invalid order hydration: ' . $this->get_errors_lines());
}
return $this;
}
public function create() {
if(strlen(Mijireh::$access_key) < 5) {
throw new Mijireh_Exception('missing mijireh access key');
}
if(!$this->validate()) {
$error_message = 'unable to create order: ' . $this->get_error_lines();
throw new Mijireh_Exception($error_message);
}
$rest = new Mijireh_RestJSON(Mijireh::$url);
$rest->setupAuth(Mijireh::$access_key, '');
try {
$result = $rest->post('orders', $this->get_data());
$this->copy_from($result);
return $this;
}
catch(Mijireh_Rest_BadRequest $e) {
throw new Mijireh_BadRequest($e->getMessage());
}
catch(Mijireh_Rest_Unauthorized $e) {
throw new Mijireh_Unauthorized("Unauthorized. Please check your api access key");
}
catch(Mijireh_Rest_NotFound $e) {
throw new Mijireh_NotFound("Mijireh resource not found: " . $rest->last_request['url']);
}
catch(Mijireh_Rest_ClientError $e) {
throw new Mijireh_ClientError($e->getMessage());
}
catch(Mijireh_Rest_ServerError $e) {
throw new Mijireh_ServerError($e->getMessage());
}
}
/**
* If meta_data or shipping_address are empty, exclude them altogether.
*/
public function get_data() {
$data = parent::get_data();
if(count($data['meta_data']) == 0) { unset($data['meta_data']); }
if(count($data['shipping_address']) == 0) { unset($data['shipping_address']); }
if(count($data['billing_address']) == 0) { unset($data['billing_address']); }
return $data;
}
/**
* Add the specified item and price to the order.
* Return the total number of items in the order (including the one that was just added)
*
* @param Mijireh_Item|string $name
* @param int $price
* @param int $quantity
* @param string $sku
* @throws Mijireh_Exception
* @return int
*/
public function add_item($name, $price=0, $quantity=1, $sku='') {
$item = '';
if(is_object($name) && get_class($name) == 'Mijireh_Item') {
$item = $name;
}
else {
$item = new Mijireh_Item();
$item->name = $name;
$item->price = $price;
$item->quantity = $quantity;
$item->sku = $sku;
}
if($item->validate()) {
$this->_data['items'][] = $item->get_data();
return $this->item_count();
}
else {
$errors = implode(' ', $item->get_errors());
throw new Mijireh_Exception('unable to add invalid item to order :: ' . $errors);
}
}
/**
* @param string $key
* @param integer $value
*/
public function add_meta_data($key, $value) {
if(!is_array($this->_data['meta_data'])) {
$this->_data['meta_data'] = array();
}
$this->_data['meta_data'][$key] = $value;
}
/**
* Return the value associated with the given key in the order's meta data.
*
* If the key does not exist, return false.
* @param string $key
*/
public function get_meta_value($key) {
$value = false;
if(isset($this->_data['meta_data'][$key])) {
$value = $this->_data['meta_data'][$key];
}
return $value;
}
public function item_count() {
$item_count = 0;
if(is_array($this->_data['items'])) {
$item_count = count($this->_data['items']);
}
return $item_count;
}
public function get_items() {
$items = array();
foreach($this->_data['items'] as $item_data) {
$item = new Mijireh_Item();
$item->copy_from($item_data);
}
}
public function clear_items() {
$this->_data['items'] = array();
}
public function clear_meta_data() {
$this->_data['meta_data'] = array();
}
public function validate() {
$this->_check_total();
$this->_check_return_url();
$this->_check_items();
return count($this->_errors) == 0;
}
/**
* Alias for set_shipping_address()
*/
public function set_address(Mijireh_Address $address){
$this->set_shipping_address($address);
}
public function set_shipping_address(Mijireh_Address $address) {
if($address->validate()) {
$this->_data['shipping_address'] = $address->get_data();
}
else {
throw new Mijireh_Exception('invalid shipping address');
}
}
public function set_billing_address(Mijireh_Address $address) {
if($address->validate()) {
$this->_data['billing_address'] = $address->get_data();
}
else {
throw new Mijireh_Exception('invalid shipping address');
}
}
/**
* Alias for get_shipping_address()
*/
public function get_address() {
return $this->get_shipping_address();
}
public function get_shipping_address() {
$address = false;
if(is_array($this->_data['shipping_address'])) {
$address = new Mijireh_Address();
$address->copy_from($this->_data['shipping_address']);
}
return $address;
}
public function get_billing_address() {
$address = false;
if(is_array($this->_data['billing_address'])) {
$address = new Mijireh_Address();
$address->copy_from($this->_data['billing_address']);
}
return $address;
}
/**
* The order total must be greater than zero.
*
* Return true if valid, otherwise false.
*
* @return boolean
*/
private function _check_total() {
$is_valid = true;
if($this->_data['total'] <= 0) {
$this->add_error('order total must be greater than zero');
$is_valid = false;
}
return $is_valid;
}
/**
* The return url must be provided and must start with http.
*
* Return true if valid, otherwise false
*
* @return boolean
*/
private function _check_return_url() {
$is_valid = false;
if(!empty($this->_data['return_url'])) {
$url = $this->_data['return_url'];
if('http' == strtolower(substr($url, 0, 4))) {
$is_valid = true;
}
else {
$this->add_error('return url is invalid');
}
}
else {
$this->add_error('return url is required');
}
return $is_valid;
}
/**
* An order must contain at least one item
*
* Return true if the order has at least one item, otherwise false.
*
* @return boolean
*/
private function _check_items() {
$is_valid = true;
if(count($this->_data['items']) <= 0) {
$is_valid = false;
$this->add_error('the order must contain at least one item');
}
return $is_valid;
}
}

View File

@ -1,265 +0,0 @@
<?php
/**
* Mijireh_Rest is a REST client for PHP.
*
* This code is licensed for use, modification, and distribution
* under the terms of the MIT License (see http://en.wikipedia.org/wiki/MIT_License)
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Mijireh_Rest {
public $curl_opts = array(
CURLOPT_RETURNTRANSFER => true, // return result instead of echoing
CURLOPT_SSL_VERIFYPEER => false, // stop cURL from verifying the peer's certificate
CURLOPT_MAXREDIRS => 10 // but don't redirect more than 10 times
);
public $base_url;
public $last_response;
public $last_request;
public $throw_exceptions = true;
public function __construct($base_url, $curl_options=null) {
if (!function_exists('curl_init')) {
throw new Exception('CURL module not available! Mijireh_Rest requires CURL. See http://php.net/manual/en/book.curl.php');
}
if(isset($curl_options) && is_array($curl_options)) {
foreach($curl_options as $key => $value) {
if($key == 'CURLOPT_FOLLOWLOCATION') {
// only enable CURLOPT_FOLLOWLOCATION if safe_mode and open_base_dir are not in use
if(ini_get('open_basedir') == '' && !ini_get('safe_mode')) {
$this->curl_opts['CURLOPT_FOLLOWLOCATION'] = true;
}
}
else {
$this->curl_opts[$key] = $value;
}
}
}
$this->base_url = $base_url;
}
// $auth can be 'basic' or 'digest'
/**
* @param string $pass
*/
public function setupAuth($user, $pass, $auth = 'basic') {
$this->curl_opts[CURLOPT_HTTPAUTH] = constant('CURLAUTH_'.strtoupper($auth));
$this->curl_opts[CURLOPT_USERPWD] = $user . ":" . $pass;
}
public function get($url) {
$curl = $this->prepRequest($this->curl_opts, $url);
$body = $this->doRequest($curl);
$body = $this->processBody($body);
return $body;
}
/**
* @param string $data
* @param string $url
*/
public function post($url, $data, $headers=array()) {
$data = (is_array($data)) ? http_build_query($data) : $data;
$curl_opts = $this->curl_opts;
$curl_opts[CURLOPT_CUSTOMREQUEST] = 'POST';
$headers[] = 'Content-Length: '.strlen($data);
$curl_opts[CURLOPT_HTTPHEADER] = $headers;
$curl_opts[CURLOPT_POSTFIELDS] = $data;
$curl = $this->prepRequest($curl_opts, $url);
$body = $this->doRequest($curl);
$body = $this->processBody($body);
return $body;
}
/**
* @param string $data
*/
public function put($url, $data, $headers=array()) {
$data = (is_array($data)) ? http_build_query($data) : $data;
$curl_opts = $this->curl_opts;
$curl_opts[CURLOPT_CUSTOMREQUEST] = 'PUT';
$headers[] = 'Content-Length: '.strlen($data);
$curl_opts[CURLOPT_HTTPHEADER] = $headers;
$curl_opts[CURLOPT_POSTFIELDS] = $data;
$curl = $this->prepRequest($curl_opts, $url);
$body = $this->doRequest($curl);
$body = $this->processBody($body);
return $body;
}
public function delete($url) {
$curl_opts = $this->curl_opts;
$curl_opts[CURLOPT_CUSTOMREQUEST] = 'DELETE';
$curl = $this->prepRequest($curl_opts, $url);
$body = $this->doRequest($curl);
$body = $this->processBody($body);
return $body;
}
public function lastBody() {
return $this->last_response['body'];
}
public function lastStatus() {
return $this->last_response['meta']['http_code'];
}
protected function processBody($body) {
// Override this in classes that extend Mijireh_Rest.
// The body of every GET/POST/PUT/DELETE response goes through
// here prior to being returned.
return $body;
}
/**
* @return string|null
*/
protected function processError($body) {
// Override this in classes that extend Mijireh_Rest.
// The body of every erroneous (non-2xx/3xx) GET/POST/PUT/DELETE
// response goes through here prior to being used as the 'message'
// of the resulting Mijireh_Rest_Exception
return $body;
}
protected function prepRequest($opts, $url) {
if (strncmp($url, $this->base_url, strlen($this->base_url)) != 0) {
$url = $this->base_url . $url;
}
$curl = curl_init($url);
foreach ($opts as $opt => $val) {
@curl_setopt($curl, $opt, $val);
}
$this->last_request = array(
'url' => $url
);
if (isset($opts[CURLOPT_CUSTOMREQUEST]))
$this->last_request['method'] = $opts[CURLOPT_CUSTOMREQUEST];
else
$this->last_request['method'] = 'GET';
if (isset($opts[CURLOPT_POSTFIELDS]))
$this->last_request['data'] = $opts[CURLOPT_POSTFIELDS];
return $curl;
}
/**
* @param resource $curl
*/
private function doRequest($curl) {
$body = curl_exec($curl);
$meta = curl_getinfo($curl);
$this->last_response = array(
'body' => $body,
'meta' => $meta
);
curl_close($curl);
$this->checkLastResponseForError();
return $body;
}
protected function checkLastResponseForError() {
if ( !$this->throw_exceptions)
return;
$meta = $this->last_response['meta'];
$body = $this->last_response['body'];
if (!$meta)
return;
$err = null;
switch ($meta['http_code']) {
case 400:
throw new Mijireh_Rest_BadRequest($this->processError($body));
break;
case 401:
throw new Mijireh_Rest_Unauthorized($this->processError($body));
break;
case 403:
throw new Mijireh_Rest_Forbidden($this->processError($body));
break;
case 404:
throw new Mijireh_Rest_NotFound($this->processError($body));
break;
case 405:
throw new Mijireh_Rest_MethodNotAllowed($this->processError($body));
break;
case 409:
throw new Mijireh_Rest_Conflict($this->processError($body));
break;
case 410:
throw new Mijireh_Rest_Gone($this->processError($body));
break;
case 422:
// Unprocessable Entity -- see http://www.iana.org/assignments/http-status-codes
// This is now commonly used (in Rails, at least) to indicate
// a response to a request that is syntactically correct,
// but semantically invalid (for example, when trying to
// create a resource with some required fields missing)
throw new Mijireh_Rest_InvalidRecord($this->processError($body));
break;
default:
if ($meta['http_code'] >= 400 && $meta['http_code'] <= 499)
throw new Mijireh_Rest_ClientError($this->processError($body));
elseif ($meta['http_code'] >= 500 && $meta['http_code'] <= 599)
throw new Mijireh_Rest_ServerError($this->processError($body));
elseif (!$meta['http_code'] || $meta['http_code'] >= 600) {
throw new Mijireh_Rest_UnknownResponse($this->processError($body));
}
}
}
}
class Mijireh_Rest_Exception extends Exception { }
class Mijireh_Rest_UnknownResponse extends Mijireh_Rest_Exception { }
/* 401-499 */ class Mijireh_Rest_ClientError extends Mijireh_Rest_Exception {}
/* 400 */ class Mijireh_Rest_BadRequest extends Mijireh_Rest_ClientError {}
/* 401 */ class Mijireh_Rest_Unauthorized extends Mijireh_Rest_ClientError {}
/* 403 */ class Mijireh_Rest_Forbidden extends Mijireh_Rest_ClientError {}
/* 404 */ class Mijireh_Rest_NotFound extends Mijireh_Rest_ClientError {}
/* 405 */ class Mijireh_Rest_MethodNotAllowed extends Mijireh_Rest_ClientError {}
/* 409 */ class Mijireh_Rest_Conflict extends Mijireh_Rest_ClientError {}
/* 410 */ class Mijireh_Rest_Gone extends Mijireh_Rest_ClientError {}
/* 422 */ class Mijireh_Rest_InvalidRecord extends Mijireh_Rest_ClientError {}
/* 500-599 */ class Mijireh_Rest_ServerError extends Mijireh_Rest_Exception {}

View File

@ -1,30 +0,0 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Mijireh_RestJSON extends Mijireh_Rest {
/**
* @param string $url
*/
public function post($url, $data, $headers=array()) {
return parent::post($url, json_encode($data), $headers);
}
public function put($url, $data, $headers=array()) {
return parent::put($url, json_encode($data), $headers);
}
protected function prepRequest($opts, $url) {
$opts[CURLOPT_HTTPHEADER][] = 'Accept: application/json';
$opts[CURLOPT_HTTPHEADER][] = 'Content-Type: application/json';
return parent::prepRequest($opts, $url);
}
public function processBody($body) {
return json_decode($body, true);
}
}

View File

@ -30,10 +30,6 @@ wp_trash_post( get_option( 'woocommerce_view_order_page_id' ) );
wp_trash_post( get_option( 'woocommerce_change_password_page_id' ) );
wp_trash_post( get_option( 'woocommerce_logout_page_id' ) );
// mijireh checkout page
if ( $mijireh_page = get_page_by_path( 'mijireh-secure-checkout' ) )
wp_trash_post( $mijireh_page->ID );
// Tables
$wpdb->query( "DROP TABLE IF EXISTS " . $wpdb->prefix . "woocommerce_attribute_taxonomies" );
$wpdb->query( "DROP TABLE IF EXISTS " . $wpdb->prefix . "woocommerce_downloadable_product_permissions" );