Skip to content

Instantly share code, notes, and snippets.

@jphungcode
Created October 21, 2020 02:59
Show Gist options
  • Save jphungcode/cb2f39cd70045048a19b010652ef8e86 to your computer and use it in GitHub Desktop.
Save jphungcode/cb2f39cd70045048a19b010652ef8e86 to your computer and use it in GitHub Desktop.
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; //secret phrase set in woocommerce
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");
}
pushOrder(data)
.then((result) => {
res.status(200).send(result);
})
.catch((error) => {
res.status(501).send(error);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment