app.post('/app/topup/crypto', authenticateUser, async (req, res) => {
const { amount, currency } = req.body;
const user = req.user;
// Get crypto gateway metadata
const cryptoGatewayOcid = 600; // Configured crypto on-ramp
const gateway = await fetchMetadata(cryptoGatewayOcid);
// Create a top-up order (your gateway is the "merchant")
const order = {
id: `topup_${crypto.randomUUID()}`,
ocid: YOUR_OCID,
reference: user.ocid.toString(),
amount,
currency,
memo: `Balance top-up for user ${user.ocid}`,
createdAt: Math.floor(Date.now() / 1000),
expiresAt: Math.floor(Date.now() / 1000) + 30 * 60,
accepts: [cryptoGatewayOcid]
};
const orderSignature = signOrder(order);
// Call crypto gateway's /checkout/create
const response = await fetch(`${gateway.config.endpoint}/checkout/create`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...createAuthHeaders(YOUR_OCID, YOUR_PRIVATE_KEY)
},
body: JSON.stringify({
order,
signature: orderSignature,
merchantOcid: YOUR_OCID,
urls: {
success: `${YOUR_APP_URL}/topup/success?order=${order.id}`,
cancel: `${YOUR_APP_URL}/topup/cancel`
}
})
});
const { checkout_url, session_id, expires_at } = await response.json();
// Store pending top-up
await db.createTopupSession({
orderId: order.id,
userId: user.id,
sessionId: session_id,
providerOcid: cryptoGatewayOcid,
amount,
currency,
status: 'pending'
});
res.json({ checkout_url });
});