Skip to content

Commit

Permalink
Fix Intro Offer price description (#28424)
Browse files Browse the repository at this point in the history
* Fix how to calc Jetpack Backup intro offer price

* Add intro offer object to ProductDetailCard

* changelog

* Backup: fix PricingCard currency and details text

* Products: only return intro offer when available

This commit fixes the return of Wpcom_Products::get_product_pricing to only return `introductory_offer` when available

* Products: fix test_get_product_price

* Fix version mismatch

* Backup: revert intro offer calculation

* My Jetpack: revert monthly price calculation

* My Jetpack: fix price detail text condition

* Backup: fix price detail text condition

* Fix changelogger version

* Fix bad minification issue on production builds
  • Loading branch information
IanRamosC authored Jan 23, 2023
1 parent f575f37 commit 5f9a8a8
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fixes the price display for products with intro offers for the first month.
16 changes: 16 additions & 0 deletions projects/packages/backup/src/js/components/Admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,17 @@ const NoBackupCapabilities = () => {
const { tracks } = useAnalytics();
const [ priceAfter, setPriceAfter ] = useState( 0 );
const [ price, setPrice ] = useState( 0 );
const [ currencyCode, setCurrencyCode ] = useState( 'USD' );
const [ introOffer, setIntroOffer ] = useState( null );
const domain = useSelect( select => select( STORE_ID ).getCalypsoSlug(), [] );

useEffect( () => {
apiFetch( { path: '/jetpack/v4/backup-promoted-product-info' } ).then( res => {
setCurrencyCode( res.currency_code );
setPrice( res.cost / 12 );

if ( res.introductory_offer ) {
setIntroOffer( res.introductory_offer );
setPriceAfter( res.introductory_offer.cost_per_interval / 12 );
} else {
setPriceAfter( res.cost / 12 );
Expand All @@ -340,6 +345,15 @@ const NoBackupCapabilities = () => {
'Special introductory pricing, all renewals are at full price. 14 day money back guarantee.',
'jetpack-backup-pkg'
);
const priceDetails =
introOffer?.interval_unit === 'month' && introOffer?.interval_count === 1
? __( 'for the first month, billed yearly', 'jetpack-backup-pkg' )
: __(
'per month, billed yearly',
'jetpack-backup-pkg',
/* dummy arg to avoid bad minification */ 0
);

return (
<Container horizontalSpacing={ 3 } horizontalGap={ 3 }>
<Col lg={ 6 } md={ 6 } sm={ 4 }>
Expand Down Expand Up @@ -369,6 +383,8 @@ const NoBackupCapabilities = () => {
onCtaClick={ sendToCart }
priceAfter={ priceAfter }
priceBefore={ price }
currencyCode={ currencyCode }
priceDetails={ priceDetails }
title={ __( 'VaultPress Backup', 'jetpack-backup-pkg' ) }
/>
</Col>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const ProductDetailCard = ( { slug, onClick, trackButtonClick, className, suppor
discountPricePerMonth: discountPrice,
wpcomProductSlug,
wpcomFreeProductSlug,
introductoryOffer,
} = pricingForUi;

const { recordEvent } = useAnalytics();
Expand Down Expand Up @@ -145,6 +146,15 @@ const ProductDetailCard = ( { slug, onClick, trackButtonClick, className, suppor
} )
: null;

const priceDescription =
introductoryOffer?.intervalUnit === 'month' && introductoryOffer?.intervalCount === 1
? __( 'for the first month, billed yearly', 'jetpack-my-jetpack' )
: __(
'/month, paid yearly',
'jetpack-my-jetpack',
/* dummy arg to avoid bad minification */ 0
);

const clickHandler = useCallback( () => {
trackButtonClick();
onClick?.( mainCheckoutRedirect );
Expand Down Expand Up @@ -224,9 +234,7 @@ const ProductDetailCard = ( { slug, onClick, trackButtonClick, className, suppor
) }
<Price value={ discountPrice } currency={ currencyCode } isOld={ false } />
</div>
<Text className={ styles[ 'price-description' ] }>
{ __( '/month, paid yearly', 'jetpack-my-jetpack' ) }
</Text>
<Text className={ styles[ 'price-description' ] }>{ priceDescription }</Text>
</>
) }

Expand Down
3 changes: 3 additions & 0 deletions projects/packages/my-jetpack/_inc/state/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export const getProduct = ( state, productId ) => {

const product = mapObjectKeysToCamel( stateProduct, true );
product.pricingForUi = mapObjectKeysToCamel( product.pricingForUi || {}, true );
product.pricingForUi.introductoryOffer = product.pricingForUi.isIntroductoryOffer
? mapObjectKeysToCamel( product.pricingForUi.introductoryOffer, true )
: null;
product.features = product.features || [];
product.supportedProducts = product.supportedProducts || [];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fixes the price display for products with intro offers for the first month.
3 changes: 3 additions & 0 deletions projects/packages/my-jetpack/src/class-wpcom-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,21 @@ public static function get_product_pricing( $product_slug ) {
$cost = $product->cost;
$discount_price = $cost;
$is_introductory_offer = false;
$introductory_offer = null;

// Get/compute the discounted price.
if ( isset( $product->introductory_offer->cost_per_interval ) ) {
$discount_price = $product->introductory_offer->cost_per_interval;
$is_introductory_offer = true;
$introductory_offer = $product->introductory_offer;
}

$pricing = array(
'currency_code' => $product->currency_code,
'full_price' => $cost,
'discount_price' => $discount_price,
'is_introductory_offer' => $is_introductory_offer,
'introductory_offer' => $introductory_offer,
);

return self::populate_with_discount( $product, $pricing, $discount_price );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public function test_get_product_price() {
'full_price' => 4.9,
'discount_price' => 2.45,
'is_introductory_offer' => false,
'introductory_offer' => null,
'coupon_discount' => 50,
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

Intro offers: fix the price display and description for products with intro offers for the first month.

0 comments on commit 5f9a8a8

Please sign in to comment.