Skip to content

Commit

Permalink
My Jetpack: Add Jetpack AI prices by tier to the interstitial page (#…
Browse files Browse the repository at this point in the history
…34196)

* enable prices for quantity-based products on interstitial pages

* get price depending on usage tier

* changelog

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/6932098518
  • Loading branch information
dhasilva authored and matticbot committed Nov 20, 2023
1 parent 550b631 commit 13381ed
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 86 deletions.
1 change: 1 addition & 0 deletions jetpack_vendor/automattic/jetpack-my-jetpack/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This is an alpha version! The changes listed here are not final.
### Added
- Display an "Activity Log" menu item to connected users.
- My Jetpack: Add direct checkout support for products with quantity-based plans
- My Jetpack: Add Jetpack AI prices by tier to the interstitial page

### Changed
- General: updated PHP requirement to PHP 7.0+
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' => '94ee643face0fb7415fd');
<?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' => 'd9c9430a7515ca0066f6');

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static function get_description() {
}

/**
* Get the internationalized usage tier long description
* Get the internationalized usage tier long description by tier
*
* @param int $tier The usage tier.
* @return string
Expand Down Expand Up @@ -141,7 +141,7 @@ public static function get_long_description() {
}

/**
* Get the internationalized usage tier features
* Get the internationalized usage tier features by tier
*
* @param int $tier The usage tier.
* @return string
Expand Down Expand Up @@ -187,17 +187,67 @@ public static function get_features() {
}

/**
* Get the product princing details
* Get the product pricing details by tier
*
* @param int $tier The usage tier.
* @return array Pricing details
*/
public static function get_pricing_for_ui_by_usage_tier( $tier ) {
$product = Wpcom_Products::get_product( static::get_wpcom_product_slug() );
$base_pricing = Wpcom_Products::get_product_pricing( static::get_wpcom_product_slug() );

if ( empty( $product ) ) {
return array();
}

if ( empty( $product->price_tier_list ) ) {
return $base_pricing;
}

$price_tier_list = $product->price_tier_list;
$yearly_prices = array();

foreach ( $price_tier_list as $price_tier ) {
if ( isset( $price_tier->maximum_units ) && isset( $price_tier->maximum_price ) ) {
// The prices are in cents
$yearly_prices[ $price_tier->maximum_units ] = $price_tier->maximum_price / 100;
}
}

$tiers = array( 100, 200, 500 );
$prices = array( 1 => $base_pricing );

foreach ( $tiers as $tier_value ) {
if ( isset( $yearly_prices[ $tier_value ] ) ) {
$prices[ $tier_value ] = array_merge(
$base_pricing,
array(
'full_price' => $yearly_prices[ $tier_value ],
'discount_price' => $yearly_prices[ $tier_value ],
'is_introductory_offer' => false,
'introductory_offer' => null,
)
);
}
}

return isset( $prices[ $tier ] ) ? $prices[ $tier ] : array();
}

/**
* Get the product pricing details
*
* @return array Pricing details
*/
public static function get_pricing_for_ui() {
$next_tier = self::get_next_usage_tier();

return array_merge(
array(
'available' => true,
'wpcom_product_slug' => static::get_wpcom_product_slug(),
),
Wpcom_Products::get_product_pricing( static::get_wpcom_product_slug() )
self::get_pricing_for_ui_by_usage_tier( $next_tier )
);
}

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' => '4.0.0-alpha1700485793',
'ver' => '4.0.0-alpha1700493412',
),
'jetpack-password-checker' => array(
'path' => 'jetpack_vendor/automattic/jetpack-password-checker',
Expand Down
Loading

0 comments on commit 13381ed

Please sign in to comment.