Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Retry failed Stripe Webhook events
# frozen_string_literal: true
# Stripe will retry failed webhooks seven times with exponential backoff. If that has been exceeded
# then the webhook event is marked "failed" and won't be retried. We can resend the event by [retrieving
# the event data and posting it to the
# webhook](!topic/api-discuss/N33ZXqp3NzI).
# To use this, configure your endpoint URL below, then run this in providing event IDs on the command line.
SECRET = StripeEvent.signing_secrets.first # Hard-code this if you don't have the secret in this environment
event_ids = ARGV # Or hard-code a list of event IDs
def sign_event(data)
time =
payload = "#{time}.#{data}"
signature = Stripe::Webhook::Signature.send(:compute_signature, payload, SECRET)
event_ids.each do |event_id|
event_data = Stripe::Event.retrieve(event_id).to_json
response =
headers: {
"Content-Type" => "application/json; charset=utf8",
"Cache-Control" => "no-cache",
"User-Agent" => "Stripe/1.0 (+",
"Stripe-Signature" => sign_event(event_data)
body: event_data
puts "#{event_id}: (#{response.status})\n#{response.body}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment