also @rolznz , I noticed that when using <bc-pay-button>, the bc:onpaid event doesn’t fire when listening directly on the button element. it only fires globally on window. This is because the event is dispatched from within launchPaymentModal (specifically from the bc-payment component), but it doesn't bubble up through the bc-pay-button itself.
To improve modularity and make it easier to listen for events in scoped components or apps using Web Components (or frameworks like React/Vue), I suggest forwarding the event from bc-pay-button like this:
const { setPaid } = launchPaymentModal({
onPaid: (response) => {
this._paid = true;
this.dispatchEvent(new CustomEvent('bc:onpaid', {
detail: response,
bubbles: true,
composed: true,
}));
},
invoice: this.invoice,
paymentMethods: this.paymentMethods,
});
This allows users to do:
payButton.addEventListener('bc:onpaid', (e) => {
console.log('got paid', e.detail);
});
instead of having to rely on a global window listener, which can be problematic in apps with multiple buttons or more complex scopes.
Originally posted by @Dunsin-cyber in #301 (comment)
also @rolznz , I noticed that when using
<bc-pay-button>, thebc:onpaidevent doesn’t fire when listening directly on the button element. it only fires globally onwindow. This is because the event is dispatched from withinlaunchPaymentModal(specifically from thebc-paymentcomponent), but it doesn't bubble up through thebc-pay-buttonitself.To improve modularity and make it easier to listen for events in scoped components or apps using Web Components (or frameworks like React/Vue), I suggest forwarding the event from
bc-pay-buttonlike this:This allows users to do:
instead of having to rely on a global
windowlistener, which can be problematic in apps with multiple buttons or more complex scopes.Originally posted by @Dunsin-cyber in #301 (comment)