Skip to content

Commit

Permalink
Remove purchase token for siteless purchases
Browse files Browse the repository at this point in the history
  • Loading branch information
IanRamosC committed Nov 1, 2024
1 parent 25866ca commit bca6d64
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ const ConnectionStep = ( {
const { recordEvent } = useAnalytics();
const { setNotice, resetNotice } = useContext( NoticeContext );

const { purchaseToken, siteUrl, adminUrl } = getMyJetpackWindowInitialState();
const { siteUrl, adminUrl } = getMyJetpackWindowInitialState();
const redirectUri = `?redirect_uri=${ encodeURIComponent( window.location.href ) }`;
const connectAfterCheckoutUrl = `&connect_after_checkout=true&from_site_slug=${ siteUrl }&admin_url=${ adminUrl }`;
const query = `${ redirectUri }${ purchaseToken }${ connectAfterCheckoutUrl }`;
const query = `${ redirectUri }${ connectAfterCheckoutUrl }`;
const jetpackPlansPath = getRedirectUrl( 'jetpack-nav-plans-no-site', { query } );

const activationButtonLabel = __( 'Activate Jetpack in one click', 'jetpack-my-jetpack' );
Expand Down
45 changes: 0 additions & 45 deletions projects/packages/my-jetpack/src/class-initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,27 +202,6 @@ public static function can_use_analytics() {
return $tracking->should_enable_tracking( new Terms_Of_Service(), $status );
}

/**
* Gets a purchase token that is used for Jetpack logged out visitor checkout.
* The purchase token should be appended to all CTA url's that lead to checkout.
*
* @return string|boolean
*/
protected static function get_purchase_token() {
if ( ! self::current_user_can_purchase() ) {
return false;
}

$purchase_token = \Jetpack_Options::get_option( 'purchase_token', false );

if ( $purchase_token ) {
return $purchase_token;
}
// If the purchase token is not saved in the options table yet, then add it.
\Jetpack_Options::update_option( 'purchase_token', self::generate_purchase_token(), true );
return \Jetpack_Options::get_option( 'purchase_token', false );
}

/**
* Enqueue admin page assets.
*
Expand Down Expand Up @@ -287,7 +266,6 @@ public static function enqueue_scripts() {
'loadAddLicenseScreen' => self::is_licensing_ui_enabled(),
'adminUrl' => esc_url( admin_url() ),
'IDCContainerID' => static::get_idc_container_id(),
'purchaseToken' => self::get_purchase_token(),
'userIsAdmin' => current_user_can( 'manage_options' ),
'userIsNewToJetpack' => self::is_jetpack_user_new(),
'lifecycleStats' => array(
Expand Down Expand Up @@ -990,27 +968,4 @@ public static function alert_if_missing_connection( array $red_bubble_slugs ) {

return $red_bubble_slugs;
}

/**
* Generates a purchase token that is used for Jetpack logged out visitor checkout.
*
* @return string
*/
protected static function generate_purchase_token() {
return wp_generate_password( 12, false );
}

/**
* Determine if the current user is allowed to make Jetpack purchases.
*
* @return boolean True if the user can make purchases, false if not
*/
public static function current_user_can_purchase() {
// Make sure only administrators can make purchases.
if ( ! current_user_can( 'manage_options' ) ) {
return false;
}

return true;
}
}

0 comments on commit bca6d64

Please sign in to comment.