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 ({ eventBus, getApi }) => {
eventBus.on('basket.initialized', async () => {
const basketPaymentsApi = await getApi('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¶
- get
- select$
- getAvailable
- selectAvailable$
- setPayment
- setPaymentData
- getSelectedPayment
- selectSelectedPayment$
- getActivePaymentCost
- selectActivePaymentCost$
- getPaymentChannelStrategy
- addPaymentInfo
- getPaymentInfo
- getSectionValidation
- selectSectionValidation$