Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WooCommerce API Manager migration #12

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4c1abfe
Added WooCommerce classes (replicated from EDD).
vovafeldman Oct 31, 2016
62f38bd
Removed the minor EDD dependency left in the abstract migration endpo…
vovafeldman Nov 1, 2016
42c7465
Merge pull request #1 from Freemius/feature/woocommerce
shramee Nov 3, 2016
13cc199
Removing EDD and adding WC in /includes/*
shramee Nov 8, 2016
b12adcf
Admin settings and templates for WC
shramee Nov 8, 2016
20ef811
Sample file
shramee Nov 8, 2016
0f915ac
Plugin root files naming
shramee Nov 8, 2016
242ff6a
Order array example
shramee Nov 8, 2016
e13b34c
Plugin activation redirection and correcting namespace
shramee Nov 8, 2016
cad67e1
EDD > WC in file docs
shramee Nov 8, 2016
c408994
Updating FS_Entity_Map
shramee Nov 8, 2016
e79dae9
Subscriptions not implemented Exception...
shramee Nov 8, 2016
41c165a
WC Product to FS plugin and plans
shramee Nov 11, 2016
867bbaf
Migration endpoint changes
shramee Nov 11, 2016
9ab0cdb
FS_WC_Migration class
shramee Nov 11, 2016
2aa8aae
Undefined function
shramee Nov 11, 2016
cabff66
This is an abstract class, so it shouldn't be specifically associated…
vovafeldman Nov 11, 2016
ffaeab2
Merge pull request #9 from Freemius/develop
vovafeldman Nov 12, 2016
0fc17f0
Merge remote-tracking branch 'Freemius/feature/woocommerce'
shramee Nov 15, 2016
7752d5a
Merge remote-tracking branch 'origin/master'
shramee Nov 15, 2016
b46abb6
Resolving conflicts
shramee Nov 15, 2016
1deafc2
User's email not read for migration
shramee Nov 20, 2016
591318d
Fixing local pricing id, billing cycle and license quota
shramee Nov 25, 2016
7354ce0
Get correct ID even if products have same Software Title
shramee Nov 25, 2016
c443ab8
Email not used in API
shramee Nov 25, 2016
2a6ea37
Unknown payment method error
shramee Nov 29, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
define( 'WP_FSM__MAIN_ENDPOINT', 'fs-api' );
}

if ( ! defined( 'WP_FS__NAMESPACE_EDD' ) ) {
define( 'WP_FS__NAMESPACE_EDD', 'EDD' );
if ( ! defined( 'WP_FS__NAMESPACE_WC' ) ) {
define( 'WP_FS__NAMESPACE_WC', 'wc' );
}

if ( ! defined( 'WP_FS__IS_PRODUCTION_MODE' ) ) {
Expand Down
37 changes: 16 additions & 21 deletions freemius-edd-migration.php → freemius-wc-migration.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
<?php
/**
* Plugin Name: Freemius for EDD Migration
* Plugin Name: Freemius for WC Migration
* Plugin URI: http://freemius.com/
* Description: Server side endpoint to sync data between Freemius and EDD.
* Description: Server side endpoint to sync data between Freemius and WC.
* Version: 1.0.0
* Author: Freemius
* Author URI: http://freemius.com
* License: GPL2
*
* @requires
* 1. EDD 2.5 or higher, assuming payments currency is USD and have no fees.
* 1. WC 2.5 or higher, assuming payments currency is USD and have no fees.
* 2. PHP 5.3 or higher [using spl_autoload_register()]
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

function fs_edd_migration_init() {
if ( ! class_exists( 'Easy_Digital_Downloads' ) ||
! class_exists( 'EDD_Software_Licensing' )
) {
function fs_wc_migration_init() {
if ( ! class_exists( 'WooCommerce_API_Manager' ) ) {
deactivate_plugins( basename( __FILE__ ) );

// Message error + allow back link.
wp_die(
__( 'Freemius for EDD Migration plugin requires Easy Digital Downloads and its Software Licensing extension to be active.',
'fs-edd-migration' ),
__( 'Freemius for WCAM Migration plugin requires WooCommerce API Manager.',
'fs-wc-migration' ),
__( 'Error' ),
array( 'back_link' => true )
);
Expand All @@ -36,31 +34,28 @@ function fs_edd_migration_init() {
require_once __DIR__ . '/start.php';

// Load migration module.
require_once WP_FSM__DIR_MIGRATION . '/edd/class-fs-edd-migration-endpoint.php';
require_once WP_FSM__DIR_MIGRATION . '/wc/class-fs-wc-migration-endpoint.php';
}

// Get Freemius EDD Migration running.
add_action( 'plugins_loaded', 'fs_edd_migration_init' );
// Get Freemius WC Migration running.
add_action( 'plugins_loaded', 'fs_wc_migration_init' );

function fs_edd_migration_auto_redirect() {
function fs_wc_migration_auto_redirect() {
if ( ! function_exists( 'is_network_admin' ) || ! is_network_admin() ) {
if ( 'true' === get_option( 'fs_edd_migration_activated' ) ) {
if ( 'true' === get_option( 'fs_wc_migration_activated' ) ) {
// Load config.
require_once __DIR__ . '/start.php';

update_option( 'fs_edd_migration_activated', null );
update_option( 'fs_wc_migration_activated', null );

if ( fs_redirect( add_query_arg( array(
'post_type' => 'download',
'page' => 'fs-migration',
), admin_url( 'edit.php', 'admin' ) ) ) ) {
if ( fs_redirect( admin_url( 'admin.php?page=fs-migration' ) ) ) {
exit;
}
}
}
}

add_action( 'admin_init', 'fs_edd_migration_auto_redirect' );
add_action( 'admin_init', 'fs_wc_migration_auto_redirect' );

function fs_migration_plugin_activation() {
require_once __DIR__ . '/includes/class-fs-entity-mapper.php';
Expand All @@ -69,7 +64,7 @@ function fs_migration_plugin_activation() {
FS_Entity_Mapper::create_table();

// Hint the plugin that it was just activated.
update_option( "fs_edd_migration_activated", 'true' );
update_option( "fs_wc_migration_activated", 'true' );
}

register_activation_hook( __FILE__, 'fs_migration_plugin_activation' );
2 changes: 1 addition & 1 deletion includes/class-fs-entity-mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class FS_Entity_Mapper {
private $_table_name;

/**
* @var string E.g. EDD or WOO
* @var string E.g. WC or WOO
*/
private $_namespace;

