Created
June 26, 2022 15:45
-
-
Save LucaTNT/b146c15ec391c00d76700673b6439e14 to your computer and use it in GitHub Desktop.
Shell script to sign a Stripe webhook event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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