diff --git a/src/API/Auth/Basic.php b/src/API/Auth/Basic.php index f9ccf84..6cb874b 100644 --- a/src/API/Auth/Basic.php +++ b/src/API/Auth/Basic.php @@ -12,6 +12,10 @@ public function auth() { return true; } + public function get_url() { + return ''; + } + abstract protected function get_username(); abstract protected function get_password(); diff --git a/src/API/Auth/OAuth.php b/src/API/Auth/OAuth.php index 738660a..fa0fa02 100644 --- a/src/API/Auth/OAuth.php +++ b/src/API/Auth/OAuth.php @@ -10,6 +10,8 @@ public function get_type() { abstract protected function get_access_token(); + abstract public function get_url(); + public function get_headers() { $headers = array(); diff --git a/src/API/REST.php b/src/API/REST.php index 06e4cff..5b22cff 100644 --- a/src/API/REST.php +++ b/src/API/REST.php @@ -34,7 +34,13 @@ protected function get_auth() { * @return bool */ protected function is_auth_request( $url ) { - return strstr( $url, $this->get_auth()->get_url() ); + $auth_url = $this->get_auth()->get_url(); + + if ( empty( $auth_url ) ) { + return false; + } + + return strstr( $url, $auth_url ); } protected function get_timeout( $request_type = 'GET' ) { @@ -68,7 +74,6 @@ protected function maybe_encode_body( $body_args, $content_type = '' ) { * @return Response */ protected function get_response( $url, $type = 'GET', $body_args = array(), $headers = array() ) { - $headers = $this->get_headers( $headers ); $response = false; $is_auth_request = false; @@ -78,6 +83,12 @@ protected function get_response( $url, $type = 'GET', $body_args = array(), $hea $auth_response = $this->get_auth()->auth(); } + /** + * Need to build-up headers after (potentially) performing the auth request + * to make sure new auth headers are set. + */ + $headers = $this->get_headers( $headers ); + if ( 'GET' === $type ) { $response = wp_remote_get( esc_url_raw( $url ), diff --git a/src/DataStores/Shipment.php b/src/DataStores/Shipment.php index bbf5aed..dc2f68c 100644 --- a/src/DataStores/Shipment.php +++ b/src/DataStores/Shipment.php @@ -206,7 +206,6 @@ public function update( &$shipment ) { // Shipping provider has changed - lets remove existing label if ( in_array( 'shipping_provider', $changed_props, true ) ) { - if ( $shipment->supports_label() && $shipment->has_label() ) { $shipment->get_label()->delete(); } diff --git a/src/Install.php b/src/Install.php index 743c5ee..f49eac8 100644 --- a/src/Install.php +++ b/src/Install.php @@ -549,7 +549,7 @@ private static function get_schema() { shipment_date_sent_gmt datetime default NULL, shipment_est_delivery_date datetime default NULL, shipment_est_delivery_date_gmt datetime default NULL, - shipment_status varchar(20) NOT NULL default 'gzd-draft', + shipment_status varchar(150) NOT NULL default 'gzd-draft', shipment_order_id bigint(20) unsigned NOT NULL DEFAULT 0, shipment_packaging_id bigint(20) unsigned NOT NULL DEFAULT 0, shipment_parent_id bigint(20) unsigned NOT NULL DEFAULT 0, diff --git a/src/PickupDelivery.php b/src/PickupDelivery.php index a1596d2..cc4f8fb 100644 --- a/src/PickupDelivery.php +++ b/src/PickupDelivery.php @@ -716,14 +716,20 @@ public static function register_assets() { } public static function get_excluded_gateways() { + $excluded_gateways = array( 'cod' ); + + if ( ! is_admin() ) { + $excluded_gateways[] = 'amazon_payments_advanced'; + } + /** * Filter to disable pickup delivery for certain gateways. * * @param array $gateways Array of gateway IDs to exclude. */ - $codes = apply_filters( 'woocommerce_gzd_shipments_pickup_delivery_excluded_gateways', array( 'cod', 'amazon_payments_advanced' ) ); + $excluded_gateways = apply_filters( 'woocommerce_gzd_shipments_pickup_delivery_excluded_gateways', $excluded_gateways ); - return $codes; + return $excluded_gateways; } public static function get_pickup_delivery_cart_args() {