Last active
October 29, 2019 07:34
-
-
Save unicodeveloper/ba3f3977407514bbd3d9781c318698b9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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("/fibre", function(req, res) { | |
let event = 'customer.created' | |
let fullName = 'Mark Fish' | |
let email = '[email protected]' | |
let payload = { | |
'event': event, | |
'data': { | |
'full_name': fullName, | |
'email': email | |
} | |
} | |
let signature = crypto.createHmac('sha512', process.env.EDEN_FIBRE_SECRET_KEY).update(JSON.stringify(payload)).digest('hex'); | |
const options = { | |
headers: {'X-Fibre-Signature': signature } | |
}; | |
axios.post('https://edenbackend-staging.herokuapp.com/api/fibre/discount', 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