The Phoenix payment iframe communicates with your application through the window.postMessage API. This page explains the messages exchanged between your application and the Phoenix payment iframe.
Your application should listen for these messages and take appropriate actions:
window.addEventListener('message', function(event) { // IMPORTANT: Verify origin for security if (event.origin !== 'https://app-partner.phoenix.market') return; // Handle transaction success message if (event.data?.type === 'TRANSACTION_SUCCESS') { const { amount, token, chain, walletAddress, sendAmount, transactionHash, basescanLink } = event.data.data; console.log('Transaction successful:', transactionHash); console.log(`Amount: $${amount} ${token} on ${chain}`); console.log(`Transaction link: ${basescanLink}`); // Update your UI or redirect user to a success page } // Handle order created message else if (event.data?.type === 'ORDER_CREATED') { const { order_id, ...data } = event.data.data; console.log('Order created:', event.data.data); // You should store order details in your database, especially the order_id } // Handle cancel message else if (event.data?.type === 'CANCEL') { console.log('Payment canceled by user'); // Close the iframe or update UI accordingly // Example: document.getElementById('phoenix-iframe').style.display = 'none'; } // Handle open explorer URL message else if (event.data?.type === 'OPEN_EXPLORER_URL') { const url = event.data.url; console.log('Opening explorer URL:', url); // Open the URL in a new tab window.open(url, '_blank'); } // Handle done message else if (event.data?.type === 'USER_DONE') { console.log('Payment process completed'); // Close the iframe or update UI accordingly, similar to CANCEL // Example: document.getElementById('phoenix-iframe').style.display = 'none'; }});