Introduce new onboarding-options in JS hook

This commit is contained in:
Philipp Stracker 2025-02-21 21:12:20 +01:00
parent c0dbcf6884
commit 5919e45d1e
No known key found for this signature in database
3 changed files with 22 additions and 10 deletions

View file

@ -68,10 +68,11 @@ export function sandboxOnboardingUrl() {
/**
* Side effect. Fetches the ISU-login URL for a production account.
*
* @param {string[]} products Which products/features to display in the ISU popup.
* @param {string[]} [products=[]] Which products/features to display in the ISU popup.
* @param {Object} [options={}] Options to customize the onboarding workflow.
* @return {Function} The thunk function.
*/
export function productionOnboardingUrl( products = [] ) {
export function productionOnboardingUrl( products = [], options = {} ) {
return async () => {
try {
return apiFetch( {
@ -80,6 +81,7 @@ export function productionOnboardingUrl( products = [] ) {
data: {
useSandbox: false,
products,
options,
},
} );
} catch ( e ) {

View file

@ -35,7 +35,17 @@ export const flags = ( state ) => {
* @return {string[]} The ISU products, based on choices made in the onboarding wizard.
*/
export const determineProductsAndCaps = ( state ) => {
const derivedProducts = [];
/**
* An array of product-names that are used to build an onboarding URL via the
* PartnerReferrals API.
*/
const products = [];
/**
* Internal options that are parsed by the PartnerReferrals class to customize
* the API payload.
*/
const options = {};
const { isCasualSeller, areOptionalPaymentMethodsEnabled } =
persistentData( state );
@ -46,24 +56,24 @@ export const determineProductsAndCaps = ( state ) => {
* Branch 1: Credit Card Payments not available.
* The store uses the Express-checkout product.
*/
derivedProducts.push( 'EXPRESS_CHECKOUT' );
products.push( 'EXPRESS_CHECKOUT' );
} else if ( isCasualSeller ) {
/**
* Branch 2: Merchant has no business.
* The store uses the Express-checkout product.
*/
derivedProducts.push( 'EXPRESS_CHECKOUT' );
products.push( 'EXPRESS_CHECKOUT' );
} else {
/**
* Branch 3: Merchant is business, and can use CC payments.
* The store uses the advanced PPCP product.
*/
derivedProducts.push( 'PPCP' );
products.push( 'PPCP' );
}
if ( canUseVaulting ) {
derivedProducts.push( 'ADVANCED_VAULTING' );
products.push( 'ADVANCED_VAULTING' );
}
return derivedProducts;
return { products, options };
};

View file

@ -30,7 +30,7 @@ const ACTIVITIES = {
export const useHandleOnboardingButton = ( isSandbox ) => {
const { sandboxOnboardingUrl } = CommonHooks.useSandbox();
const { productionOnboardingUrl } = CommonHooks.useProduction();
const products = OnboardingHooks.useDetermineProducts();
const { products, options } = OnboardingHooks.useDetermineProducts();
const { startActivity } = CommonHooks.useBusyState();
const { authenticateWithOAuth } = CommonHooks.useAuthentication();
const [ onboardingUrl, setOnboardingUrl ] = useState( '' );
@ -43,7 +43,7 @@ export const useHandleOnboardingButton = ( isSandbox ) => {
if ( isSandbox ) {
res = await sandboxOnboardingUrl();
} else {
res = await productionOnboardingUrl( products );
res = await productionOnboardingUrl( products, options );
}
if ( res.success && res.data ) {