I’m encountering a persistent “Module Not Found” error when trying to set up an HTTP function for IPN handling with PayTabs. Despite ensuring that my file is named correctly (http-functions.js) and located in the Backend section, the Wix system logs still show an attempt to load a non-existent .js file. Here’s the error message I receive:
I’ve tried the following steps to resolve the issue:
Renamed the file to .jsw from .js. Same error.
Ensured that the file is placed in the Backend directory.
Checked for any caching issues and waited for changes to propagate.
Synced my site after making changes in Dev mode.
Despite these efforts, the error persists. Has anyone encountered a similar issue or can offer insights into what might be going wrong? Any help would be greatly appreciated!
Not sure if you can help with this but if you don’t mind I’m also having a problem with comparing the signatures together from the payment gateway API and the website.
I wrote all this code after hours and hours of research (never done it before as you said). I added console logs to help me with every step to debug the problem, it seems the signature that I’m retrieving from the header comes back as null.
import { ok, badRequest, serverError } from 'wix-http-functions';
import wixSecretsBackend from 'wix-secrets-backend';
import { createHmac } from 'crypto';
export async function post_paymentCallback(request) {
console.log("Received IPN callback request");
// Retrieve the server key from Wix Secrets Manager
let serverKey;
try {
serverKey = await wixSecretsBackend.getSecret("MEPS_SERVER_KEY");
console.log("Server key retrieved successfully");
} catch (error) {
console.error("Error retrieving server key:", error);
return serverError({ "body": "Error retrieving server key" });
}
// Extract the signature from the request headers
const requestSignature = request.headers["Signature"]; // Lowercase 's' to ensure compatibility
console.log("Request signature extracted:", requestSignature);
if (!requestSignature) {
console.log("No signature found in the request headers.");
return badRequest({ "body": "No signature provided in the request headers." });
}
try {
// Read the request body
const requestBody = await request.body.text();
console.log("Request body received:", requestBody);
// Generate an HMAC signature of the request body using the server key
const calculatedSignature = createHmac('sha256', serverKey)
.update(requestBody)
.digest('hex');
console.log("Calculated signature:", calculatedSignature);
// Compare the signature from MEPS with the signature you've generated
if (calculatedSignature === requestSignature) {
console.log("Signature match confirmed");
// If the signature matches, parse the IPN data and handle it
const ipnData = JSON.parse(requestBody);
console.log("IPN data parsed:", ipnData);
// Implement your logic to process the IPN data here
// Respond to MEPS with 200 OK to acknowledge receipt of the notification
return ok({ "body": "Signature verified successfully" });
} else {
console.log("Signature mismatch detected");
// If the signature does not match, respond with 500 Server Error
return serverError({ "body": "Invalid signature" });
}
} catch (error) {
// Log any errors for debugging
console.error('Error processing payment callback:', error);
// Respond with 500 Server Error
return serverError({ "body": `Error processing request: ${error.message}` });
}
}