Skip to content

Instantly share code, notes, and snippets.

@LucaTNT
Created June 26, 2022 15:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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