Skip to content

selectActivePaymentCost$(): Observable<FullPrice | undefined>

The selectActivePaymentCost$ method provides an observable that emits updates to the cost of the active payment option, allowing you to monitor changes in real-time.

Returned value

A returned value has a type of Observable<FullPrice | undefined> where FullPrice represents the FullPrice model which emits the current cost of the active payment method and updates whenever the cost changes.

Example

In this example, we subscribe to the selectActivePaymentCost$ observable to track changes to the active payment cost.

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

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

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

    const activePaymentCost$ = basketPaymentsApi.selectActivePaymentCost$();

    activePaymentCost$.subscribe((activePaymentCost) => {
        if (activePaymentCost) {
            console.log('Updated active payment cost:', activePaymentCost);
        } else {
            console.log('No active payment cost available.');
        }
    });
});

Basket Payments API methods reference

Models reference