Expand Down
2 changes: 1 addition & 1 deletion includes/class-fs-logger.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @package Freemius for EDD Add-On
* @package Freemius for WC Add-On
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion includes/class-fs-option-manager.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @package Freemius for EDD Add-On
* @package Freemius for WC Add-On
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion includes/entities/class-fs-billing.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @package Freemius for EDD Add-On
* @package Freemius for WC Add-On
* @copyright Copyright (c) 2016, Freemius, Inc.
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion includes/entities/class-fs-developer.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @package Freemius for EDD Add-On
* @package Freemius for WC Add-On
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
Expand Down
76 changes: 38 additions & 38 deletions includes/entities/class-fs-entity-map.php
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
<?php
/**
* @package Freemius for EDD Add-On
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
*/
/**
* @package Freemius for EDD Add-On
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

class FS_Entity_Map extends FS_Entity {
class FS_Entity_Map extends FS_Entity {

#region Properties
#region Properties

/**
* @var string
*/
public $namespace;
/**
* @var string
*/
public $entity_type;
/**
* @var string
*/
public $local_id;
/**
* @var number
*/
public $remote_id;
/**
* @var string
*/
public $namespace;
/**
* @var string
*/
public $entity_type;
/**
* @var string
*/
public $local_id;
/**
* @var number
*/
public $remote_id;

#endregion Properties
#endregion Properties

/**
* @param object|bool $entity_map
*/
function __construct( $entity_map = false ) {
parent::__construct( $entity_map );
}
/**
* @param object|bool $entity_map
*/
function __construct( $entity_map = false ) {
parent::__construct( $entity_map );
}

