I'm trying to use a payment services webhook and verifying the signture. I'm having some trouble with processing payload.
the webhook.verify function in standardwebhooks library requires a string or a Buffer payload (as seen in error in image 2)
When I try it in a local express app. I do this- (see commented code 1) (the express.raw at the top allows me to access the raw payload without express preprocessing it) I log the response to see types if payload and it comes like this [image 1],
notice the payload is type buffer, i convert it to string and pass it to function. This works.
Now when I replicate the same thing in appwrite - (see commented code 2) , the payload is coming in as object and I think that is causing issues with webhook.verify function, getting a response like this [image 2] What I suspect is happening is appwrite preprocesses the payload and converts it from buffer to object.
Here are some questions I have .
- is there a way to stop this preprocessing like I'm doing in express and get a raw buffer payload.
- can I use express in an appwrite cloud function and do it like that.
- any other way I can verify the signature, I suspect this should be something similar to what stripe uses, so if you have verified stripe payload maybe that would apply here as well.
Thanks in advance!
express code code 1
app.post('/webhook', async (req, res) => {
try {
console.log("req", req.body)
console.log(typeof req.body)
const rawBody = req.body.toString('utf8');
const headersList = req.headers;
let webhookHeaders = {
"webhook-id": headersList["webhook-id"] || "",
"webhook-signature": headersList["webhook-signature"] || "",
"webhook-timestamp": headersList["webhook-timestamp"] || "",
};
try{
const verifyres = await webhook.verify(rawBody, webhookHeaders);
console.log("verifyres", verifyres)```
appwrite code code 2
try {
let params = req.body || {};
log(typeof params)
log("params",params )
const rawBody = params.toString('utf8');
log("rawBody",rawBody)
log(typeof rawBody)
const headersList = req.headers;
let webhookHeaders = {
"webhook-id": headersList["webhook-id"] || "",
"webhook-signature": headersList["webhook-signature"] || "",
"webhook-timestamp": headersList["webhook-timestamp"] || "",
};
log("webHookHeaders", webhookHeaders)
log(typeof webhookHeaders)
try{
const verifyres = await webhook.verify(params, webhookHeaders);
log("verifyres", verifyres)```
code pasted in comments bcs post limit reached 😅
Recommended threads
- Not getting data
IDK what the issue is but I am stuck at a weried but that I am calling this function ``` @override Future<List<CategoryModel>> getCategories() async { t...
- Problem with the new Email policies
when user set those thing from cloud panel and when they open that page again or reload that time it forget what we have checked and it set default to false on ...
- Deleted my account, trying to signup aga...
https://cloud.appwrite.io/console/login?error=%7B%22message%22%3A%22This+email+address+must+already+be+in+its+canonical+form.+Please+remove+aliases%2C+tags%2C+o...