Class: PaymentKit::WebhookController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/payment_kit/webhook_controller.rb

Overview

HTTP entrypoint: verify signature(s) → dedupe → instrument → 200 OK.

PaymentKit treats 4xx as a permanent failure (no retry) and retries 5xx or timeouts five times over roughly 27 hours, so failure mapping matters:

  • bad/missing signature → 401, never retried
  • verified but unparseable → 400, never retried
  • subscriber raised → 500 by default (retried), or 200 when PaymentKit.error_handler is configured

Endpoints must answer within 30 seconds, so subscribers should enqueue work rather than perform it inline.

Instance Method Summary collapse

Instance Method Details

#eventObject

Handles one webhook delivery: verify, deduplicate, dispatch, answer.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/payment_kit/webhook_controller.rb', line 24

def event
  # raw_post (not body.read) so verification still sees the exact bytes
  # after middleware or param parsing has consumed the request stream.
  PaymentKit.process_webhook(
    request.raw_post,
    request.headers["X-Webhook-Signature"]
  )
  head :ok
rescue AuthenticationError => e
  logger&.error("[PaymentKit::WebhookController] #{e.message}")
  head :unauthorized
rescue InvalidRequestError => e
  logger&.error("[PaymentKit::WebhookController] #{e.message}")
  head :bad_request
rescue StandardError => e
  raise if PaymentKit.error_handler.nil?

  PaymentKit.error_handler.call(e, request)
  head :ok
end