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 a12126d commit 036add0
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 102 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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",
"automattic/jetpack-transport-helper": "^0.1.6-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
56 changes: 28 additions & 28 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": "d2e3788fc073345a8f216f297c78cdca7946c224"
"reference": "14790ec7ffe25df6825452353f4af1994cbfcfa8"
},
"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": "4a9f3876f33ec5c69505ea6647036658e8b71eb6"
"reference": "0c7f04f1b8dcd71cb9252d8fda5af25b56a3f1cf"
},
"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": "6077689273d77f1fa90de5ad1ba2baf58d865cc4"
"reference": "d5eb8510f7389f60ee8557be747968c20681cddb"
},
"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": "0a63260d24a8d36f7cdec94069c65d74af267129"
"reference": "6c8c25f46322ba4da34775ba96aad51a33f7a684"
},
"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": "d1a224b99dbb1a0d4245d1cea09a26e937a5969f"
"reference": "784a4b6838c2420da1cba519766e6c659261115a"
},
"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": "1f9ee9274e93ddf682c93200259c0c8ae04a69be"
"reference": "b815752d754f7a9a1e824b29a5c95c35d5cdf124"
},
"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": "cf3a4c47aa61834d0caef79000b671660a5f3b9f"
"reference": "a208550b0b1462784fc23ca2a94d29cd6fff2efb"
},
"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": "64c5cbe6bc69278039c2e3223e923073540f2bd5"
"reference": "397f0e173b405ead12fe28a2e4cb9d0efbc43c48"
},
"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": "dfe8f3b71a0a0725e4be0cf0c6b9f8de6ab0e741"
"reference": "568068edfa40a00513e8eafb6842aed322a90402"
},
"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": "db537bc12f12716c52725588e8518a1403c925eb"
"reference": "0156cc69d7695dc045c96ad2bf69345d7d59326b"
},
"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": "8b25e3f9eb0fe8097f61ebabd3c3f18bc90d44e2"
"reference": "cb07e4953bd2aa0bd4b2a97cc910e08b45f543f2"
},
"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": "f35f52ed860b29c41f0419bba80a4e5b2595024f"
"reference": "18da716e251028cdf8849f30006371a433880d92"
},
"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": "6962caf178a8f6e39201baea2c4315b703089da3"
"reference": "3d8d4c227de7ea8d2d0daef346bf9f14fdc4fd6b"
},
"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": "b3858aafb7470f2a3db11942098314dd682d8797"
"reference": "c3c2c20d85d49f3276098b77e9d95b49d313bbad"
},
"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": "160fd143c9257952e03d6913d1226d61994a6c19"
"reference": "7b85b10920f38cad414e8ffb09dd6ac26f096328"
},
"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": "7a5b81ad38f1f3b491f2da6996134413284dac05"
"reference": "193bfb5cff49c304dd62dec0a1b1af45014cbc3d"
},
"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": "68e334baff25d907e9ac48de45d4d6b9a3bfc1fe"
"reference": "41fb22b90c49904b1552329ea19c2b3d0c185d2e"
},
"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-plans",
"reference": "fc3310d0a2180388b955a623874463295f6da7d7"
"reference": "6733beaf598bcde5b9e11ac3747f1ba8645c81f0"
},
"require": {
"automattic/jetpack-connection": "^1.57.4"
Expand Down Expand Up @@ -1125,7 +1125,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-plugins-installer",
"reference": "00f1696cccacc2bc0d8827829b70ab360e3c92b2"
"reference": "64b547a0d0c785245216009d8858ecfe6db5e901"
},
"require": {
"automattic/jetpack-a8c-mc-stats": "^1.4.21"
Expand Down Expand Up @@ -1179,7 +1179,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-redirect",
"reference": "51dcc051440793d69684ea19502af89108f4b6ea"
"reference": "ed2916e54873f8f8a30da0626b643bb368e0e518"
},
"require": {
"automattic/jetpack-status": "^1.18.3"
Expand Down Expand Up @@ -1233,7 +1233,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-roles",
"reference": "35374bbd4ccff72bd97ea9ca49bde27f5afc08bb"
"reference": "e8ea7ccb4a02c910382adc220be4c798996b5ac7"
},
"require-dev": {
"automattic/jetpack-changelogger": "^3.3.8",
Expand Down Expand Up @@ -1284,7 +1284,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-status",
"reference": "f8e94cccf99bef1ae1050e93fd829b29d12b9d1e"
"reference": "84d05ca5c0ce9d701c7ed9c6951d7f57a10f5bc6"
},
"require": {
"automattic/jetpack-constants": "^1.6.23"
Expand Down Expand Up @@ -1339,7 +1339,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-sync",
"reference": "a8d95ab6716eb72e47d893ca73585830a111dcf4"
"reference": "5e52d24fc671b8fe3aee6740ea181de65520d64e"
},
"require": {
"automattic/jetpack-connection": "^1.57.4",
Expand Down Expand Up @@ -1409,7 +1409,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-transport-helper",
"reference": "e4904e7776570667036495244cad52aafeb33a60"
"reference": "83a25aa2ebc86c0036a633c1363a3d5ef08bcebf"
},
"require": {
"automattic/jetpack-connection": "^1.57.4"
Expand Down Expand Up @@ -1482,7 +1482,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-waf",
"reference": "91aa54c45be40617f95ecbb17507e927d80dc1e4"
"reference": "26de413879c660c2e699a3cc0f06dc938fb93f10"
},
"require": {
"automattic/jetpack-connection": "^1.57.4",
Expand Down
Loading

0 comments on commit 036add0

Please sign in to comment.