Skip to content

selectIsEveryAvailablePaymentFree$(): Observable<boolean>

The selectIsEveryAvailablePaymentFree$ method allows you to observe whether every available payment option is free.

Returned value

A returned value has a type of Observable<boolean>. It emits true if every available payment option is free; otherwise, it emits false.

Example

In this example, we make a basketShippingsApi call to observe whether every available payment option is free.

useStorefront(async (storefront) => {
    let basketShippingsApi = storefront.getApiSync('basketShippingsApi');

    if (!basketShippingsApi) {
        const featureSystemApi = this.getApiSync(FEATURE_SYSTEM_API_NAME);
        await featureSystemApi.registerDynamic('basket');

        basketShippingsApi = storefront.getApiSync('basketShippingsApi');
    }

    const isEveryPaymentFree$ = basketShippingsApi.selectIsEveryAvailablePaymentFree$();

    isEveryPaymentFree$.subscribe((isFree) => {
        if (isFree) {
            console.log('All available payment options are free.');
        } else {
            console.log('Some payment options have associated costs.');
        }
    });
});

Basket Address API methods reference