Skip to content

Instantly share code, notes, and snippets.

@jphungcode
Last active October 21, 2020 02:53
Show Gist options
  • Save jphungcode/7ecf03d525a8e3ef39aa7bf2e9c00345 to your computer and use it in GitHub Desktop.
Save jphungcode/7ecf03d525a8e3ef39aa7bf2e9c00345 to your computer and use it in GitHub Desktop.
Woocommerce integration with PFC express
const crypto = require("crypto");
const fetch = require("isomorphic-fetch");
exports.wooComPushToPFC = functions.https.onRequest((req, res) => {
const method = req.method;
const headers = req.headers;
const data = req.body;
if (method !== "POST") {
res.status(501).send("Incorrect req method");
}
const secret = functions.config().woocommerce.secret; // your secret phrase set in woocommerce webhook - I will cover this later
const signature = headers["x-wc-webhook-signature"];
const hash = crypto
.createHmac("SHA256", secret)
.update(req.rawBody)
.digest("base64");
if (hash !== signature) {
res.status(501).send("Unauthorized access");
}
console.log(data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment