Class: SpreeDoordash::WebhooksController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- SpreeDoordash::WebhooksController
- Defined in:
- app/controllers/spree_doordash/webhooks_controller.rb
Overview
Receives DoorDash Drive webhook notifications. Basic-Auth-verified instead of Square's HMAC signature (see SpreeDoordash::WebhookVerifier) and, like SpreeSquare::WebhooksController, deliberately does the least possible work synchronously: verify, record, ack, hand off to a job. DoorDash "sends each webhook event up to 3 times" on anything other than 200 (its own docs), so a slow or non-2xx response means retries.
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/spree_doordash/webhooks_controller.rb', line 19 def create credential = SpreeDoordash::Credential.find_by(store: Spree::Store.default) unless SpreeDoordash::WebhookVerifier.valid?( authorization_header: request.headers['Authorization'], expected_token: credential&.webhook_basic_auth_token ) Rails.logger.warn('[SpreeDoordash] webhook auth verification failed') return head :unauthorized end raw_body = request.raw_post payload = JSON.parse(raw_body) event = find_or_log_event(raw_body, payload) SpreeDoordash::DeliveryWebhookJob.perform_later(event.id) if event.previously_new_record? head :ok rescue JSON::ParserError head :bad_request end |