Remove install support for Woo.com hosted products (#42952)
* Installer url API * Redirect if installer not available * Remove paid product autoinstall support --------- Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
parent
df17713dea
commit
8d6621ece1
|
@ -13,6 +13,7 @@ import { recordEvent } from '@woocommerce/tracks';
|
|||
import { SubscriptionsContext } from '../../../../contexts/subscriptions-context';
|
||||
import {
|
||||
addNotice,
|
||||
getInstallUrl,
|
||||
installProduct,
|
||||
removeNotice,
|
||||
} from '../../../../utils/functions';
|
||||
|
@ -59,68 +60,102 @@ export default function Install( props: InstallProps ) {
|
|||
|
||||
startInstall();
|
||||
removeNotice( props.subscription.product_key );
|
||||
installProduct( props.subscription )
|
||||
.then( () => {
|
||||
loadSubscriptions( false ).then( () => {
|
||||
|
||||
if ( props.subscription.is_installable ) {
|
||||
installProduct( props.subscription )
|
||||
.then( () => {
|
||||
loadSubscriptions( false ).then( () => {
|
||||
addNotice(
|
||||
props.subscription.product_key,
|
||||
sprintf(
|
||||
// translators: %s is the product name.
|
||||
__(
|
||||
'%s successfully installed.',
|
||||
'woocommerce'
|
||||
),
|
||||
props.subscription.product_name
|
||||
),
|
||||
NoticeStatus.Success
|
||||
);
|
||||
stopInstall();
|
||||
} );
|
||||
|
||||
recordEvent( 'marketplace_product_installed', {
|
||||
product_zip_slug: props.subscription.zip_slug,
|
||||
product_id: props.subscription.product_id,
|
||||
product_current_version: props.subscription.version,
|
||||
} );
|
||||
|
||||
if ( props.onSuccess ) {
|
||||
props.onSuccess();
|
||||
}
|
||||
} )
|
||||
.catch( ( error ) => {
|
||||
loadSubscriptions( false ).then( () => {
|
||||
let errorMessage = sprintf(
|
||||
// translators: %s is the product name.
|
||||
__( '%s couldn’t be installed.', 'woocommerce' ),
|
||||
props.subscription.product_name
|
||||
);
|
||||
if ( error?.success === false && error?.data.message ) {
|
||||
errorMessage += ' ' + error.data.message;
|
||||
}
|
||||
addNotice(
|
||||
props.subscription.product_key,
|
||||
errorMessage,
|
||||
NoticeStatus.Error,
|
||||
{
|
||||
actions: [
|
||||
{
|
||||
label: __( 'Try again', 'woocommerce' ),
|
||||
onClick: install,
|
||||
},
|
||||
],
|
||||
}
|
||||
);
|
||||
stopInstall();
|
||||
|
||||
if ( props.onError ) {
|
||||
props.onError();
|
||||
}
|
||||
} );
|
||||
|
||||
recordEvent( 'marketplace_product_install_failed', {
|
||||
product_zip_slug: props.subscription.zip_slug,
|
||||
product_id: props.subscription.product_id,
|
||||
product_current_version: props.subscription.version,
|
||||
error_message: error?.data?.message,
|
||||
} );
|
||||
} );
|
||||
} else {
|
||||
getInstallUrl( props.subscription ).then( ( url: string ) => {
|
||||
recordEvent( 'marketplace_product_install_url', {
|
||||
product_zip_slug: props.subscription.zip_slug,
|
||||
product_id: props.subscription.product_id,
|
||||
product_current_version: props.subscription.version,
|
||||
product_install_url: url,
|
||||
} );
|
||||
|
||||
stopInstall();
|
||||
|
||||
if ( url ) {
|
||||
window.open( url, '_self' );
|
||||
} else {
|
||||
addNotice(
|
||||
props.subscription.product_key,
|
||||
sprintf(
|
||||
// translators: %s is the product name.
|
||||
__( '%s successfully installed.', 'woocommerce' ),
|
||||
__(
|
||||
'%s couldn’t be installed. Please install the product manually.',
|
||||
'woocommerce'
|
||||
),
|
||||
props.subscription.product_name
|
||||
),
|
||||
NoticeStatus.Success
|
||||
NoticeStatus.Error
|
||||
);
|
||||
stopInstall();
|
||||
} );
|
||||
|
||||
recordEvent( 'marketplace_product_installed', {
|
||||
product_zip_slug: props.subscription.zip_slug,
|
||||
product_id: props.subscription.product_id,
|
||||
product_current_version: props.subscription.version,
|
||||
} );
|
||||
|
||||
if ( props.onSuccess ) {
|
||||
props.onSuccess();
|
||||
}
|
||||
} )
|
||||
.catch( ( error ) => {
|
||||
loadSubscriptions( false ).then( () => {
|
||||
let errorMessage = sprintf(
|
||||
// translators: %s is the product name.
|
||||
__( '%s couldn’t be installed.', 'woocommerce' ),
|
||||
props.subscription.product_name
|
||||
);
|
||||
if ( error?.success === false && error?.data.message ) {
|
||||
errorMessage += ' ' + error.data.message;
|
||||
}
|
||||
addNotice(
|
||||
props.subscription.product_key,
|
||||
errorMessage,
|
||||
NoticeStatus.Error,
|
||||
{
|
||||
actions: [
|
||||
{
|
||||
label: __( 'Try again', 'woocommerce' ),
|
||||
onClick: install,
|
||||
},
|
||||
],
|
||||
}
|
||||
);
|
||||
stopInstall();
|
||||
|
||||
if ( props.onError ) {
|
||||
props.onError();
|
||||
}
|
||||
} );
|
||||
|
||||
recordEvent( 'marketplace_product_install_failed', {
|
||||
product_zip_slug: props.subscription.zip_slug,
|
||||
product_id: props.subscription.product_id,
|
||||
product_current_version: props.subscription.version,
|
||||
error_message: error?.data?.message,
|
||||
} );
|
||||
} );
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
@ -30,6 +30,7 @@ export type Subscription = {
|
|||
version: string;
|
||||
subscription_installed: boolean;
|
||||
subscription_available: boolean;
|
||||
is_installable: boolean;
|
||||
};
|
||||
|
||||
export interface SubscriptionLocal {
|
||||
|
|
|
@ -310,6 +310,16 @@ function activateProduct( subscription: Subscription ): Promise< void > {
|
|||
);
|
||||
}
|
||||
|
||||
function getInstallUrl( subscription: Subscription ): Promise< string > {
|
||||
return apiFetch( {
|
||||
path:
|
||||
'/wc/v3/marketplace/subscriptions/install-url?product_key=' +
|
||||
subscription.product_key,
|
||||
} ).then( ( response ) => {
|
||||
return ( response as { data: { url: string } } )?.data.url;
|
||||
} );
|
||||
}
|
||||
|
||||
function installProduct( subscription: Subscription ): Promise< void > {
|
||||
return connectProduct( subscription ).then( () => {
|
||||
return wpAjax( 'install-' + subscription.product_type, {
|
||||
|
@ -423,6 +433,7 @@ export {
|
|||
fetchSearchResults,
|
||||
fetchSubscriptions,
|
||||
refreshSubscriptions,
|
||||
getInstallUrl,
|
||||
installProduct,
|
||||
updateProduct,
|
||||
addNotice,
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: update
|
||||
Comment: Replace installer with redirect for Woo.com hosted products.
|
||||
|
|
@ -99,11 +99,6 @@ class WC_Helper_Plugin_Info {
|
|||
$results = json_decode( wp_remote_retrieve_body( $request ), true );
|
||||
if ( ! empty( $results ) ) {
|
||||
$response = (object) $results;
|
||||
|
||||
$product = array_shift( $products );
|
||||
if ( isset( $product['package'] ) ) {
|
||||
$response->download_link = $product['package'];
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
|
|
@ -94,6 +94,22 @@ class WC_Helper_Subscriptions_API {
|
|||
),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
'wc/v3',
|
||||
'/marketplace/subscriptions/install-url',
|
||||
array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array( __CLASS__, 'install_url' ),
|
||||
'permission_callback' => array( __CLASS__, 'get_permission' ),
|
||||
'args' => array(
|
||||
'product_key' => array(
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -257,6 +273,50 @@ class WC_Helper_Subscriptions_API {
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the install URL for a WooCommerce.com product.
|
||||
*
|
||||
* @param WP_REST_Request $request Request object.
|
||||
*/
|
||||
public static function install_url( $request ) {
|
||||
$product_key = $request->get_param( 'product_key' );
|
||||
$subscription = WC_Helper::get_subscription( $product_key );
|
||||
|
||||
if ( ! $subscription ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => __( 'We couldn\'t find a subscription for this product.', 'woocommerce' ),
|
||||
),
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
if ( true === $subscription['local']['installed'] ) {
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'message' => __( 'This product is already installed.', 'woocommerce' ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
$install_url = WC_Helper::get_subscription_install_url( $subscription['product_key'] );
|
||||
|
||||
if ( ! $install_url ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => __( 'There was an error getting the install URL for this product.', 'woocommerce' ),
|
||||
),
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'url' => $install_url,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
WC_Helper_Subscriptions_API::load();
|
||||
|
|
|
@ -1177,6 +1177,35 @@ class WC_Helper {
|
|||
return $deactivated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a subscriptions install URL.
|
||||
*
|
||||
* @param string $product_key Subscription product key.
|
||||
* @return string
|
||||
*/
|
||||
public static function get_subscription_install_url( $product_key ) {
|
||||
$install_url_response = WC_Helper_API::get(
|
||||
'install-url',
|
||||
array(
|
||||
'authenticated' => true,
|
||||
'query_string' => esc_url( '?product_key=' . $product_key . '&wc_version=' . WC()->version ),
|
||||
)
|
||||
);
|
||||
|
||||
$code = wp_remote_retrieve_response_code( $install_url_response );
|
||||
if ( 200 !== $code ) {
|
||||
self::log( sprintf( 'Install URL API call returned a non-200 response code (%d)', $code ) );
|
||||
return '';
|
||||
}
|
||||
|
||||
$body = json_decode( wp_remote_retrieve_body( $install_url_response ), true );
|
||||
if ( empty( $body['data']['url'] ) ) {
|
||||
self::log( sprintf( 'Install URL API call returned an invalid body: %s', wp_remote_retrieve_body( $install_url_response ) ) );
|
||||
return '';
|
||||
}
|
||||
return $body['data']['url'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate a plugin.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue