Skip to content

Commit

Permalink
My Jetpack: Show correct CTA and status for Stats card (#33058)
Browse files Browse the repository at this point in the history
* My Jetpack: Add support for upgradable products

* Mark no-plan, Stats Free & PWYW as upgradeable

* Add code comment

* changelog

* version update

* more version updates

* Bump versions

* add complete plan remove pwyw

* add complete plan remove pwyw

* revise comment

---------

Co-authored-by: Jason Moon <jsnmoon@users.noreply.github.com>
Co-authored-by: Grzegorz Chudzinski-Pawlowski <112354940+grzegorz-cp@users.noreply.github.com>
Co-authored-by: Dognose <dognose24@gmail.com>
Co-authored-by: Jasper Kang <kangzjnet@gmail.com>

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/6180739073
  • Loading branch information
kangzj authored and matticbot committed Sep 14, 2023
1 parent 402d02c commit cf46e62
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 96 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"automattic/jetpack-composer-plugin": "^1.1.13",
"automattic/jetpack-config": "^1.15.3",
"automattic/jetpack-identity-crisis": "^0.10.5-alpha",
"automattic/jetpack-my-jetpack": "^3.4.5",
"automattic/jetpack-my-jetpack": "^3.5.0-alpha",
"automattic/jetpack-plugins-installer": "^0.2.5",
"automattic/jetpack-sync": "^1.57.0-alpha"
},
Expand Down
8 changes: 8 additions & 0 deletions jetpack_vendor/automattic/jetpack-my-jetpack/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.5.0-alpha] - unreleased

This is an alpha version! The changes listed here are not final.

### Changed
- Added support for upgradable products. Updated the Stats card to handle upgradeable products.

## [3.4.5] - 2023-09-13
### Changed
- Updated package dependencies. [#33001]
Expand Down Expand Up @@ -1018,6 +1025,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Created package

[3.5.0-alpha]: https://github.com/Automattic/jetpack-my-jetpack/compare/3.4.5...3.5.0-alpha
[3.4.5]: https://github.com/Automattic/jetpack-my-jetpack/compare/3.4.4...3.4.5
[3.4.4]: https://github.com/Automattic/jetpack-my-jetpack/compare/3.4.3...3.4.4
[3.4.3]: https://github.com/Automattic/jetpack-my-jetpack/compare/3.4.2...3.4.3
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => 'a67c7452ff5b30375083');
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => 'a0b633c370d349fd89c8');
34 changes: 17 additions & 17 deletions jetpack_vendor/automattic/jetpack-my-jetpack/build/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion jetpack_vendor/automattic/jetpack-my-jetpack/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"link-template": "https://github.com/Automattic/jetpack-my-jetpack/compare/${old}...${new}"
},
"branch-alias": {
"dev-trunk": "3.4.x-dev"
"dev-trunk": "3.5.x-dev"
},
"version-constants": {
"::PACKAGE_VERSION": "src/class-initializer.php"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Initializer {
*
* @var string
*/
const PACKAGE_VERSION = '3.4.5';
const PACKAGE_VERSION = '3.5.0-alpha';

/**
* HTML container ID for the IDC screen on My Jetpack page.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ public static function populate_with_discount( $product, $pricing, $price ) {
* @return Object|WP_Error
*/
public static function get_site_current_purchases() {
// TODO: Add a short-lived cache (less than a minute) to accommodate repeated invocation of this function.
static $purchases = null;

if ( $purchases !== null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,15 @@ public static function has_trial_support() {
return false;
}

/**
* Checks whether the product can be upgraded to a different product.
*
* @return boolean
*/
public static function is_upgradable() {
return false;
}

/**
* Checks whether product is a bundle.
*
Expand Down Expand Up @@ -357,6 +366,9 @@ public static function get_status() {
// We only consider missing user connection an error when the Product is active.
if ( static::$requires_user_connection && ! ( new Connection_Manager() )->has_connected_owner() ) {
$status = 'error';
} elseif ( static::is_upgradable() ) {
// Upgradable plans should ignore whether or not they have the required plan.
$status = 'can_upgrade';
} elseif ( ! static::has_required_plan() ) { // We need needs_purchase here as well because some products we consider active without the required plan.
if ( static::has_trial_support() ) {
$status = 'needs_purchase_or_free';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,46 @@ public static function has_required_plan() {
return false;
}

/**
* Checks whether the product can be upgraded to a different product.
* Only Jetpack Stats Commercial plan is not upgradable.
*
* @return boolean
*/
public static function is_upgradable() {
$purchases_data = Wpcom_Products::get_site_current_purchases();
if ( is_wp_error( $purchases_data ) ) {
return false;
}
if ( is_array( $purchases_data ) && ! empty( $purchases_data ) ) {
foreach ( $purchases_data as $purchase ) {
if (
(
// Purchase is Jetpack Stats...
0 === strpos( $purchase->product_slug, 'jetpack_stats' ) &&
// but not Jetpack Stats Free...
false === strpos( $purchase->product_slug, 'free' )
) || 0 === strpos( $purchase->product_slug, 'jetpack_complete' )
) {
// Only Jetpack Stats paid plans should be eligible for this conditional.
// Sample product slugs: jetpack_stats_monthly
return false;
}
}
}
return true;
}

/**
* Checks whether the product supports trial or not.
* Since Jetpack Stats has been widely available as a free product in the past, it "supports" a trial.
*
* @return boolean
*/
public static function has_trial_support() {
return true;
}

/**
* Get the WordPress.com URL for purchasing Jetpack Stats for the current site.
*
Expand Down
2 changes: 1 addition & 1 deletion jetpack_vendor/i18n-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
),
'jetpack-my-jetpack' => array(
'path' => 'jetpack_vendor/automattic/jetpack-my-jetpack',
'ver' => '3.4.5',
'ver' => '3.5.0-alpha1694663900',
),
'jetpack-password-checker' => array(
'path' => 'jetpack_vendor/automattic/jetpack-password-checker',
Expand Down
50 changes: 25 additions & 25 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-a8c-mc-stats",
"reference": "8d792bdf011e5c388d69148ea13a408a757dbc77"
"reference": "4c1f1ee3642f4b187dcc74e30deaf7914f135179"
},
"require-dev": {
"automattic/jetpack-changelogger": "^3.3.8",
Expand Down Expand Up @@ -57,7 +57,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-admin-ui",
"reference": "6e0b95e6d7f501262fa68f01e290d1e59f39d524"
"reference": "d63ddadd8e401321c8d93619d760492ffe05e02b"
},
"require-dev": {
"automattic/jetpack-changelogger": "^3.3.8",
Expand Down Expand Up @@ -119,7 +119,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-assets",
"reference": "42410011c8799c2f1ed2aa02bd85178b41a2f5f9"
"reference": "bb4c531fd0ceb0a5dc02178bc4fda85b6b215787"
},
"require": {
"automattic/jetpack-constants": "^1.6.23"
Expand Down Expand Up @@ -187,7 +187,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-autoloader",
"reference": "3a84e6113b02f6e8acfc9998eee8b651f518ce29"
"reference": "1b29919f28b71bbbfb3715ce50d5fed77471fd96"
},
"require": {
"composer-plugin-api": "^1.1 || ^2.0"
Expand Down Expand Up @@ -249,7 +249,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-composer-plugin",
"reference": "106b5051e320fd96d54eb296def2ea2e3bdc3ff2"
"reference": "d607ed164456fde59643d866dfe073f0e459b591"
},
"require": {
"composer-plugin-api": "^2.1.0"
Expand Down Expand Up @@ -308,7 +308,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-config",
"reference": "980d8c6d44f444edcb3c2800dfdd5f7e20b558c7"
"reference": "0fc38ccb33c7c1500e5c2fe63e64e037055fd208"
},
"require-dev": {
"automattic/jetpack-changelogger": "^3.3.8"
Expand Down Expand Up @@ -350,7 +350,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-connection",
"reference": "7ff048ac90013e8e916554a34a423986a59d3ff6"
"reference": "7e2cdb93e20422c5b61b168e349445de329e1bb6"
},
"require": {
"automattic/jetpack-a8c-mc-stats": "^1.4.21",
Expand Down Expand Up @@ -428,7 +428,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-constants",
"reference": "5f7535b9628c8e404698b14ab3d72cd32a6d5f5d"
"reference": "505378c3e5fa58d9d8386af2136e1e5539d59fbb"
},
"require-dev": {
"automattic/jetpack-changelogger": "^3.3.8",
Expand Down Expand Up @@ -479,7 +479,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-device-detection",
"reference": "36ac964f923126822afa7d2d2b63d15772e9f45a"
"reference": "923c4877e8d308dfae55f4034930b29d4c392f0e"
},
"require-dev": {
"automattic/jetpack-changelogger": "^3.3.8",
Expand Down Expand Up @@ -529,7 +529,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-identity-crisis",
"reference": "ddfa58d9a450ba8a4d3d6db9517b261a8f525717"
"reference": "7044022021174d1525568592a1c476e982d1ea78"
},
"require": {
"automattic/jetpack-assets": "^1.18.10",
Expand Down Expand Up @@ -607,7 +607,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-ip",
"reference": "60419e121c63e89bb8d1ec31ae861bf14d16c8bd"
"reference": "9a59b6c7151252a168b0a805fc9aec168d874632"
},
"require-dev": {
"automattic/jetpack-changelogger": "^3.3.8",
Expand Down Expand Up @@ -662,7 +662,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-jitm",
"reference": "fd214f2667b0bfb208bd173442aecd30625c7472"
"reference": "51da63f33201f233ee3fd99fa6542cc55afddf79"
},
"require": {
"automattic/jetpack-a8c-mc-stats": "^1.4.21",
Expand Down Expand Up @@ -737,7 +737,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-licensing",
"reference": "e4575ed10429f61a7532f6d5b30bf27a11881d1f"
"reference": "cd313b4992ccc986ca672ba016b80bebd3df9b56"
},
"require": {
"automattic/jetpack-connection": "^1.57.4"
Expand Down Expand Up @@ -798,7 +798,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-logo",
"reference": "82bc67136fd284d913d810c3425a736204fb3653"
"reference": "5df59a6535091a275752d5ad2b25294e057f306a"
},
"require-dev": {
"automattic/jetpack-changelogger": "^3.3.8",
Expand Down Expand Up @@ -843,12 +843,12 @@
},
{
"name": "automattic/jetpack-my-jetpack",
"version": "3.4.5",
"version_normalized": "3.4.5.0",
"version": "3.5.0-alpha.1694663900",
"version_normalized": "3.5.0.0-alpha1694663900",
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-my-jetpack",
"reference": "6ca39e9cb80044fa01d51ce5216fe5b1a61ddf96"
"reference": "8bbe8c9ab5fc360cdab376bd435242d4d3d291b6"
},
"require": {
"automattic/jetpack-admin-ui": "^0.2.22",
Expand Down Expand Up @@ -878,7 +878,7 @@
"link-template": "https://github.com/Automattic/jetpack-my-jetpack/compare/${old}...${new}"
},
"branch-alias": {
"dev-trunk": "3.4.x-dev"
"dev-trunk": "3.5.x-dev"
},
"version-constants": {
"::PACKAGE_VERSION": "src/class-initializer.php"
Expand Down Expand Up @@ -938,7 +938,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-partner",
"reference": "777f58b223a7baed1fe3a7e198900ddae30f4dac"
"reference": "8449317b54b79e898f599d2692616cd6351f7ab3"
},
"require": {
"automattic/jetpack-connection": "^1.57.4",
Expand Down Expand Up @@ -1000,7 +1000,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-password-checker",
"reference": "df6d72f6948dda75334b36ea8ddcfd1cbfc4934b"
"reference": "ebb8cbe12e497dc4a8b7e8243de10d66526de1c3"
},
"require-dev": {
"automattic/jetpack-changelogger": "^3.3.8",
Expand Down Expand Up @@ -1058,7 +1058,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-plugins-installer",
"reference": "854e9364a7f6a5f16e3aa634f755c12910394d2b"
"reference": "099990f24a7096a68ee7f8ffebf06d827ac2fa7b"
},
"require": {
"automattic/jetpack-a8c-mc-stats": "^1.4.21"
Expand Down Expand Up @@ -1112,7 +1112,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-redirect",
"reference": "0aa0409644ebdc9a76e327c42867fde6d6a68031"
"reference": "e750f9d2b86327caf67b255a65a2c37509baf46e"
},
"require": {
"automattic/jetpack-status": "^1.18.3"
Expand Down Expand Up @@ -1166,7 +1166,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-roles",
"reference": "23ccf480329a29a640967e2fbd81f719e63d4252"
"reference": "0f5056c960dbc4b7ce5c1be27d327df6c1609e1a"
},
"require-dev": {
"automattic/jetpack-changelogger": "^3.3.8",
Expand Down Expand Up @@ -1217,7 +1217,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-status",
"reference": "9acaf6285dd78814581fe61afd68eb4d3bc9f09c"
"reference": "032115a7558626411ff23742c91a9c62d3fc8e98"
},
"require": {
"automattic/jetpack-constants": "^1.6.23"
Expand Down Expand Up @@ -1272,7 +1272,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-sync",
"reference": "e2cf7af123e0a32699d00b6343e7dbbea1a89cb7"
"reference": "2ada669597d1b98fdb3cb3b6d124ba7d3dfc25e2"
},
"require": {
"automattic/jetpack-connection": "^1.57.4",
Expand Down
Loading

0 comments on commit cf46e62

Please sign in to comment.