@goweekdays/core 2.6.0 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -6414,7 +6414,7 @@ function usePaypalService() {
6414
6414
  certCache.set(url, certPem);
6415
6415
  return certPem;
6416
6416
  }
6417
- async function verifyWebhook(rawBody, headers, webhookId = PAYPAL_WEBHOOK_ID) {
6417
+ async function verifySignature(rawBody, headers, webhookId = PAYPAL_WEBHOOK_ID) {
6418
6418
  const transmissionId = headers["paypal-transmission-id"];
6419
6419
  const timeStamp = headers["paypal-transmission-time"];
6420
6420
  const certUrl = headers["paypal-cert-url"];
@@ -6439,7 +6439,7 @@ function usePaypalService() {
6439
6439
  return {
6440
6440
  addOrder,
6441
6441
  captureOrder,
6442
- verifyWebhook
6442
+ verifySignature
6443
6443
  };
6444
6444
  }
6445
6445
 
@@ -9857,20 +9857,34 @@ function useUtilController() {
9857
9857
  }
9858
9858
  }
9859
9859
  }
9860
- const { verifyWebhook } = usePaypalService();
9860
+ const { verifySignature } = usePaypalService();
9861
9861
  async function paypalWebhook(req, res, next) {
9862
- console.log(req);
9863
9862
  try {
9864
- await verifyWebhook(req.body, req.headers, PAYPAL_WEBHOOK_ID);
9865
- res.status(200).send("OK");
9866
- return;
9863
+ const headers = req.headers;
9864
+ const event = req.body;
9865
+ const data = JSON.parse(event);
9866
+ console.log(`headers`, headers);
9867
+ console.log(`parsed json`, JSON.stringify(data, null, 2));
9868
+ console.log(`raw event: ${event}`);
9869
+ const isSignatureValid = await verifySignature(
9870
+ event,
9871
+ headers,
9872
+ PAYPAL_WEBHOOK_ID
9873
+ );
9874
+ if (isSignatureValid) {
9875
+ console.log("Signature is valid.");
9876
+ console.log(`Received event`, JSON.stringify(data, null, 2));
9877
+ } else {
9878
+ console.log(
9879
+ `Signature is not valid for ${data?.id} ${headers?.["correlation-id"]}`
9880
+ );
9881
+ }
9882
+ res.sendStatus(200);
9867
9883
  } catch (error) {
9868
9884
  logger28.log({
9869
9885
  level: "error",
9870
- message: "PayPal webhook verification failed"
9886
+ message: `${error}`
9871
9887
  });
9872
- res.status(400).send("Invalid webhook");
9873
- return;
9874
9888
  }
9875
9889
  }
9876
9890
  return {