2020-03-10 13:39:21 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-04-03 11:50:54 +00:00
|
|
|
import {
|
|
|
|
emitterCallback,
|
|
|
|
reducer,
|
|
|
|
emitEvent,
|
|
|
|
emitEventWithAbort,
|
|
|
|
} from '../event-emit';
|
2020-03-10 13:39:21 +00:00
|
|
|
|
|
|
|
const EMIT_TYPES = {
|
|
|
|
CHECKOUT_COMPLETE_WITH_SUCCESS: 'checkout_complete',
|
|
|
|
CHECKOUT_COMPLETE_WITH_ERROR: 'checkout_complete_error',
|
|
|
|
CHECKOUT_PROCESSING: 'checkout_processing',
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Receives a reducer dispatcher and returns an object with the
|
|
|
|
* onCheckoutComplete callback registration function for the checkout emit
|
|
|
|
* events.
|
|
|
|
*
|
|
|
|
* Calling the event registration function with the callback will register it
|
|
|
|
* for the event emitter and will return a dispatcher for removing the
|
|
|
|
* registered callback (useful for implementation in `useEffect`).
|
|
|
|
*
|
|
|
|
* @param {Function} dispatcher The emitter reducer dispatcher.
|
|
|
|
*
|
|
|
|
* @return {Object} An object with the `onCheckoutComplete` emmitter registration
|
|
|
|
*/
|
|
|
|
const emitterSubscribers = ( dispatcher ) => ( {
|
2020-04-03 11:50:54 +00:00
|
|
|
onCheckoutCompleteSuccess: emitterCallback(
|
|
|
|
EMIT_TYPES.CHECKOUT_COMPLETE_WITH_SUCCESS,
|
|
|
|
dispatcher
|
|
|
|
),
|
|
|
|
onCheckoutCompleteError: emitterCallback(
|
|
|
|
EMIT_TYPES.CHECKOUT_COMPLETE_WITH_ERROR,
|
|
|
|
dispatcher
|
|
|
|
),
|
|
|
|
onCheckoutProcessing: emitterCallback(
|
|
|
|
EMIT_TYPES.CHECKOUT_PROCESSING,
|
|
|
|
dispatcher
|
|
|
|
),
|
2020-03-10 13:39:21 +00:00
|
|
|
} );
|
|
|
|
|
2020-03-20 16:46:24 +00:00
|
|
|
export {
|
|
|
|
EMIT_TYPES,
|
|
|
|
emitterSubscribers,
|
|
|
|
reducer,
|
|
|
|
emitEvent,
|
|
|
|
emitEventWithAbort,
|
|
|
|
};
|