Last active
October 21, 2020 02:53
-
-
Save jphungcode/7ecf03d525a8e3ef39aa7bf2e9c00345 to your computer and use it in GitHub Desktop.
Woocommerce integration with PFC express
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
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