Skip to main content
Version: Lab (preview)

on

Registers a listener for a Messenger event.


Function​

const unsubscribe = messenger.on(event, callback)

Parameters​

Parametertyperequireddescription
eventStringYesName of the event. One of the events below.
callbackFunctionYesCalled with the event's payload each time the event fires.

Available events​

Eventdescription
readyFires when initialize connects the Messenger.
transaction_completeFires when processWalletTransaction processes a payment, including a declined one. The payload has the Transaction. Check its status.
transaction_errorFires when Pay Theory's servers return an error for processWalletTransaction. The payload has the error message. Errors the Messenger catches before it sends the payment, such as a missing field, only come back in the ERROR response.
iframe_unloadedFires when the Messenger's hidden iframe unloads.

Returns​

Returns a function that removes the event listener when called.


Usage​

// Register event listener
const unsubscribe = messenger.on('transaction_complete', (data) => {
console.log('Transaction completed:', data.transaction);
});

// Remove event listener later
unsubscribe();

Event data​

ready event​

{
success: Boolean
}

transaction_complete event​

{
transaction: {
transaction_id: String,
status: String,
gross_amount: Number,
// ...the rest of the Transaction fields
}
}

transaction_error event​

{
error: String
}

iframe_unloaded event​

{
timestamp: Number
}