Last active
July 24, 2021 12:56
-
-
Save unicodeveloper/4d43a5b24fb501faf54a87fcb76e6b87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dotenv/config'; | |
import express from 'express'; | |
import axios from 'axios'; | |
import cors from 'cors'; | |
import crypto from 'crypto'; | |
const app = express(); | |
app.use(cors()); | |
app.use(express.json()); | |
app.use(express.urlencoded({ extended: true })); | |
app.post("/whatever", function(req, res) { | |
let payload = { | |
'event': 'customer.subscribed', | |
'data': { | |
'fullName': 'olori baba', | |
'email': 'givethem@yahoo.com', | |
'phoneNo': '08023975521', | |
'homeAddress': '7, Marlian HQ', | |
'landmark': 'Near Mafo Studios', | |
'gender': 'non-binary', | |
'area': 53 , | |
'plan': 'HARDWORKERSPLEETA' | |
} | |
} | |
let signature = crypto.createHmac('sha512', process.env.EDEN_SPLEET_SECRET_KEY).update(JSON.stringify(payload)).digest('hex'); | |
const options = { | |
headers: {'X-Spleet-Signature': signature } | |
}; | |
axios.post('https://edenbackend-staging.herokuapp.com/api/spleet/hook', payload, options) | |
.then(response => { | |
return res.json({ | |
'response': response.data | |
}) | |
}) | |
.catch(error => { | |
if(error.response){ | |
console.log("Errors ", error); | |
return res.json(error.response) | |
} else if(error.request) { | |
console.log(error.request); | |
return res.json(error.request) | |
} else { | |
console.log(error.config); | |
return res.json(error.config) | |
} | |
}) | |
}); | |
app.listen(3000, () => | |
console.log('Example app listening on port 3000!'), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment