Ryan Chandler Ryan Chandler

Easy Stripe webhook testing with Laravel

Laravel

I've been working on a couple of new side projects recently and integrating with Stripe is super simple thanks to Cashier.

Testing webhooks locally normally means using the Stripe CLI and that involves a couple of options to make sure it's configured correctly for your Laravel application and also proxying those webhooks to the correct endpoint.

One of the handiest scripts I used whilst working on Forge was a tiny Bash script that configures the Stripe CLI based on your .env file automatically.

#!/usr/bin/env bash

set -euo pipefail

APP_URL="$(awk -F '=' '/^APP_URL/{gsub(/"/, "", $2); print $2}' .env)"
STRIPE_SECRET="$(awk -F '=' '/^STRIPE_SECRET/{gsub(/"/, "", $2); print $2}' .env)"

stripe listen -f "$APP_URL/stripe/webhook" --api-key="$STRIPE_SECRET"

As long as you've got the awk utility on your system, you should be good to add this to your project somewhere and execute it when need be.

chmod +x ./bin/stripe.sh
./stripe.sh