Skip to content

Instantly share code, notes, and snippets.

@LucaTNT
Created June 26, 2022 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LucaTNT/b146c15ec391c00d76700673b6439e14 to your computer and use it in GitHub Desktop.
Save LucaTNT/b146c15ec391c00d76700673b6439e14 to your computer and use it in GitHub Desktop.
Shell script to sign a Stripe webhook event
#!/usr/bin/env bash
WEBHOOK_DESTINATION="http://localhost:3000/stripe/webhook"
WEBHOOK_SECRET="whsec_ENTER_YOURS_HERE"
if [[ ! "$#" -eq 1 ]]; then
echo "USAGE: $0 /path/to/event.json";
exit 1;
fi
timestamp="$(date +%s)."
echo -n $timestamp > sign.tmp
cat $1 >> sign.tmp
signature="$(cat sign.tmp | openssl dgst -hmac "$WEBHOOK_SECRET" -sha256)"
curl "$WEBHOOK_DESTINATION" \
-H "Stripe-Signature: t=$timestamp,v1=$signature" \
-H "Content-Type: application/json" \
--data-binary @"$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment