Skip to navigation

Listen for Successful Account Link Messages

JavaScript
import React, { useEffect } from 'react';
function App() {
useEffect(() => {
const handleMessage = (event) => {
// Use 'https://coinflow.cash' in production.
if (event.origin !== 'https://sandbox.coinflow.cash') return;
try {
const data = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;
if (data?.data === 'accountLinked') {
console.log('Successfully linked:', data.info.type); // the type of account linked: bank, card, iban, pix
}
if (data?.data === 'accountLinkError') {
console.log('Link failed:', data.info.type, data.info.status, data.info.message);
}
} catch (error) {
console.error('Error:', error);
}
};
window.addEventListener('message', handleMessage);
return () => {
window.removeEventListener('message', handleMessage);
};
}, []);
return (
<div className="App" style={{ height: "500px" }}>
<iframe
allow="geolocation"
src="https://sandbox.coinflow.cash/YOUR_SETTLEMENT_CHAIN/withdraw/YOUR_MERCHANT_ID?sessionKey=USER_SESSION_KEY&bankAccountLinkRedirect=URL_ENCODED_URL_TO_REDIRECT_TO"
height={"600px"}
/>
</div>
);
}
export default App;
Response Example
{"success":true}

Define the handleMessage function

handleMessage function parses the data and converts it to a json object. Then, if the message contains ‘accountLinked’, it logs a success message along with the account type (data.info.type) — which could be “bank”, “card”, “iban”, or “pix”.

Merchants can replace this with their own functionalities here.

Handle failed account links

If the link attempt fails, the iframe emits an accountLinkError message instead. Its info carries the account type, the HTTP status of the failed request (data.info.status, absent when the request never reached the API), and the error message (data.info.message) — so you can surface the reason to the customer or log it for support rather than seeing only a generic failure screen.

If you embed the flow with the React SDK, pass an onAccountLinkError callback to <CoinflowWithdraw> instead of registering your own listener.