Skip to content

addPaymentChannelStrategy(channelKey: string, paymentChannel: IStrategy<void, IPaymentChannel>): void

The addPaymentChannelStrategy method registers a new payment channel strategy for a specific channel key, enabling customized payment processing based on different channels.

Input parameters

channelKey

channelKey is a mandatory parameter of type string that identifies the payment channel to which the strategy will be added.

paymentChannel

paymentChannel is a mandatory parameter of type IStrategy<void, IPaymentChannel> where IStrategy represents the IStrategy type and IPaymentChannel represents the IPaymentChannel type that defines the strategy or configuration for the specified payment channel.

Returned value

This method does not return any value (void).

Example

In this example, we use the basketPaymentsApi to add a new payment channel strategy for a specific channel key. To get a payment strategy for a specific key we use the getPaymentChannelStrategy method.

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

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

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

    const channelKey = 'stripe';
    const stripeChannelStrategy = basketPaymentsApi.getPaymentChannelStrategy(channelKey);

    basketPaymentsApi.addPaymentChannelStrategy(channelKey, stripeChannelStrategy);

    console.log(`Added payment channel strategy for ${channelKey}.`);
});

Basket Payments API methods reference

Objects reference