Created
October 21, 2020 02:59
-
-
Save jphungcode/cb2f39cd70045048a19b010652ef8e86 to your computer and use it in GitHub Desktop.
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
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