Class: PurchaseKit::WebhooksController

Inherits:
ApplicationController show all
Defined in:
app/controllers/purchase_kit/webhooks_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/purchase_kit/webhooks_controller.rb', line 5

def create
  event = verified_event
  event_type = event[:type].to_s.tr(".", "_").to_sym

  # Publish to event system (fires registered callbacks)
  PurchaseKit::Events.publish(event_type, event)

  # Queue for Pay's webhook processing if Pay is available
  PurchaseKit.queue_pay_webhook(event) if PurchaseKit.pay_enabled?

  head :ok
rescue JSON::ParserError => e
  Rails.logger.error "[PurchaseKit] Invalid JSON in webhook: #{e.message}"
  head :bad_request
rescue PurchaseKit::SignatureVerificationError => e
  Rails.logger.error "[PurchaseKit] Webhook signature error: #{e.message}"
  head :bad_request
end