Pay3 Javascript SDK
Event Listeners
9min
introduction after completing transactions in pay3 sdk ui, the pay3 sdk publishes events to app pay3 sdk transaction status this event is fired by pay3 sdk in following scenario on completion of checkout transaction triggered by pay3 opencheckout() payload data (type object) following keys are present in this object status (type string) the status can have one of these values success or error or initiated message (type string) user friendly message returned after completion of the transaction orderid (type string) pay3 order id requestid (type string) unique id passed by app register callback pay3pay on() this function registers a callback, which is invoked when the given event type is received from pay3 parameter eventname (type string) name of the event for which we want to register the callback callbackfn (type function) callback function accepting a parameter payload index js function mylistener(payload) => { if (payload error) { console log("error during transaction ", payload); } else { const { status, message, orderid, requestid } = payload data; console log("received transaction response", { status, message, orderid, requestid }); } } pay3pay on('pay3 sdk transaction status', mylistener); check if registered pay3pay haslisteners() this function returns true if the event already has a registered callback parameter eventname (type string) name of the event for which we want to test if the callback is registered return (type boolean) const isregistered = pay3pay haslisteners('pay3 sdk transaction status'); unregister callback pay3pay removelistener() this function removes a function that is already registered as a callback input of this function needs to be the same as that was provided in pay3pay on function call parameter eventname (type string) name of the event for which we want to register the callback callbackfn (type function) callback function accepting a parameter payload pay3pay removelistener('pay3 sdk transaction status', mylistener); register callback in react native using webview for react native with javascript sdk, the pay3 payment publishes the events using window\ reactnativewebview\ postmessage(string payload) these events are available via onmessage handler of the webview \<webview source={{uri \<url returned by opencheckout or openpayout>}} onmessage={(event) => { const data = json parse(event nativeevent data); alert(json stringify(data)); }} /> // sample json object { "type" "pay3 sdk transaction", "data" { "message" "transaction completed successfully", "requestid" "cebb18de 739d 432d 89ff b0dc2677c891", "status" "success", "orderid" "1f16294b fa2b 4eec b55d 7c6638eb76ed" } }