Integration
No code
Code
const { createHmac } = require("crypto");
const express = require('express')
const app = express()
app.use(express.raw({ type: '*/*', limit: '10mb' }));
const PORT = 3000
const LLAMAPAY_API_KEY = "llamapay_sk_YOUR_API_KEY"
const LLAMAPAY_WEBHOOK_SECRET = "llamapay_webhook_secret_XXXX"
app.post('/webhook', (req, res) => {
const hmac = createHmac('sha256', LLAMAPAY_WEBHOOK_SECRET)
.update(req.body).digest('hex');
if(req.headers['x-cc-webhook-signature'] !== hmac){
return res.sendStatus(401)
}
const body = JSON.parse(req.body);
if(body.type === "charge:pending"){
console.log("User paid:", body.data.metadata)
}
res.sendStatus(200)
})
app.post('/new-payment/:userHandle', async (req, res) => {
const payment = await fetch("https://api.llamapay.io/charges", {
method: "POST",
headers:{
Authorization: LLAMAPAY_API_KEY
},
body: JSON.stringify({
"pricing_type": "fixed_price",
"local_price": {
"amount": "1.00",
"currency": "USD"
},
"metadata": {
"userHandle": req.params.userHandle
}
})
}).then(r=>r.json())
res.send(payment.data.hosted_url)
})
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`)
})Last updated