Skip to content

getSelectedPayment(): BasketPayment | undefined

The getSelectedPayment method retrieves the currently selected payment option for the basket's shipping configuration.

Returned value

A returned value has a type of BasketPayment | undefined where BasketPayment represents the BasketPayment model, indicating the selected payment method or undefined if no payment method has been selected.

Example

In this example, we use the basketPaymentsApi to retrieve the currently selected payment option.

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

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

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

    const selectedPayment = basketPaymentsApi.getSelectedPayment();

    if (selectedPayment) {
        console.log('Selected payment option:', selectedPayment);
    } else {
        console.log('No payment option has been selected.');
    }
});

Basket Payments API methods reference

Models reference