Version Description
- Better UX when selecting shipping label payment method
Download this release
Release Info
| Developer | woothemes |
| Plugin | |
| Version | 1.6.1 |
| Comparing to | |
| See all releases | |
Code changes from version 1.6.0 to 1.6.1
classes/class-wc-connect-api-client.php
CHANGED
|
@@ -382,6 +382,33 @@ if ( ! class_exists( 'WC_Connect_API_Client' ) ) {
|
|
| 382 |
return $response_body;
|
| 383 |
}
|
| 384 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
/**
|
| 386 |
* Adds useful WP/WC/WCC information to request bodies
|
| 387 |
*
|
| 382 |
return $response_body;
|
| 383 |
}
|
| 384 |
|
| 385 |
+
/**
|
| 386 |
+
* Proxy an HTTP request through the WCS Server
|
| 387 |
+
*
|
| 388 |
+
* @param $path Path of proxy route
|
| 389 |
+
* @param $args WP_Http request args
|
| 390 |
+
*
|
| 391 |
+
* @return array|WP_Error
|
| 392 |
+
*/
|
| 393 |
+
public function proxy_request( $path, $args ) {
|
| 394 |
+
$proxy_url = trailingslashit( WOOCOMMERCE_CONNECT_SERVER_URL );
|
| 395 |
+
$proxy_url .= ltrim( $path, '/' );
|
| 396 |
+
|
| 397 |
+
$args['headers']['Authorization'] = $this->authorization_header();
|
| 398 |
+
|
| 399 |
+
$http_timeout = 60; // 1 minute
|
| 400 |
+
|
| 401 |
+
if ( function_exists( 'wc_set_time_limit' ) ) {
|
| 402 |
+
wc_set_time_limit( $http_timeout + 10 );
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
$args['timeout'] = $http_timeout;
|
| 406 |
+
|
| 407 |
+
$response = wp_remote_request( $proxy_url, $args );
|
| 408 |
+
|
| 409 |
+
return $response;
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
/**
|
| 413 |
* Adds useful WP/WC/WCC information to request bodies
|
| 414 |
*
|
classes/class-wc-connect-payment-methods-store.php
CHANGED
|
@@ -50,31 +50,28 @@ if ( ! class_exists( 'WC_Connect_Payment_Methods_Store' ) ) {
|
|
| 50 |
}
|
| 51 |
|
| 52 |
protected function potentially_update_selected_payment_method_from_payment_methods( $payment_methods ) {
|
| 53 |
-
$payment_method_count = count( $payment_methods );
|
| 54 |
-
|
| 55 |
-
// No payment methods at all? Clear anything we have stored
|
| 56 |
-
if ( 0 === $payment_method_count ) {
|
| 57 |
-
$this->service_settings_store->set_selected_payment_method_id( 0 );
|
| 58 |
-
return;
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
$payment_method_ids = array();
|
|
|
|
| 62 |
foreach ( (array) $payment_methods as $payment_method ) {
|
| 63 |
$payment_method_id = intval( $payment_method->payment_method_id );
|
|
|
|
| 64 |
if ( 0 !== $payment_method_id ) {
|
| 65 |
$payment_method_ids[] = $payment_method_id;
|
| 66 |
}
|
| 67 |
}
|
| 68 |
|
| 69 |
-
//
|
| 70 |
-
if (
|
| 71 |
-
$this->service_settings_store->set_selected_payment_method_id(
|
| 72 |
return;
|
| 73 |
}
|
| 74 |
|
| 75 |
-
//
|
| 76 |
$selected_payment_method_id = $this->service_settings_store->get_selected_payment_method_id();
|
| 77 |
-
if (
|
|
|
|
|
|
|
|
|
|
| 78 |
$this->service_settings_store->set_selected_payment_method_id( $payment_method_ids[ 0 ] );
|
| 79 |
}
|
| 80 |
}
|
| 50 |
}
|
| 51 |
|
| 52 |
protected function potentially_update_selected_payment_method_from_payment_methods( $payment_methods ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
$payment_method_ids = array();
|
| 54 |
+
|
| 55 |
foreach ( (array) $payment_methods as $payment_method ) {
|
| 56 |
$payment_method_id = intval( $payment_method->payment_method_id );
|
| 57 |
+
|
| 58 |
if ( 0 !== $payment_method_id ) {
|
| 59 |
$payment_method_ids[] = $payment_method_id;
|
| 60 |
}
|
| 61 |
}
|
| 62 |
|
| 63 |
+
// No payment methods at all? Clear anything we have stored
|
| 64 |
+
if ( 0 === count( $payment_method_ids ) ) {
|
| 65 |
+
$this->service_settings_store->set_selected_payment_method_id( 0 );
|
| 66 |
return;
|
| 67 |
}
|
| 68 |
|
| 69 |
+
// Has the stored method ID been removed? Select the first available one
|
| 70 |
$selected_payment_method_id = $this->service_settings_store->get_selected_payment_method_id();
|
| 71 |
+
if (
|
| 72 |
+
$selected_payment_method_id &&
|
| 73 |
+
! in_array( $selected_payment_method_id, $payment_method_ids )
|
| 74 |
+
) {
|
| 75 |
$this->service_settings_store->set_selected_payment_method_id( $payment_method_ids[ 0 ] );
|
| 76 |
}
|
| 77 |
}
|
classes/class-wc-connect-taxjar-integration.php
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class WC_Connect_TaxJar_Integration {
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* @var WC_Connect_API_Client
|
| 7 |
+
*/
|
| 8 |
+
public $api_client;
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
* @var WC_Taxjar_Integration
|
| 12 |
+
*/
|
| 13 |
+
protected $taxjar_integration;
|
| 14 |
+
|
| 15 |
+
const TAXJAR_URL = 'https://api.taxjar.com';
|
| 16 |
+
const PROXY_PATH = 'taxjar';
|
| 17 |
+
const FAKE_TOKEN = '[Managed by WooCommerce Services]';
|
| 18 |
+
|
| 19 |
+
public function __construct( WC_Connect_API_Client $api_client ) {
|
| 20 |
+
$this->api_client = $api_client;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
public function init() {
|
| 24 |
+
add_filter( 'default_option_woocommerce_taxjar-integration_settings', array( $this, 'override_taxjar_settings' ) );
|
| 25 |
+
add_filter( 'option_woocommerce_taxjar-integration_settings', array( $this, 'check_taxjar_settings' ) );
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
public function check_taxjar_settings( $settings ) {
|
| 29 |
+
if (
|
| 30 |
+
isset( $settings['api_token'] ) &&
|
| 31 |
+
( $settings['api_token'] === strtolower( self::FAKE_TOKEN ) )
|
| 32 |
+
) {
|
| 33 |
+
return $this->override_taxjar_settings( $settings );
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
return $settings;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
public function override_taxjar_settings( $settings ) {
|
| 40 |
+
$store_city = get_option( 'woocommerce_store_city' );
|
| 41 |
+
$store_postcode = get_option( 'woocommerce_store_postcode' );
|
| 42 |
+
|
| 43 |
+
// Check for store address before hijacking requests.
|
| 44 |
+
if ( empty( $store_city ) || empty( $store_postcode ) ) {
|
| 45 |
+
return $settings;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
// Attach proxy filter.
|
| 49 |
+
add_filter( 'pre_http_request', array( $this, 'proxy_taxjar_requests' ), 10, 3 );
|
| 50 |
+
|
| 51 |
+
if ( ! is_array( $settings ) ) {
|
| 52 |
+
$settings = array();
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
$settings = array_merge( $settings, array(
|
| 56 |
+
'api_token' => self::FAKE_TOKEN,
|
| 57 |
+
'enabled' => 'yes',
|
| 58 |
+
'store_city' => $store_city,
|
| 59 |
+
'store_zip' => $store_postcode,
|
| 60 |
+
) );
|
| 61 |
+
|
| 62 |
+
return $settings;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
public function proxy_taxjar_requests( $pre, $r, $url ) {
|
| 66 |
+
// TODO: get verification requests working through proxy
|
| 67 |
+
if ( 'https://api.taxjar.com/v2/verify' === $url ) {
|
| 68 |
+
return array(
|
| 69 |
+
'response' => array(
|
| 70 |
+
'code' => 200,
|
| 71 |
+
),
|
| 72 |
+
'body' => '',
|
| 73 |
+
);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
// Proxy all TaxJar requests through the WCS server
|
| 77 |
+
if ( strpos( $url, self::TAXJAR_URL ) === 0 ) {
|
| 78 |
+
$taxjar_url = trailingslashit( self::TAXJAR_URL );
|
| 79 |
+
$wcs_path = trailingslashit( self::PROXY_PATH );
|
| 80 |
+
$proxy_path = str_replace( $taxjar_url, $wcs_path, $url );
|
| 81 |
+
|
| 82 |
+
return $this->api_client->proxy_request( $proxy_path, $r );
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
return $pre;
|
| 86 |
+
}
|
| 87 |
+
}
|
readme.txt
CHANGED
|
@@ -3,7 +3,7 @@ Contributors: automattic, woothemes, allendav, kellychoffman, jkudish, jeffstiel
|
|
| 3 |
Tags: canada-post, shipping, stamps, usps, woocommerce
|
| 4 |
Requires at least: 4.6
|
| 5 |
Tested up to: 4.8
|
| 6 |
-
Stable tag: 1.6.
|
| 7 |
License: GPLv2 or later
|
| 8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 9 |
|
|
@@ -79,6 +79,9 @@ The source code is freely available [in GitHub](https://github.com/Automattic/wo
|
|
| 79 |
|
| 80 |
== Changelog ==
|
| 81 |
|
|
|
|
|
|
|
|
|
|
| 82 |
= 1.6.0 =
|
| 83 |
* New streamlined onboarding process for plugin dependencies
|
| 84 |
* Better packaging workflow for orders not using live rates at checkout
|
| 3 |
Tags: canada-post, shipping, stamps, usps, woocommerce
|
| 4 |
Requires at least: 4.6
|
| 5 |
Tested up to: 4.8
|
| 6 |
+
Stable tag: 1.6.1
|
| 7 |
License: GPLv2 or later
|
| 8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 9 |
|
| 79 |
|
| 80 |
== Changelog ==
|
| 81 |
|
| 82 |
+
= 1.6.1 =
|
| 83 |
+
* Better UX when selecting shipping label payment method
|
| 84 |
+
|
| 85 |
= 1.6.0 =
|
| 86 |
* New streamlined onboarding process for plugin dependencies
|
| 87 |
* Better packaging workflow for orders not using live rates at checkout
|
woocommerce-services.php
CHANGED
|
@@ -7,7 +7,7 @@
|
|
| 7 |
* Author URI: http://woocommerce.com/
|
| 8 |
* Text Domain: woocommerce-services
|
| 9 |
* Domain Path: /i18n/languages/
|
| 10 |
-
* Version: 1.6.
|
| 11 |
*
|
| 12 |
* Copyright (c) 2017 Automattic
|
| 13 |
*
|
|
@@ -152,6 +152,11 @@ if ( ! class_exists( 'WC_Connect_Loader' ) ) {
|
|
| 152 |
*/
|
| 153 |
protected $nux;
|
| 154 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
protected $services = array();
|
| 156 |
|
| 157 |
protected $service_object_cache = array();
|
|
@@ -169,7 +174,7 @@ if ( ! class_exists( 'WC_Connect_Loader' ) ) {
|
|
| 169 |
public function __construct() {
|
| 170 |
$this->wc_connect_base_url = trailingslashit( defined( 'WOOCOMMERCE_CONNECT_DEV_SERVER_URL' ) ? WOOCOMMERCE_CONNECT_DEV_SERVER_URL : plugins_url( 'dist/', __FILE__ ) );
|
| 171 |
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
|
| 172 |
-
add_action( '
|
| 173 |
}
|
| 174 |
|
| 175 |
public function get_logger() {
|
|
@@ -332,6 +337,10 @@ if ( ! class_exists( 'WC_Connect_Loader' ) ) {
|
|
| 332 |
$this->nux = $nux;
|
| 333 |
}
|
| 334 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
/**
|
| 336 |
* Load our textdomain
|
| 337 |
*
|
|
@@ -342,11 +351,11 @@ if ( ! class_exists( 'WC_Connect_Loader' ) ) {
|
|
| 342 |
}
|
| 343 |
|
| 344 |
/**
|
| 345 |
-
*
|
| 346 |
*
|
| 347 |
-
*
|
| 348 |
*/
|
| 349 |
-
public function
|
| 350 |
$this->load_dependencies();
|
| 351 |
|
| 352 |
add_action( 'admin_init', array( $this, 'admin_enqueue_scripts' ) );
|
|
@@ -361,6 +370,16 @@ if ( ! class_exists( 'WC_Connect_Loader' ) ) {
|
|
| 361 |
return;
|
| 362 |
}
|
| 363 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
$this->schedule_service_schemas_fetch();
|
| 365 |
$this->service_settings_store->migrate_legacy_services();
|
| 366 |
$this->attach_hooks();
|
|
@@ -370,11 +389,12 @@ if ( ! class_exists( 'WC_Connect_Loader' ) ) {
|
|
| 370 |
* Load all plugin dependencies.
|
| 371 |
*/
|
| 372 |
public function load_dependencies() {
|
| 373 |
-
require_once( plugin_basename( 'classes/class-wc-connect-error-notice.php' ) );
|
| 374 |
-
require_once( plugin_basename( 'classes/class-wc-connect-compatibility.php' ) );
|
| 375 |
require_once( plugin_basename( 'classes/class-wc-connect-logger.php' ) );
|
| 376 |
require_once( plugin_basename( 'classes/class-wc-connect-api-client.php' ) );
|
| 377 |
require_once( plugin_basename( 'classes/class-wc-connect-service-schemas-validator.php' ) );
|
|
|
|
|
|
|
|
|
|
| 378 |
require_once( plugin_basename( 'classes/class-wc-connect-shipping-method.php' ) );
|
| 379 |
require_once( plugin_basename( 'classes/class-wc-connect-service-schemas-store.php' ) );
|
| 380 |
require_once( plugin_basename( 'classes/class-wc-connect-service-settings-store.php' ) );
|
|
@@ -384,6 +404,7 @@ if ( ! class_exists( 'WC_Connect_Loader' ) ) {
|
|
| 384 |
require_once( plugin_basename( 'classes/class-wc-connect-shipping-label.php' ) );
|
| 385 |
require_once( plugin_basename( 'classes/class-wc-connect-nux.php' ) );
|
| 386 |
|
|
|
|
| 387 |
$logger = new WC_Connect_Logger( new WC_Logger() );
|
| 388 |
$validator = new WC_Connect_Service_Schemas_Validator();
|
| 389 |
$api_client = new WC_Connect_API_Client( $validator, $this );
|
|
@@ -393,6 +414,7 @@ if ( ! class_exists( 'WC_Connect_Loader' ) ) {
|
|
| 393 |
$tracks = new WC_Connect_Tracks( $logger, __FILE__ );
|
| 394 |
$shipping_label = new WC_Connect_Shipping_Label( $api_client, $settings_store, $schemas_store, $payment_methods_store );
|
| 395 |
$nux = new WC_Connect_Nux( $tracks, $shipping_label );
|
|
|
|
| 396 |
|
| 397 |
$this->set_logger( $logger );
|
| 398 |
$this->set_api_client( $api_client );
|
|
@@ -403,6 +425,9 @@ if ( ! class_exists( 'WC_Connect_Loader' ) ) {
|
|
| 403 |
$this->set_tracks( $tracks );
|
| 404 |
$this->set_shipping_label( $shipping_label );
|
| 405 |
$this->set_nux( $nux );
|
|
|
|
|
|
|
|
|
|
| 406 |
}
|
| 407 |
|
| 408 |
/**
|
| 7 |
* Author URI: http://woocommerce.com/
|
| 8 |
* Text Domain: woocommerce-services
|
| 9 |
* Domain Path: /i18n/languages/
|
| 10 |
+
* Version: 1.6.1
|
| 11 |
*
|
| 12 |
* Copyright (c) 2017 Automattic
|
| 13 |
*
|
| 152 |
*/
|
| 153 |
protected $nux;
|
| 154 |
|
| 155 |
+
/**
|
| 156 |
+
* @var WC_Connect_TaxJar_Integration
|
| 157 |
+
*/
|
| 158 |
+
protected $taxjar;
|
| 159 |
+
|
| 160 |
protected $services = array();
|
| 161 |
|
| 162 |
protected $service_object_cache = array();
|
| 174 |
public function __construct() {
|
| 175 |
$this->wc_connect_base_url = trailingslashit( defined( 'WOOCOMMERCE_CONNECT_DEV_SERVER_URL' ) ? WOOCOMMERCE_CONNECT_DEV_SERVER_URL : plugins_url( 'dist/', __FILE__ ) );
|
| 176 |
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
|
| 177 |
+
add_action( 'before_woocommerce_init', array( $this, 'pre_wc_init' ) );
|
| 178 |
}
|
| 179 |
|
| 180 |
public function get_logger() {
|
| 337 |
$this->nux = $nux;
|
| 338 |
}
|
| 339 |
|
| 340 |
+
public function set_taxjar( WC_Connect_TaxJar_Integration $taxjar ) {
|
| 341 |
+
$this->taxjar = $taxjar;
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
/**
|
| 345 |
* Load our textdomain
|
| 346 |
*
|
| 351 |
}
|
| 352 |
|
| 353 |
/**
|
| 354 |
+
* Perform plugin bootstrapping that needs to happen before WC init.
|
| 355 |
*
|
| 356 |
+
* This allows the modification of extensions, integrations, etc.
|
| 357 |
*/
|
| 358 |
+
public function pre_wc_init() {
|
| 359 |
$this->load_dependencies();
|
| 360 |
|
| 361 |
add_action( 'admin_init', array( $this, 'admin_enqueue_scripts' ) );
|
| 370 |
return;
|
| 371 |
}
|
| 372 |
|
| 373 |
+
add_action( 'woocommerce_init', array( $this, 'after_wc_init' ) );
|
| 374 |
+
$this->taxjar->init();
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
/**
|
| 378 |
+
* Bootstrap our plugin and hook into WP/WC core.
|
| 379 |
+
*
|
| 380 |
+
* @codeCoverageIgnore
|
| 381 |
+
*/
|
| 382 |
+
public function after_wc_init() {
|
| 383 |
$this->schedule_service_schemas_fetch();
|
| 384 |
$this->service_settings_store->migrate_legacy_services();
|
| 385 |
$this->attach_hooks();
|
| 389 |
* Load all plugin dependencies.
|
| 390 |
*/
|
| 391 |
public function load_dependencies() {
|
|
|
|
|
|
|
| 392 |
require_once( plugin_basename( 'classes/class-wc-connect-logger.php' ) );
|
| 393 |
require_once( plugin_basename( 'classes/class-wc-connect-api-client.php' ) );
|
| 394 |
require_once( plugin_basename( 'classes/class-wc-connect-service-schemas-validator.php' ) );
|
| 395 |
+
require_once( plugin_basename( 'classes/class-wc-connect-taxjar-integration.php' ) );
|
| 396 |
+
require_once( plugin_basename( 'classes/class-wc-connect-error-notice.php' ) );
|
| 397 |
+
require_once( plugin_basename( 'classes/class-wc-connect-compatibility.php' ) );
|
| 398 |
require_once( plugin_basename( 'classes/class-wc-connect-shipping-method.php' ) );
|
| 399 |
require_once( plugin_basename( 'classes/class-wc-connect-service-schemas-store.php' ) );
|
| 400 |
require_once( plugin_basename( 'classes/class-wc-connect-service-settings-store.php' ) );
|
| 404 |
require_once( plugin_basename( 'classes/class-wc-connect-shipping-label.php' ) );
|
| 405 |
require_once( plugin_basename( 'classes/class-wc-connect-nux.php' ) );
|
| 406 |
|
| 407 |
+
|
| 408 |
$logger = new WC_Connect_Logger( new WC_Logger() );
|
| 409 |
$validator = new WC_Connect_Service_Schemas_Validator();
|
| 410 |
$api_client = new WC_Connect_API_Client( $validator, $this );
|
| 414 |
$tracks = new WC_Connect_Tracks( $logger, __FILE__ );
|
| 415 |
$shipping_label = new WC_Connect_Shipping_Label( $api_client, $settings_store, $schemas_store, $payment_methods_store );
|
| 416 |
$nux = new WC_Connect_Nux( $tracks, $shipping_label );
|
| 417 |
+
$taxjar = new WC_Connect_TaxJar_Integration( $api_client );
|
| 418 |
|
| 419 |
$this->set_logger( $logger );
|
| 420 |
$this->set_api_client( $api_client );
|
| 425 |
$this->set_tracks( $tracks );
|
| 426 |
$this->set_shipping_label( $shipping_label );
|
| 427 |
$this->set_nux( $nux );
|
| 428 |
+
$this->set_taxjar( $taxjar );
|
| 429 |
+
|
| 430 |
+
add_action( 'admin_init', array( $this, 'load_admin_dependencies' ) );
|
| 431 |
}
|
| 432 |
|
| 433 |
/**
|
