async function createTransaction(userId, amount) {
try {
const response = await fetch('/v2/transactions', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ userId, amount, asset: 'USDC', network: 'polygon' })
});
if (!response.ok) {
const error = await response.json();
switch (error.code) {
case 'KYC_INCOMPLETE':
return { error: 'Please complete KYC first' };
case 'PENDING_TRANSACTION_EXISTS':
return { error: 'You have an active transaction' };
case 'AMOUNT_TOO_LOW':
return { error: 'Minimum amount is $10' };
default:
return { error: error.message };
}
}
return await response.json();
} catch (err) {
return { error: 'Network error. Please try again.' };
}
}