Skip to content

Commit

Permalink
Wait 15 seconds before processing event (wait for medusa to create or…
Browse files Browse the repository at this point in the history
…der)
  • Loading branch information
Rohit3523 committed Oct 21, 2024
1 parent 17eb7b4 commit 5784527
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions dist/api/razorpay/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ exports.default = async (req, res) => {
try {
const body = Buffer.isBuffer(req.body) ? JSON.parse(req.body.toString('utf-8')) : req.body;
logger.info(`Received Razorpay: ${JSON.stringify(body)}`);
await wait(15000);
const validationResponse = razorpay_1.default.validateWebhookSignature(JSON.stringify(body), webhookSignature, webhookSecret);
if (!validationResponse) {
res.sendStatus(400);
Expand Down Expand Up @@ -62,3 +63,8 @@ exports.default = async (req, res) => {
return;
}
};
async function wait(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
10 changes: 9 additions & 1 deletion src/api/razorpay/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export default async (req: MedusaRequest, res: MedusaResponse) => {

logger.info(`Received Razorpay: ${JSON.stringify(body)}`);

await wait(15000);

const validationResponse = Razorpay.validateWebhookSignature(
JSON.stringify(body),
webhookSignature,
Expand Down Expand Up @@ -75,4 +77,10 @@ export default async (req: MedusaRequest, res: MedusaResponse) => {
res.sendStatus(500);
return;
}
};
};

async function wait(ms: number) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}

0 comments on commit 5784527

Please sign in to comment.