8. Handling Callbacks from Web-Components

Events are our way of letting you know when something interesting happens in web-components.

The payment-platform web-component is a DOM element that provides various events to which you can attach listeners to in your client side code. For specific events, please refer to following document:

To attach an event handler to web-component, you'll need to call addEventListener on your desired web-component element.

<payment-platform id="onboarding" merchant-id="ea0e0ae6-aa42-48da-b801-0106facf1e37" type="boarding"></payment-platform>

<script type="application/javascript">
    document.getElementById('onboarding').addEventListener('stepChange', function(e) {
        console.log(e.detail)
    })
    document.getElementById('onboarding').addEventListener('submitted', function(e) {
        console.log(e.detail)
    })
</script>

Below you'll find some equivalent examples in other popular frameworks.

React

function MyComponent() {

    const addEvents = useCallback(node => {
        if (node !== null) {
            node.addEventListener('stepChange', function(e) {
                console.log('step changed', e.detail);
            })
        }
    });
    
    return <payment-platform 
        ref={addEvents} 
        merchant-id="ea0e0ae6-aa42-48da-b801-0106facf1e37" 
        type="boarding"></payment-platform>
}

VueJS

Angular

Last updated