Here's another approach that you might want to consider:
# controllers/webhooks/stripe_controller.rbclassWebhooks::StripeController<ApplicationControllerbefore_action:authorize_request!defhandlerpayload=request.request_parameters# this will parse the body to json if content type is json# 1. Save the event and process in backgroundsave_event_for_the_record_and_process_later# 2. Process nowprocess_now(payload)endprivate# Save events in db or other system so you can process event in background# and also to have a record of what you actually got from stripe.# It might be helful to debug future issues.defsave_event_for_the_record(payload)event=Webhooks::StripeEvent.new(payload: payload)ifevent.saveevent.process_laterhead(:ok)elsehead:unprocessable_entityendenddefprocess_now(payload)casepayload['event']when....endenddefauthorize_request!# validate request ...endend
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here's another approach that you might want to consider: