Skip to content

Commit

Permalink
Export utils functions directly
Browse files Browse the repository at this point in the history
  • Loading branch information
sirbrillig committed Dec 10, 2024
1 parent b58596b commit 9e5efd8
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions client/me/purchases/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import {
import { addPaymentMethod, changePaymentMethod, addNewPaymentMethod } from './paths';
import type { Purchase } from 'calypso/lib/purchases/types';

function isDataLoading( props: {
export function isDataLoading( props: {
hasLoadedSites: boolean;
hasLoadedUserPurchasesFromServer: boolean;
} ): boolean {
return ! props.hasLoadedSites || ! props.hasLoadedUserPurchasesFromServer;
}

function canEditPaymentDetails( purchase: Purchase ) {
export function canEditPaymentDetails( purchase: Purchase ) {
return (
! isExpired( purchase ) &&
! isOneTimePurchase( purchase ) &&
Expand All @@ -26,59 +26,46 @@ function canEditPaymentDetails( purchase: Purchase ) {
);
}

function getChangePaymentMethodPath( siteSlug: string, purchase: Purchase ) {
export function getChangePaymentMethodPath( siteSlug: string, purchase: Purchase ) {
if ( isPaidWithCreditCard( purchase ) && purchase.payment.creditCard ) {
return changePaymentMethod( siteSlug, purchase.id, purchase.payment.creditCard.id );
}

return addPaymentMethod( siteSlug, purchase.id );
}

function getAddNewPaymentMethodPath() {
export function getAddNewPaymentMethodPath() {
return addNewPaymentMethod;
}

function isTemporarySitePurchase( purchase: Purchase ) {
export function isTemporarySitePurchase( purchase: Purchase ) {
const { domain } = purchase;
// Currently only Jeypack, Akismet and some Marketplace products allow siteless/userless(license-based) purchases which require a temporary
// site(s) to work. This function may need to be updated in the future as additional products types
// incorporate siteless/userless(licensebased) product based purchases..
return /^siteless.(jetpack|akismet|marketplace.wp).com$/.test( domain );
}

function getTemporarySiteType( purchase: Purchase ) {
export function getTemporarySiteType( purchase: Purchase ) {
const { productType } = purchase;
return isTemporarySitePurchase( purchase ) ? productType : null;
}

function isAkismetTemporarySitePurchase( purchase: Purchase ) {
export function isAkismetTemporarySitePurchase( purchase: Purchase ) {
const { productType } = purchase;
return isTemporarySitePurchase( purchase ) && productType === 'akismet';
}

function isMarketplaceTemporarySitePurchase( purchase: Purchase ) {
export function isMarketplaceTemporarySitePurchase( purchase: Purchase ) {
const { productType } = purchase;
return isTemporarySitePurchase( purchase ) && productType === 'saas_plugin';
}

function isJetpackTemporarySitePurchase( purchase: Purchase ) {
export function isJetpackTemporarySitePurchase( purchase: Purchase ) {
const { productType } = purchase;
return isTemporarySitePurchase( purchase ) && productType === 'jetpack';
}

function getCancelPurchaseSurveyCompletedPreferenceKey( purchaseId: string | number ) {
export function getCancelPurchaseSurveyCompletedPreferenceKey( purchaseId: string | number ) {
return `cancel-purchase-survey-completed-${ purchaseId }`;
}

export {
canEditPaymentDetails,
getChangePaymentMethodPath,
getAddNewPaymentMethodPath,
isDataLoading,
isTemporarySitePurchase,
getCancelPurchaseSurveyCompletedPreferenceKey,
getTemporarySiteType,
isJetpackTemporarySitePurchase,
isAkismetTemporarySitePurchase,
isMarketplaceTemporarySitePurchase,
};

0 comments on commit 9e5efd8

Please sign in to comment.