-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example or documentation on how Webhook works #38
Comments
I can help up to the point of using the instantiated event The issue is that we need to emphasize the need for a RAW request body, not a parsed one nor with any bit out of place. It's used in the HMAC. This will implicate a middleware/router/framework. I can provide a Kemal example. Would I merely edit the Here's an example, which I would explain as much as possible
|
I was thinking about this : maybe make a webhook.md and link to it from the readme.md ? (the readme.md is very long as it is, it'll shrink when all objects/methods are implemented but still) I can add a Lucky example like this one (@stephendolan lucky' skills might bring something better :-p ) : class StripeEvents::Webhook < ApiAction
include Api::Auth::SkipRequireAuthToken
accepted_formats [:json, :xml], default: :json
post "/stripe/webhook" do
# You can use webhooks to receive information about asynchronous payment events.
# For more about our webhook events check out https://stripe.com/docs/webhooks.
webhook_secret = Application.settings.stripe_webhook_secret
signature_header = request.headers["Stripe-Signature"]
begin
event = Stripe::Webhook.construct_event(payload: request.body.not_nil!.gets_to_end, sig_header: signature_header, secret: webhook_secret)
rescue e : JSON::SerializableError
Log.error { e.message }
json({status: "error", error: e.message}, 500)
rescue e2 : SignatureVerificationError
Log.error { "⚠️ Webhook signature verification failed." }
json({status: "error", error: e2}, 404)
else
event_handler(event.not_nil!)
json({status: "success"})
end
end |
@vectorselector @rmarronnier Sounds good. As simple as possible is good; we can add it as a wiki page, maybe? We should probably have for at least the 2-3 biggest frameworks, in other words, for Kemal, Lucky, and Amber. I will try to set it up during this week. You should not need to set |
I haven't got time to do this yet. If you guys (@rmarronnier and @vectorselector) have tested it, we can use those for some wiki page for it, at least. :) |
It is possible to understand how to set up the webhook through the API docs or the ruby version of it.
But maybe add an example in the readme to make it easier to understand?
The text was updated successfully, but these errors were encountered: