Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion client/dashboard/me/billing-history/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { formatCurrency } from '@automattic/number-formatters';
import { formatCurrency, formatNumber } from '@automattic/number-formatters';
import { __, _n, sprintf } from '@wordpress/i18n';
import {
isDIFMProduct,
isGoogleWorkspace,
isTitanMail,
isTieredVolumeSpaceAddon,
isJetpackSearch,
isJetpackStatsPaidProductSlug,
} from '../../utils/purchase';
import type { Receipt, ReceiptItem } from '@automattic/api-core';
import type { IntroductoryOfferTerms } from '@automattic/shopping-cart';
Expand Down Expand Up @@ -153,6 +154,22 @@ function renderJetpackSearchQuantitySummary( licensedQuantity: number, isRenewal
);
}

function renderJetpackStatsQuantitySummary( licensedQuantity: number, isRenewal: boolean ) {
if ( isRenewal ) {
return sprintf(
/* translators: %s: formatted number of views per month */
__( 'Renewal for %s views per month' ),
formatNumber( licensedQuantity )
);
}

return sprintf(
/* translators: %s: formatted number of views per month */
__( 'Purchase for %s views per month' ),
formatNumber( licensedQuantity )
);
}

function renderSpaceAddOnquantitySummary( licensedQuantity: number, isRenewal: boolean ) {
if ( isRenewal ) {
return sprintf(
Expand Down Expand Up @@ -224,6 +241,10 @@ export function renderTransactionQuantitySummary( {
return renderJetpackSearchQuantitySummary( licensedQuantity, isRenewal );
}

if ( isJetpackStatsPaidProductSlug( wpcom_product_slug ) ) {
return renderJetpackStatsQuantitySummary( licensedQuantity, isRenewal );
}

if ( isGoogleWorkspace( product ) || isTitanMail( product ) ) {
return renderTransactionQuantitySummaryForMailboxes(
licensedQuantity,
Expand Down
16 changes: 16 additions & 0 deletions client/dashboard/utils/purchase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,22 @@ export function isJetpackSearch( product: ObjectWithProductSlug ): boolean {
: false;
}

const JETPACK_STATS_PAID_PRODUCT_SLUGS = [
'jetpack_stats_bi_yearly',
'jetpack_stats_yearly',
'jetpack_stats_monthly',
'jetpack_stats_pwyw_yearly',
] as const;

/**
* Checks if a product slug is a paid Jetpack Stats product.
*/
export function isJetpackStatsPaidProductSlug( productSlug: string | undefined ): boolean {
return productSlug
? ( JETPACK_STATS_PAID_PRODUCT_SLUGS as readonly string[] ).includes( productSlug )
: false;
}

export function isJetpackT1SecurityPlan( purchase: Purchase ): boolean {
const securityT1Slugs = [
JetpackPlans.PLAN_JETPACK_SECURITY_T1_YEARLY,
Expand Down
25 changes: 24 additions & 1 deletion client/me/purchases/billing-history/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import {
isTitanMail,
isTieredVolumeSpaceAddon,
isJetpackSearch,
isJetpackStatsPaidProductSlug,
} from '@automattic/calypso-products';
import { formatCurrency } from '@automattic/number-formatters';
import { formatCurrency, formatNumber } from '@automattic/number-formatters';
import { LocalizeProps, useTranslate } from 'i18n-calypso';
import { Fragment } from 'react';
import { useTaxName } from 'calypso/my-sites/checkout/src/hooks/use-country-list';
Expand Down Expand Up @@ -230,6 +231,24 @@ function renderJetpackSearchQuantitySummary(
} );
}

function renderJetpackStatsQuantitySummary(
licensed_quantity: number,
isRenewal: boolean,
translate: LocalizeProps[ 'translate' ]
) {
if ( isRenewal ) {
return translate( 'Renewal for %(quantity)s views per month', {
args: { quantity: formatNumber( licensed_quantity ) },
comment: '%(quantity)s is the number of views per month for Jetpack Stats',
} );
}

return translate( 'Purchase for %(quantity)s views per month', {
args: { quantity: formatNumber( licensed_quantity ) },
comment: '%(quantity)s is the number of views per month for Jetpack Stats',
} );
}

function renderSpaceAddOnquantitySummary(
licensed_quantity: number,
isRenewal: boolean,
Expand Down Expand Up @@ -311,6 +330,10 @@ export function renderTransactionQuantitySummary(
return renderJetpackSearchQuantitySummary( licensed_quantity, isRenewal, translate );
}

if ( isJetpackStatsPaidProductSlug( wpcom_product_slug ) ) {
return renderJetpackStatsQuantitySummary( licensed_quantity, isRenewal, translate );
}

if ( isGoogleWorkspace( product ) || isTitanMail( product ) ) {
return renderTransactionQuantitySummaryForMailboxes(
licensed_quantity,
Expand Down
Loading