Skip to content

selectAvailable$(): Observable<BasketPayment[]>

The selectAvailable$ method provides an observable stream of the available payment options, allowing you to subscribe to real-time updates based on changes in the basket's state or user eligibility.

Returned value

A returned value has a type of Observable<BasketPayment[]> where BasketPayment represents the BasketPayment model, which emits the current list of available payment methods and updates whenever there are changes.

Example

In this example, we subscribe to the selectAvailable$ observable to monitor available payment options.

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

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

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

    const availablePaymentOptions$ = basketPaymentsApi.selectAvailable$();

    availablePaymentOptions$.subscribe((availablePaymentOptions) => {
        console.log('Updated available payment options:', availablePaymentOptions);
    });
});

Basket Payments API methods reference

Models reference