Skip to content

selectPaymentCostForActiveShippingByPaymentId$(): Observable<FullPrice | undefined>

The selectPaymentCostForActiveShippingByPaymentId$ method allows you to observe the payment cost for an active shipping method by payment ID.

Returned value

A returned value has a type of Observable<FullPrice | undefined> where FullPrice represents the FullPrice model.

Example

In this example, we make a basketShippingsApi call to observe the payment cost for an active shipping method by payment ID.

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 paymentCostForActiveShipping$ = basketShippingsApi.selectPaymentCostForActiveShippingByPaymentId$();

    paymentCostForActiveShipping$.subscribe((paymentCost) => {
        if (paymentCost) {
            console.log('Payment cost for active shipping:', paymentCost.grossValueFormatted);
        } else {
            console.log('No payment cost available for the selected shipping method.');
        }
    });
});

Basket Address API methods reference

Models reference