javascript
// Submit order from landing page form
async function submitOrder(formData) {
const response = await fetch(
'https://api.adstema.com/api/v1/network-orders/create',
{
method: 'POST',
headers: {
'X-Network-Key': 'nk_your_partner_key',
'Content-Type': 'application/json',
},
body: JSON.stringify({
externalId: `order-${Date.now()}`,
customerEmail: formData.email,
customerPhone: formData.phone,
customerName: formData.name,
items: formData.cartItems,
totalAmount: formData.total,
currency: 'RSD',
webhookUrl: 'https://your-domain.com/webhooks/orders',
}),
}
);
const data = await response.json();
if (data.success) {
console.log('Order submitted:', data.data.id);
return data.data;
} else {
throw new Error(data.message);
}
}
// Handle incoming webhooks from ADSTEMA
app.post('/webhooks/orders', (req, res) => {
const { externalId, status, orderNumber } = req.body;
if (status === 'CONFIRMED') {
// Mark sale as confirmed in your system
markOrderAsConfirmed(externalId, orderNumber);
} else if (status === 'REJECTED') {
// Handle rejection
notifyCustomer(externalId);
}
res.json({ received: true });
});