Download wp-calypso/client/landing/stepper/utils/checkout.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.67 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/landing/stepper/utils/checkout.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/landing/stepper/utils/checkout.ts
-
curl -L -o checkout.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/landing/stepper/utils/checkout.ts
1.67 kB
| import { addQueryArgs } from '@wordpress/url'; | |
| import { | |
| setSignupCompleteSlug, | |
| persistSignupDestination, | |
| setSignupCompleteFlowName, | |
| setSignupCompleteStepName, | |
| } from 'calypso/signup/storageUtils'; | |
| interface GoToCheckoutProps { | |
| flowName: string; | |
| stepName: string; | |
| siteSlug: string; | |
| destination: string; | |
| from?: string; | |
| plan?: string; | |
| cancelDestination?: string; | |
| extraProducts?: string[]; | |
| forceRedirection?: boolean; | |
| extraQueryParams?: Record< string, string >; | |
| } | |
| export const goToCheckout = ( { | |
| flowName, | |
| stepName, | |
| siteSlug, | |
| destination, | |
| plan, | |
| cancelDestination, | |
| extraProducts = [], | |
| extraQueryParams: extraParams = {}, | |
| }: GoToCheckoutProps ) => { | |
| const relativeCurrentPath = window.location.href.replace( window.location.origin, '' ); | |
| const params = { | |
| redirect_to: destination, | |
| cancel_to: cancelDestination || relativeCurrentPath, | |
| signup: '1', | |
| ...extraParams, | |
| }; | |
| persistSignupDestination( destination ); | |
| setSignupCompleteSlug( siteSlug ); | |
| setSignupCompleteFlowName( flowName ); | |
| setSignupCompleteStepName( stepName ); | |
| const products = [ ...( plan ? [ plan ] : [] ), ...extraProducts ]; | |
| const productSlugs = products.length > 0 ? `/${ products.join( ',' ) }` : ''; | |
| // If no products are provided, we might have added plan to the cart so we just go to the checkout page directly. | |
| // If the flag forceRedirection is true, we also go to the checkout page via redirection. | |
| // The theme upsell link does not work with siteId and requires a siteSlug. | |
| // See https://github.com/Automattic/wp-calypso/pull/64899 | |
| window.location.href = addQueryArgs( | |
| `/checkout/${ encodeURIComponent( siteSlug ) }${ productSlugs }`, | |
| params | |
| ); | |
| }; | |