// Webhook handler
app.post('/api/paygate-webhook', async (req, res) => {
const { type, accessToken, featureIds, walletAddress } = req.body;
if (type === 'feature.unlocked') {
// Store token for user
await db.users.update({
where: { wallet: walletAddress },
data: {
accessToken,
features: featureIds
}
});
}
res.json({ received: true });
});
// Verify access in your app
async function checkFeatureAccess(userToken, featureId) {
const response = await fetch(
'https://api-paygate.getaether.xyz/public/feature/verify',
{
method: 'POST',
headers: {
'X-API-Key': process.env.PAYGATE_API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
accessToken: userToken
})
}
);
const { valid, features } = await response.json();
return valid && features.includes(featureId);
}
// Usage
if (await checkFeatureAccess(user.accessToken, 'analytics_pro')) {
// Show pro analytics
}