Skip to content

Instantly share code, notes, and snippets.

@unicodeveloper
Last active October 29, 2019 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unicodeveloper/ba3f3977407514bbd3d9781c318698b9 to your computer and use it in GitHub Desktop.
Save unicodeveloper/ba3f3977407514bbd3d9781c318698b9 to your computer and use it in GitHub Desktop.
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 = 'takeit@chairman.com'
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