Listen for Successful Account Link Messages

JavaScript
1import React, { useEffect } from 'react';
2
3function App() {
4 useEffect(() => {
5 const handleMessage = (event) => {
6
7 try {
8 const data = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;
9
10 if (data?.data === 'accountLinked') {
11 console.log('Successfully linked:', data.info.type); // the type of account linked: bank, card, iban, pix
12 }
13 } catch (error) {
14 console.error('Error:', error);
15 }
16 };
17
18 window.addEventListener('message', handleMessage);
19 return () => {
20 window.removeEventListener('message', handleMessage);
21 };
22 }, []);
23
24 return (
25 <div className="App" style={{ height: "500px" }}>
26 <iframe
27 src="https://sandbox.coinflow.cash/solana/withdraw/YOUR_MERCHANT_ID?sessionKey=USER_SESSION_KEY&bankAccountLinkRedirect=URL_ENCODED_URL_TO_REDIRECT_TO"
28 height={"600px"}
29 />
30 </div>
31 );
32}
33
34export default App;
Response Example
1{"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.