basket.setPayment¶
basket.setPayment
is an event on the Event Bus that occurs whenever a payment method is set in the basket.
Event body¶
none
Example¶
In this example we listen to basket.setPayment
event and perform an action whenever it's emitted.
useStorefront(async (storefront) => {
storefront.eventBus.on('basket.setPayment', () => {
console.log('A payment method has been changed!');
});
});
Example¶
In this example we use a Message Storage API to retrieve an array of past basket.setPayment
events.
useStorefront((storefront) => {
const messageStorageApi = storefront.getApiSync('messageStorageSystemApi');
const pastSetPaymentEvents = messageStorageApi.getChannelMessages('basket.setPayment');
if (pastSetPaymentEvents.length > 0) {
pastSetPaymentEvents.forEach(({ body: eventBody }) => {
console.log('perform action on every past event');
});
}
});