static function get_type() {
return 'map';
}
}
static function get_type() {
return 'map';
}
}
2 changes: 1 addition & 1 deletion includes/entities/class-fs-entity.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @package Freemius for EDD Add-On
* @package Freemius for WC Add-On
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion includes/entities/class-fs-event.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @package Freemius for EDD Add-On
* @package Freemius for WC Add-On
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion includes/entities/class-fs-install.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @package Freemius for EDD Add-On
* @package Freemius for WC Add-On
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion includes/entities/class-fs-license.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @package Freemius for EDD Add-On
* @package Freemius for WC Add-On
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion includes/entities/class-fs-payment.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @package Freemius for EDD Add-On
* @package Freemius for WC Add-On
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion includes/entities/class-fs-plan.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @package Freemius for EDD Add-On
* @package Freemius for WC Add-On
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion includes/entities/class-fs-pricing.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @package Freemius for EDD Add-On
* @package Freemius for WC Add-On
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion includes/entities/class-fs-scope-entity.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @package Freemius for EDD Add-On
* @package Freemius for WC Add-On
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion includes/entities/class-fs-subscription.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @package Freemius for EDD Add-On
* @package Freemius for WC Add-On
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion includes/entities/class-fs-user.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @package Freemius for EDD Add-On
* @package Freemius for WC Add-On
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
Expand Down
2 changes: 2 additions & 0 deletions includes/migration/class-fs-migration-abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,8 @@ protected function migrate_purchase( $customer_id ) {
* @return \FS_Subscription
*/
protected function migrate_subscription( $customer_id ) {
throw new Exception( 'Subscriptions not implemented' );

$result = $this->api_call(
"/users/{$customer_id}/plans/{$this->get_plan_id()}/pricing/{$this->get_pricing_id()}.json",
'post',
Expand Down
22 changes: 17 additions & 5 deletions includes/migration/class-fs-migration-endpoint-abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected function init( $namespace ) {
add_action( 'init', array( $this, 'maybe_process_api_request' ) );
}

// Reduce query load for EDD API calls
// Reduce query load for API calls.
add_action( 'after_setup_theme', array( $this, 'reduce_query_load' ) );

add_action( 'admin_menu', array( &$this, '_add_submenu' ), 99999999 );
Expand Down Expand Up @@ -173,7 +173,7 @@ protected function link_entity( FS_Entity $entity, $local_entity_id ) {
function get_remote_paid_plan_id( $local_module_id ) {
return $this->get_remote_id(
FS_Plan::get_type(),
$local_module_id . ':' . ( edd_has_variable_prices( $local_module_id ) ? '1' : '0' )
$this->get_local_paid_plan_id( $local_module_id )
);
}

Expand Down Expand Up @@ -301,7 +301,7 @@ function _notices() {
function _add_submenu() {
// Add Freemius submenu item.
$hook = add_submenu_page(
'edit.php?post_type=download',
'woocommerce',
'Freemius',
'Freemius',
'manage_options',
Expand Down Expand Up @@ -358,7 +358,7 @@ function _save_settings() {
}

/**
* Get all EDD downloads mapped to FS objects for the settings page.
* Get all products mapped to FS objects for the settings page.
*
* @author Vova Feldman
* @since 1.0.0
Expand Down Expand Up @@ -797,7 +797,7 @@ public function _sync_module_to_freemius_callback() {
$local_module = $this->get_local_module_by_id( $local_module_id );

if ( false === $local_module ) {
// Post not exist or not an EDD download.
// Post not exist.
$this->shoot_json_failure( "There's no local module with the specified ID ({$local_module_id})." );
}

Expand Down Expand Up @@ -905,6 +905,18 @@ abstract protected function get_local_module_migration_manager( $local_module, F
*/
abstract protected function get_local_module_by_id( $local_module_id );

/**
* Should return the local plan ID.
*
* @author Vova Feldman
* @since 1.0.0
*
* @param string $local_module_id
*
* @return string
*/
abstract protected function get_local_paid_plan_id( $local_module_id );

/**
* Should return an array of all local modules.
*
Expand Down
4 changes: 2 additions & 2 deletions includes/migration/class-fs-module-migration-abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ abstract protected function get_local_paid_plan_pricing_count();
* Get local paid plan pricing unique IDs.
*
* This case is relevant when there are different pricing objects for the
* same feature-set but different license activations limit like in EDD.
* same feature-set but different license activations limit like in EDD or WC.
*
* @author Vova Feldman (@svovaf)
* @since 1.0.0
Expand Down Expand Up @@ -1017,4 +1017,4 @@ private function delete_plan( $plan_id ) {
}

#endregion
}
}
Loading