Skip to main content

Events

The full list of available events are:

Event NameDescription
beforeLoadBefore the widget resources get loaded
afterLoadAfter the widget resources were loaded
beforeCreateBefore the widget instance is created
afterCreateAfter the widget instance is created
beforeRenderBefore the widget is rendered
afterRenderAfter the widget is rendered
fetchPaymentDataStartStart of fetching the payment data
fetchPaymentDataEndEnd of fetching the payment data
purposeChangedPurpose changed
amountChangedAmount changed
currencyChangedCurrency changed
paymentTypeChangedPayment type changed (e.g. one-off or recurring)
recurringIntervalChangedInterval changed
paymentMethodChangedPayment method changed
beforePaymentValidateAndSendBefore payment form has been validated and sent
beforePaymentValidateBefore payment form has been validated
afterPaymentValidateAfter payment form has been validated
paymentValidateSuccessAfter payment form has been validated successfully
paymentValidateErrorAfter payment form has been validated with errors
beforePaymentSendBefore payment form has been sent
paymentCompleteAfter payment has been completed
subscriptionUpdateCompleteAfter subscription has beeb updated
subscriptionCancelledAfter subscription has been cancelled

Subscribe to an event

In order to subscribe to an event, call window.rnw.tamaro.events.<EVENT_NAME>.subscribe(<CALLBACK>).

  • The <EVENT_NAME> can be found above
  • The <CALLBACK> is a JavaScript function that will be called once the event has fired.

In the following example the callbackPurposeChanged function gets called whenever the user changes the purpose of the donation form.

window.rnw.tamaro.runWidget('.rnw-tamaro-widget');

function callbackPurposeChanged(event) {
console.log(
`Received event ${event.eventName} with the following data:`,
event.data,
);
}

window.rnw.tamaro.events.purposeChanged.subscribe(callbackPurposeChanged);

All event handlers receive event that is structured as such:

PropertyTypeDescription
eventNamestringThe name of the fired event
dataobjectTamaro event data
data.apiobjectAPI instance.
Not present for the events beforeLoad, afterLoad, beforeCreate

Calling subscribe function will return new function that allows you to unsubscribe from this event.

let unsubscribe = window.rnw.tamaro.events.purposeChanged.subscribe(
callbackPurposeChanged,
);
unsubscribe();

Subscribe to all events

The following snippet subscribes to all events of your Tamaro Widget and logs it to the console.

Object.keys(rnw.tamaro.events).forEach((eventName) => {
window.rnw.tamaro.events[eventName].subscribe((event) => {
console.log(event.eventName, event.data);
});
});

window.rnw.tamaro.runWidget('.rnw-tamaro-widget');