@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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @goweekdays/core
2
2
 
3
+ ## 2.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - f984739: Fix signature verification
8
+
3
9
  ## 2.6.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.js CHANGED
@@ -6420,7 +6420,7 @@ function usePaypalService() {
6420
6420
  certCache.set(url, certPem);
6421
6421
  return certPem;
6422
6422
  }
6423
- async function verifyWebhook(rawBody, headers, webhookId = PAYPAL_WEBHOOK_ID) {
6423
+ async function verifySignature(rawBody, headers, webhookId = PAYPAL_WEBHOOK_ID) {
6424
6424
  const transmissionId = headers["paypal-transmission-id"];
6425
6425
  const timeStamp = headers["paypal-transmission-time"];
6426
6426
  const certUrl = headers["paypal-cert-url"];
@@ -6445,7 +6445,7 @@ function usePaypalService() {
6445
6445
  return {
6446
6446
  addOrder,
6447
6447
  captureOrder,
6448
- verifyWebhook
6448
+ verifySignature
6449
6449
  };
6450
6450
  }
6451
6451
 
@@ -9823,20 +9823,34 @@ function useUtilController() {
9823
9823
  }
9824
9824
  }
9825
9825
  }
9826
- const { verifyWebhook } = usePaypalService();
9826
+ const { verifySignature } = usePaypalService();
9827
9827
  async function paypalWebhook(req, res, next) {
9828
- console.log(req);
9829
9828
  try {
9830
- await verifyWebhook(req.body, req.headers, PAYPAL_WEBHOOK_ID);
9831
- res.status(200).send("OK");
9832
- return;
9829
+ const headers = req.headers;
9830
+ const event = req.body;
9831
+ const data = JSON.parse(event);
9832
+ console.log(`headers`, headers);
9833
+ console.log(`parsed json`, JSON.stringify(data, null, 2));
9834
+ console.log(`raw event: ${event}`);
9835
+ const isSignatureValid = await verifySignature(
9836
+ event,
9837
+ headers,
9838
+ PAYPAL_WEBHOOK_ID
9839
+ );
9840
+ if (isSignatureValid) {
9841
+ console.log("Signature is valid.");
9842
+ console.log(`Received event`, JSON.stringify(data, null, 2));
9843
+ } else {
9844
+ console.log(
9845
+ `Signature is not valid for ${data?.id} ${headers?.["correlation-id"]}`
9846
+ );
9847
+ }
9848
+ res.sendStatus(200);
9833
9849
  } catch (error) {
9834
9850
  import_utils55.logger.log({
9835
9851
  level: "error",
9836
- message: "PayPal webhook verification failed"
9852
+ message: `${error}`
9837
9853
  });
9838
- res.status(400).send("Invalid webhook");
9839
- return;
9840
9854
  }
9841
9855
  }
9842
9856
  return {